Compare commits
1 Commits
fix/react-
...
fix/label-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6dd1d3b6e2 |
@@ -8,6 +8,12 @@ import * as labelRepo from "@kan/db/repository/label.repo";
|
|||||||
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
||||||
import { assertUserInWorkspace } from "../utils/auth";
|
import { assertUserInWorkspace } from "../utils/auth";
|
||||||
|
|
||||||
|
const labelSchema = z.object({
|
||||||
|
publicId: z.string(),
|
||||||
|
name: z.string(),
|
||||||
|
colourCode: z.string().nullable(),
|
||||||
|
});
|
||||||
|
|
||||||
export const labelRouter = createTRPCRouter({
|
export const labelRouter = createTRPCRouter({
|
||||||
byPublicId: protectedProcedure
|
byPublicId: protectedProcedure
|
||||||
.meta({
|
.meta({
|
||||||
@@ -21,7 +27,7 @@ export const labelRouter = createTRPCRouter({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.input(z.object({ labelPublicId: z.string().min(12) }))
|
.input(z.object({ labelPublicId: z.string().min(12) }))
|
||||||
.output(z.custom<Awaited<ReturnType<typeof labelRepo.getByPublicId>>>())
|
.output(labelSchema)
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
const userId = ctx.user?.id;
|
const userId = ctx.user?.id;
|
||||||
|
|
||||||
@@ -52,7 +58,11 @@ export const labelRouter = createTRPCRouter({
|
|||||||
code: "NOT_FOUND",
|
code: "NOT_FOUND",
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return {
|
||||||
|
publicId: result.publicId,
|
||||||
|
name: result.name,
|
||||||
|
colourCode: result.colourCode,
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
create: protectedProcedure
|
create: protectedProcedure
|
||||||
.meta({
|
.meta({
|
||||||
@@ -72,7 +82,7 @@ export const labelRouter = createTRPCRouter({
|
|||||||
colourCode: z.string().length(7),
|
colourCode: z.string().length(7),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.output(z.custom<Awaited<ReturnType<typeof labelRepo.create>>>())
|
.output(labelSchema)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const userId = ctx.user?.id;
|
const userId = ctx.user?.id;
|
||||||
|
|
||||||
@@ -108,7 +118,11 @@ export const labelRouter = createTRPCRouter({
|
|||||||
code: "INTERNAL_SERVER_ERROR",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return {
|
||||||
|
publicId: result.publicId,
|
||||||
|
name: result.name,
|
||||||
|
colourCode: result.colourCode,
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
update: protectedProcedure
|
update: protectedProcedure
|
||||||
.meta({
|
.meta({
|
||||||
@@ -128,7 +142,7 @@ export const labelRouter = createTRPCRouter({
|
|||||||
colourCode: z.string().length(7),
|
colourCode: z.string().length(7),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.output(z.custom<Awaited<ReturnType<typeof labelRepo.update>>>())
|
.output(labelSchema)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const userId = ctx.user?.id;
|
const userId = ctx.user?.id;
|
||||||
|
|
||||||
@@ -153,7 +167,17 @@ export const labelRouter = createTRPCRouter({
|
|||||||
|
|
||||||
const result = await labelRepo.update(ctx.db, input);
|
const result = await labelRepo.update(ctx.db, input);
|
||||||
|
|
||||||
return result;
|
if (!result)
|
||||||
|
throw new TRPCError({
|
||||||
|
message: `Failed to update label`,
|
||||||
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
publicId: result.publicId,
|
||||||
|
name: result.name,
|
||||||
|
colourCode: result.colourCode,
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
delete: protectedProcedure
|
delete: protectedProcedure
|
||||||
.meta({
|
.meta({
|
||||||
|
|||||||
@@ -23,7 +23,12 @@ export const create = async (
|
|||||||
createdBy: labelInput.createdBy,
|
createdBy: labelInput.createdBy,
|
||||||
boardId: labelInput.boardId,
|
boardId: labelInput.boardId,
|
||||||
})
|
})
|
||||||
.returning({ id: labels.id });
|
.returning({
|
||||||
|
id: labels.id,
|
||||||
|
publicId: labels.publicId,
|
||||||
|
name: labels.name,
|
||||||
|
colourCode: labels.colourCode,
|
||||||
|
});
|
||||||
|
|
||||||
if (labelInput.cardId && result) {
|
if (labelInput.cardId && result) {
|
||||||
await db.insert(cardsToLabels).values({
|
await db.insert(cardsToLabels).values({
|
||||||
@@ -91,6 +96,7 @@ export const update = async (
|
|||||||
.where(eq(labels.publicId, labelInput.labelPublicId))
|
.where(eq(labels.publicId, labelInput.labelPublicId))
|
||||||
.returning({
|
.returning({
|
||||||
id: labels.id,
|
id: labels.id,
|
||||||
|
publicId: labels.publicId,
|
||||||
name: labels.name,
|
name: labels.name,
|
||||||
colourCode: labels.colourCode,
|
colourCode: labels.colourCode,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user