feat: update checklist name

This commit is contained in:
Henry
2025-08-10 23:08:52 +01:00
parent a3f0809507
commit a89bd835d0
7 changed files with 180 additions and 75 deletions

View File

@@ -73,6 +73,51 @@ export const checklistRouter = createTRPCRouter({
return newChecklist;
}),
update: protectedProcedure
.input(
z.object({
checklistPublicId: z.string().length(12),
name: z.string().min(1).max(255),
}),
)
.output(z.object({ publicId: z.string().length(12), name: z.string() }))
.mutation(async ({ ctx, input }) => {
const userId = ctx.user?.id;
if (!userId)
throw new TRPCError({
message: `User not authenticated`,
code: "UNAUTHORIZED",
});
const checklist = await checklistRepo.getChecklistByPublicId(
ctx.db,
input.checklistPublicId,
);
if (!checklist)
throw new TRPCError({
message: `Checklist with public ID ${input.checklistPublicId} not found`,
code: "NOT_FOUND",
});
await assertUserInWorkspace(
ctx.db,
userId,
checklist.card.list.board.workspace.id,
);
const updated = await checklistRepo.updateChecklistById(ctx.db, {
id: checklist.id,
name: input.name,
});
if (!updated)
throw new TRPCError({
message: `Failed to update checklist`,
code: "INTERNAL_SERVER_ERROR",
});
return updated;
}),
createItem: protectedProcedure
.meta({
openapi: {
@@ -241,46 +286,4 @@ export const checklistRouter = createTRPCRouter({
return { success: true };
}),
// update: protectedProcedure
// .meta({
// openapi: {
// summary: "Update a checklist",
// method: "PUT",
// path: "/cards/{cardPublicId}/checklists/{checklistPublicId}",
// description: "Updates a checklist",
// tags: ["Cards"],
// protect: true,
// },
// })
// .input(
// z.object({
// cardPublicId: z.string().min(12),
// checklistPublicId: z.string().min(12),
// title: z.string().min(1),
// }),
// )
// .output(checklistSchema)
// .mutation(async ({ ctx, input }) => {
// }),
// delete: protectedProcedure
// .meta({
// openapi: {
// summary: "Delete a checklist",
// method: "DELETE",
// path: "/cards/{cardPublicId}/checklists/{checklistPublicId}",
// description: "Deletes a checklist",
// tags: ["Cards"],
// },
// })
// .input(
// z.object({
// cardPublicId: z.string().min(12),
// checklistPublicId: z.string().min(12),
// }),
// )
// .output(checklistSchema)
// .mutation(async ({ ctx, input }) => {
// }),
});

View File

@@ -309,6 +309,7 @@ export const getWithListAndMembersByPublicId = async (
index: true,
},
where: isNull(checklists.deletedAt),
orderBy: asc(checklists.index),
with: {
items: {
columns: {
@@ -318,6 +319,7 @@ export const getWithListAndMembersByPublicId = async (
index: true,
},
where: isNull(checklistItems.deletedAt),
orderBy: asc(checklistItems.index),
},
},
},

View File

@@ -171,3 +171,15 @@ export const softDeleteItemById = async (
return result;
};
export const updateChecklistById = async (
db: dbClient,
args: { id: number; name: string },
) => {
const [result] = await db
.update(checklists)
.set({ name: args.name, updatedAt: new Date() })
.where(eq(checklists.id, args.id))
.returning({ publicId: checklists.publicId, name: checklists.name });
return result;
};