feat: update label

This commit is contained in:
Henry
2024-08-27 23:34:52 +01:00
parent 2adcac85a4
commit 583256a46b
6 changed files with 145 additions and 38 deletions

View File

@@ -7,6 +7,19 @@ import * as cardRepo from "~/server/db/repository/card.repo";
import * as labelRepo from "~/server/db/repository/label.repo";
export const labelRouter = createTRPCRouter({
byPublicId: protectedProcedure
.input(z.object({ publicId: z.string().min(12) }))
.query(async ({ ctx, input }) => {
const label = await labelRepo.getByPublicId(ctx.db, input.publicId);
if (!label)
throw new TRPCError({
message: `Label with public ID ${input.publicId} not found`,
code: "NOT_FOUND",
});
return label;
}),
create: protectedProcedure
.input(
z.object({
@@ -42,6 +55,19 @@ export const labelRouter = createTRPCRouter({
boardId: card.list.boardId,
});
return result;
}),
update: protectedProcedure
.input(
z.object({
publicId: z.string().min(12),
name: z.string().min(1).max(36),
colourCode: z.string().length(7),
}),
)
.mutation(async ({ ctx, input }) => {
const result = await labelRepo.update(ctx.db, input);
return result;
}),
});

View File

@@ -52,10 +52,29 @@ export const getByPublicId = async (
) => {
const { data } = await db
.from("label")
.select(`id`)
.select(`id, publicId, name, colourCode`)
.eq("publicId", labelPublicId)
.limit(1)
.single();
return data;
};
export const update = async (
db: SupabaseClient<Database>,
labelInput: {
publicId: string;
name: string;
colourCode: string;
},
) => {
const { data } = await db
.from("label")
.update({
name: labelInput.name,
colourCode: labelInput.colourCode,
})
.eq("publicId", labelInput.publicId);
return data;
};