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