diff --git a/apps/server/src/models/course/course.router.ts b/apps/server/src/models/course/course.router.ts index f08d35c..4ed98c4 100644 --- a/apps/server/src/models/course/course.router.ts +++ b/apps/server/src/models/course/course.router.ts @@ -3,84 +3,92 @@ import { TrpcService } from '@server/trpc/trpc.service'; import { Prisma, UpdateOrderSchema } from '@nice/common'; import { CourseService } from './course.service'; import { z, ZodType } from 'zod'; -const CourseCreateArgsSchema: ZodType = z.any() -const CourseUpdateArgsSchema: ZodType = z.any() -const CourseCreateManyInputSchema: ZodType = z.any() -const CourseDeleteManyArgsSchema: ZodType = z.any() -const CourseFindManyArgsSchema: ZodType = z.any() -const CourseFindFirstArgsSchema: ZodType = z.any() -const CourseWhereInputSchema: ZodType = z.any() -const CourseSelectSchema: ZodType = z.any() +const CourseCreateArgsSchema: ZodType = z.any(); +const CourseUpdateArgsSchema: ZodType = z.any(); +const CourseCreateManyInputSchema: ZodType = + z.any(); +const CourseDeleteManyArgsSchema: ZodType = + z.any(); +const CourseFindManyArgsSchema: ZodType = z.any(); +const CourseFindFirstArgsSchema: ZodType = z.any(); +const CourseWhereInputSchema: ZodType = z.any(); +const CourseSelectSchema: ZodType = z.any(); @Injectable() export class CourseRouter { - constructor( - private readonly trpc: TrpcService, - private readonly courseService: CourseService, - ) { } - router = this.trpc.router({ - create: this.trpc.protectProcedure - .input(CourseCreateArgsSchema) - .mutation(async ({ ctx, input }) => { - const { staff } = ctx; - return await this.courseService.create(input, { staff }); - }), - update: this.trpc.protectProcedure - .input(CourseUpdateArgsSchema) - .mutation(async ({ ctx, input }) => { - const { staff } = ctx; - return await this.courseService.update(input, { staff }); - }), - createMany: this.trpc.protectProcedure.input(z.array(CourseCreateManyInputSchema)) - .mutation(async ({ ctx, input }) => { - const { staff } = ctx; + constructor( + private readonly trpc: TrpcService, + private readonly courseService: CourseService, + ) {} + router = this.trpc.router({ + create: this.trpc.protectProcedure + .input(CourseCreateArgsSchema) + .mutation(async ({ ctx, input }) => { + const { staff } = ctx; - return await this.courseService.createMany({ data: input }, staff); - }), - deleteMany: this.trpc.procedure - .input(CourseDeleteManyArgsSchema) - .mutation(async ({ input }) => { - return await this.courseService.deleteMany(input); - }), - findFirst: this.trpc.procedure - .input(CourseFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword - .query(async ({ input }) => { - return await this.courseService.findFirst(input); - }), - softDeleteByIds: this.trpc.protectProcedure - .input(z.object({ ids: z.array(z.string()) })) // expect input according to the schema - .mutation(async ({ input }) => { - return this.courseService.softDeleteByIds(input.ids); - }), - updateOrder: this.trpc.protectProcedure - .input(UpdateOrderSchema) - .mutation(async ({ input }) => { - return this.courseService.updateOrder(input); - }), - findMany: this.trpc.procedure - .input(CourseFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword - .query(async ({ input }) => { - return await this.courseService.findMany(input); - }), - findManyWithCursor: this.trpc.protectProcedure - .input(z.object({ - cursor: z.any().nullish(), - take: z.number().optional(), - where: CourseWhereInputSchema.optional(), - select: CourseSelectSchema.optional() - })) - .query(async ({ ctx, input }) => { - return await this.courseService.findManyWithCursor(input); - }), - findManyWithPagination: this.trpc.procedure - .input(z.object({ - page: z.number().optional(), - pageSize: z.number().optional(), - where: CourseWhereInputSchema.optional(), - select: CourseSelectSchema.optional() - })) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword - .query(async ({ input }) => { - return await this.courseService.findManyWithPagination(input); - }), - }); + return await this.courseService.create(input, { staff }); + }), + update: this.trpc.protectProcedure + .input(CourseUpdateArgsSchema) + .mutation(async ({ ctx, input }) => { + const { staff } = ctx; + return await this.courseService.update(input, { staff }); + }), + createMany: this.trpc.protectProcedure + .input(z.array(CourseCreateManyInputSchema)) + .mutation(async ({ ctx, input }) => { + const { staff } = ctx; + + return await this.courseService.createMany({ data: input }, staff); + }), + deleteMany: this.trpc.procedure + .input(CourseDeleteManyArgsSchema) + .mutation(async ({ input }) => { + return await this.courseService.deleteMany(input); + }), + findFirst: this.trpc.procedure + .input(CourseFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword + .query(async ({ input }) => { + return await this.courseService.findFirst(input); + }), + softDeleteByIds: this.trpc.protectProcedure + .input(z.object({ ids: z.array(z.string()) })) // expect input according to the schema + .mutation(async ({ input }) => { + return this.courseService.softDeleteByIds(input.ids); + }), + updateOrder: this.trpc.protectProcedure + .input(UpdateOrderSchema) + .mutation(async ({ input }) => { + return this.courseService.updateOrder(input); + }), + findMany: this.trpc.procedure + .input(CourseFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword + .query(async ({ input }) => { + return await this.courseService.findMany(input); + }), + findManyWithCursor: this.trpc.protectProcedure + .input( + z.object({ + cursor: z.any().nullish(), + take: z.number().optional(), + where: CourseWhereInputSchema.optional(), + select: CourseSelectSchema.optional(), + }), + ) + .query(async ({ ctx, input }) => { + return await this.courseService.findManyWithCursor(input); + }), + findManyWithPagination: this.trpc.procedure + .input( + z.object({ + page: z.number().optional(), + pageSize: z.number().optional(), + where: CourseWhereInputSchema.optional(), + select: CourseSelectSchema.optional(), + }), + ) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword + .query(async ({ input }) => { + return await this.courseService.findManyWithPagination(input); + }), + }); }