feat: update card router to support due dates
This commit is contained in:
@@ -32,6 +32,7 @@ export const cardRouter = createTRPCRouter({
|
||||
labelPublicIds: z.array(z.string().min(12)),
|
||||
memberPublicIds: z.array(z.string().min(12)),
|
||||
position: z.enum(["start", "end"]),
|
||||
dueDate: z.date().nullable().optional(),
|
||||
}),
|
||||
)
|
||||
.output(z.custom<Awaited<ReturnType<typeof cardRepo.create>>>())
|
||||
@@ -69,6 +70,7 @@ export const cardRouter = createTRPCRouter({
|
||||
createdBy: userId,
|
||||
listId: list.id,
|
||||
position: input.position,
|
||||
dueDate: input.dueDate ?? null,
|
||||
});
|
||||
|
||||
const newCardId = newCard.id;
|
||||
@@ -686,6 +688,7 @@ export const cardRouter = createTRPCRouter({
|
||||
description: z.string().optional(),
|
||||
index: z.number().optional(),
|
||||
listPublicId: z.string().min(12).optional(),
|
||||
dueDate: z.date().nullable().optional(),
|
||||
}),
|
||||
)
|
||||
.output(z.custom<Awaited<ReturnType<typeof cardRepo.update>>>())
|
||||
@@ -746,15 +749,19 @@ export const cardRouter = createTRPCRouter({
|
||||
title: string;
|
||||
description: string | null;
|
||||
publicId: string;
|
||||
dueDate: Date | null;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
if (input.title || input.description) {
|
||||
const previousDueDate = existingCard.dueDate;
|
||||
|
||||
if (input.title || input.description || input.dueDate !== undefined) {
|
||||
result = await cardRepo.update(
|
||||
ctx.db,
|
||||
{
|
||||
...(input.title && { title: input.title }),
|
||||
...(input.description && { description: input.description }),
|
||||
...(input.dueDate !== undefined && { dueDate: input.dueDate }),
|
||||
},
|
||||
{ cardPublicId: input.cardPublicId },
|
||||
);
|
||||
@@ -796,6 +803,32 @@ export const cardRouter = createTRPCRouter({
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
input.dueDate !== undefined &&
|
||||
previousDueDate?.getTime() !== input.dueDate?.getTime()
|
||||
) {
|
||||
let activityType:
|
||||
| "card.updated.dueDate.added"
|
||||
| "card.updated.dueDate.updated"
|
||||
| "card.updated.dueDate.removed";
|
||||
|
||||
if (!previousDueDate) {
|
||||
activityType = "card.updated.dueDate.added";
|
||||
} else if (!input.dueDate) {
|
||||
activityType = "card.updated.dueDate.removed";
|
||||
} else {
|
||||
activityType = "card.updated.dueDate.updated";
|
||||
}
|
||||
|
||||
activities.push({
|
||||
type: activityType,
|
||||
cardId: result.id,
|
||||
createdBy: userId,
|
||||
fromDueDate: previousDueDate ?? undefined,
|
||||
toDueDate: input.dueDate ?? undefined,
|
||||
});
|
||||
}
|
||||
|
||||
if (newListId && existingCard.listId !== newListId) {
|
||||
activities.push({
|
||||
type: "card.updated.list" as const,
|
||||
|
||||
Reference in New Issue
Block a user