feat: test refactoring board queries
This commit is contained in:
@@ -40,20 +40,12 @@ interface Card {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Label {
|
interface Label {
|
||||||
label: LabelData;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LabelData {
|
|
||||||
publicId: string;
|
publicId: string;
|
||||||
name: string;
|
name: string;
|
||||||
colourCode: string;
|
colourCode: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Member {
|
interface Member {
|
||||||
member: MemberData;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MemberData {
|
|
||||||
publicId: string;
|
publicId: string;
|
||||||
user: User;
|
user: User;
|
||||||
}
|
}
|
||||||
@@ -76,6 +68,8 @@ export default function BoardPage() {
|
|||||||
const [selectedPublicListId, setSelectedPublicListId] =
|
const [selectedPublicListId, setSelectedPublicListId] =
|
||||||
useState<PublicListId>("");
|
useState<PublicListId>("");
|
||||||
|
|
||||||
|
console.log({ boardData });
|
||||||
|
|
||||||
const boardId = params?.boardId?.length ? params.boardId[0] : null;
|
const boardId = params?.boardId?.length ? params.boardId[0] : null;
|
||||||
|
|
||||||
const updateBoard = api.board.update.useMutation();
|
const updateBoard = api.board.update.useMutation();
|
||||||
@@ -277,7 +271,7 @@ export default function BoardPage() {
|
|||||||
{(card.labels?.length ?? 0) ||
|
{(card.labels?.length ?? 0) ||
|
||||||
(card.members?.length ?? 0) ? (
|
(card.members?.length ?? 0) ? (
|
||||||
<div className="mt-2 flex justify-end space-x-1">
|
<div className="mt-2 flex justify-end space-x-1">
|
||||||
{card.labels?.map(({ label }) => (
|
{card.labels?.map((label) => (
|
||||||
<span
|
<span
|
||||||
key={label.publicId}
|
key={label.publicId}
|
||||||
className="inline-flex w-fit items-center gap-x-1.5 rounded-full px-2 py-1 text-[10px] font-medium text-neutral-600 ring-1 ring-inset ring-light-600 dark:text-dark-1000 dark:ring-dark-800"
|
className="inline-flex w-fit items-center gap-x-1.5 rounded-full px-2 py-1 text-[10px] font-medium text-neutral-600 ring-1 ring-inset ring-light-600 dark:text-dark-1000 dark:ring-dark-800"
|
||||||
@@ -294,7 +288,7 @@ export default function BoardPage() {
|
|||||||
</span>
|
</span>
|
||||||
))}
|
))}
|
||||||
<div className="isolate flex -space-x-1 overflow-hidden">
|
<div className="isolate flex -space-x-1 overflow-hidden">
|
||||||
{card.members?.map(({ member }) => (
|
{card.members?.map((member) => (
|
||||||
<span
|
<span
|
||||||
key={member.publicId}
|
key={member.publicId}
|
||||||
className="inline-flex h-6 w-6 items-center justify-center rounded-full bg-light-900 ring-2 ring-light-50 dark:bg-gray-500 dark:ring-dark-500"
|
className="inline-flex h-6 w-6 items-center justify-center rounded-full bg-light-900 ring-2 ring-light-50 dark:bg-gray-500 dark:ring-dark-500"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ interface BoardData {
|
|||||||
lists: List[];
|
lists: List[];
|
||||||
workspace: {
|
workspace: {
|
||||||
members: Members[];
|
members: Members[];
|
||||||
};
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Label {
|
interface Label {
|
||||||
@@ -44,7 +44,7 @@ interface Members {
|
|||||||
publicId: string;
|
publicId: string;
|
||||||
user: {
|
user: {
|
||||||
name: string | null;
|
name: string | null;
|
||||||
};
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Card {
|
interface Card {
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ export const authRouter = createTRPCRouter({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log({ data })
|
|
||||||
console.log({ error })
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -17,121 +17,77 @@ export const boardRouter = createTRPCRouter({
|
|||||||
|
|
||||||
// @todo: validate user has access to workspace
|
// @todo: validate user has access to workspace
|
||||||
|
|
||||||
if (!userId) return;
|
// if (!userId) return
|
||||||
|
|
||||||
const workspace = await ctx.db.query.workspaces.findFirst({
|
// const workspace = await ctx.db.query.workspaces.findFirst({
|
||||||
where: eq(workspaces.publicId, input.workspacePublicId),
|
// where: eq(workspaces.publicId, input.workspacePublicId),
|
||||||
})
|
// })
|
||||||
|
|
||||||
if (!workspace) return;
|
// if (!workspace) return;
|
||||||
|
|
||||||
return ctx.db.query.boards.findMany({
|
const { data, error } = await ctx.supabase.from('board').select(`
|
||||||
where: and(eq(boards.workspaceId, workspace.id), isNull(boards.deletedAt)),
|
publicId,
|
||||||
columns: {
|
name
|
||||||
publicId: true,
|
`).is('deletedAt', null);
|
||||||
name: true,
|
|
||||||
},
|
return data;
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
byId: publicProcedure
|
byId: publicProcedure
|
||||||
.input(z.object({ id: z.string().min(12) }))
|
.input(z.object({ id: z.string().min(12) }))
|
||||||
.query(({ ctx, input }) =>
|
.query(async ({ ctx, input }) => {
|
||||||
ctx.db.query.boards.findFirst({
|
const { data, error } = await ctx.supabase.from('board').select(`
|
||||||
where: and(eq(boards.publicId, input.id), isNull(boards.deletedAt)),
|
publicId,
|
||||||
columns: {
|
name,
|
||||||
publicId: true,
|
workspace (
|
||||||
name: true,
|
publicId,
|
||||||
},
|
members:workspace_members (
|
||||||
with: {
|
publicId,
|
||||||
workspace: {
|
user (
|
||||||
columns: {
|
name
|
||||||
publicId: true,
|
)
|
||||||
},
|
)
|
||||||
with: {
|
),
|
||||||
members: {
|
labels:label (
|
||||||
columns: {
|
publicId,
|
||||||
publicId: true,
|
name,
|
||||||
},
|
colourCode
|
||||||
with: {
|
),
|
||||||
user: {
|
lists:list (
|
||||||
columns: {
|
publicId,
|
||||||
name: true
|
name,
|
||||||
}
|
boardId,
|
||||||
}
|
index,
|
||||||
}
|
cards:card (
|
||||||
}
|
publicId,
|
||||||
}
|
title,
|
||||||
},
|
description,
|
||||||
labels: {
|
listId,
|
||||||
columns: {
|
index,
|
||||||
publicId: true,
|
labels:label (
|
||||||
colourCode: true,
|
publicId,
|
||||||
name: true,
|
name,
|
||||||
}
|
colourCode
|
||||||
},
|
),
|
||||||
lists: {
|
members:workspace_members (
|
||||||
orderBy: [asc(lists.index)],
|
publicId,
|
||||||
where: isNull(cards.deletedAt),
|
user (
|
||||||
columns: {
|
name
|
||||||
publicId: true,
|
)
|
||||||
name: true,
|
)
|
||||||
boardId: true,
|
)
|
||||||
index: true,
|
)
|
||||||
},
|
`)
|
||||||
with: {
|
.eq('publicId', input.id)
|
||||||
cards: {
|
.is('deletedAt', null)
|
||||||
where: isNull(cards.deletedAt),
|
.is('lists.deletedAt', null)
|
||||||
orderBy: [asc(cards.index)],
|
.is('lists.cards.deletedAt', null)
|
||||||
columns: {
|
.order('index', { foreignTable: 'list', ascending: true })
|
||||||
publicId: true,
|
.order('index', { foreignTable: 'list.card', ascending: true })
|
||||||
title: true,
|
.limit(1)
|
||||||
description: true,
|
.single()
|
||||||
listId: true,
|
|
||||||
index: true,
|
return data;
|
||||||
},
|
}),
|
||||||
with: {
|
|
||||||
labels: {
|
|
||||||
columns: {
|
|
||||||
labelId: false,
|
|
||||||
cardId: false,
|
|
||||||
},
|
|
||||||
with: {
|
|
||||||
label: {
|
|
||||||
columns: {
|
|
||||||
publicId: true,
|
|
||||||
name: true,
|
|
||||||
colourCode: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
members: {
|
|
||||||
columns: {
|
|
||||||
workspaceMemberId: false,
|
|
||||||
cardId: false,
|
|
||||||
},
|
|
||||||
with: {
|
|
||||||
member: {
|
|
||||||
columns: {
|
|
||||||
publicId: true,
|
|
||||||
},
|
|
||||||
with: {
|
|
||||||
user: {
|
|
||||||
columns: {
|
|
||||||
name: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
),
|
|
||||||
create: publicProcedure
|
create: publicProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
|
|||||||
Reference in New Issue
Block a user