feat: assign labels on new card
This commit is contained in:
@@ -62,6 +62,13 @@ export const boardRouter = createTRPCRouter({
|
||||
}
|
||||
}
|
||||
},
|
||||
labels: {
|
||||
columns: {
|
||||
publicId: true,
|
||||
colourCode: true,
|
||||
name: true,
|
||||
}
|
||||
},
|
||||
lists: {
|
||||
orderBy: [asc(lists.index)],
|
||||
where: isNull(cards.deletedAt),
|
||||
|
||||
@@ -15,6 +15,7 @@ export const cardRouter = createTRPCRouter({
|
||||
z.object({
|
||||
title: z.string().min(1),
|
||||
listPublicId: z.string().min(12),
|
||||
labelsPublicIds: z.array(z.string().min(12)),
|
||||
memberPublicIds: z.array(z.string().min(12))
|
||||
}),
|
||||
)
|
||||
@@ -49,6 +50,18 @@ export const cardRouter = createTRPCRouter({
|
||||
index: latestCard ? latestCard.index + 1 : 0
|
||||
});
|
||||
|
||||
if (newCard.insertId && input.labelsPublicIds.length) {
|
||||
const labels = await tx.query.labels.findMany({
|
||||
where: inArray(cards.publicId, input.labelsPublicIds),
|
||||
});
|
||||
|
||||
if (!labels.length) return;
|
||||
|
||||
const labelsInsert = labels.map((label) => ({ cardId: Number(newCard.insertId), labelId: label.id }))
|
||||
|
||||
await tx.insert(cardsToLabels).values(labelsInsert);
|
||||
}
|
||||
|
||||
if (newCard.insertId && input.memberPublicIds.length) {
|
||||
const members = await tx.query.workspaceMembers.findMany({
|
||||
where: inArray(workspaceMembers.publicId, input.memberPublicIds),
|
||||
|
||||
Reference in New Issue
Block a user