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)),
|
labelPublicIds: z.array(z.string().min(12)),
|
||||||
memberPublicIds: z.array(z.string().min(12)),
|
memberPublicIds: z.array(z.string().min(12)),
|
||||||
position: z.enum(["start", "end"]),
|
position: z.enum(["start", "end"]),
|
||||||
|
dueDate: z.date().nullable().optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.output(z.custom<Awaited<ReturnType<typeof cardRepo.create>>>())
|
.output(z.custom<Awaited<ReturnType<typeof cardRepo.create>>>())
|
||||||
@@ -69,6 +70,7 @@ export const cardRouter = createTRPCRouter({
|
|||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
listId: list.id,
|
listId: list.id,
|
||||||
position: input.position,
|
position: input.position,
|
||||||
|
dueDate: input.dueDate ?? null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const newCardId = newCard.id;
|
const newCardId = newCard.id;
|
||||||
@@ -686,6 +688,7 @@ export const cardRouter = createTRPCRouter({
|
|||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
index: z.number().optional(),
|
index: z.number().optional(),
|
||||||
listPublicId: z.string().min(12).optional(),
|
listPublicId: z.string().min(12).optional(),
|
||||||
|
dueDate: z.date().nullable().optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.output(z.custom<Awaited<ReturnType<typeof cardRepo.update>>>())
|
.output(z.custom<Awaited<ReturnType<typeof cardRepo.update>>>())
|
||||||
@@ -746,15 +749,19 @@ export const cardRouter = createTRPCRouter({
|
|||||||
title: string;
|
title: string;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
publicId: string;
|
publicId: string;
|
||||||
|
dueDate: Date | null;
|
||||||
}
|
}
|
||||||
| undefined;
|
| undefined;
|
||||||
|
|
||||||
if (input.title || input.description) {
|
const previousDueDate = existingCard.dueDate;
|
||||||
|
|
||||||
|
if (input.title || input.description || input.dueDate !== undefined) {
|
||||||
result = await cardRepo.update(
|
result = await cardRepo.update(
|
||||||
ctx.db,
|
ctx.db,
|
||||||
{
|
{
|
||||||
...(input.title && { title: input.title }),
|
...(input.title && { title: input.title }),
|
||||||
...(input.description && { description: input.description }),
|
...(input.description && { description: input.description }),
|
||||||
|
...(input.dueDate !== undefined && { dueDate: input.dueDate }),
|
||||||
},
|
},
|
||||||
{ cardPublicId: input.cardPublicId },
|
{ 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) {
|
if (newListId && existingCard.listId !== newListId) {
|
||||||
activities.push({
|
activities.push({
|
||||||
type: "card.updated.list" as const,
|
type: "card.updated.list" as const,
|
||||||
|
|||||||
Reference in New Issue
Block a user