import { Injectable } from '@nestjs/common'; import { TrpcService } from '@server/trpc/trpc.service'; import { Prisma, UpdateOrderSchema } from '@nice/common'; import { RoleService } from './role.service'; import { z, ZodType } from 'zod'; const RoleCreateArgsSchema: ZodType = z.any() const RoleUpdateArgsSchema: ZodType = z.any() const RoleCreateManyInputSchema: ZodType = z.any() const RoleDeleteManyArgsSchema: ZodType = z.any() const RoleFindManyArgsSchema: ZodType = z.any() const RoleFindFirstArgsSchema: ZodType = z.any() const RoleWhereInputSchema: ZodType = z.any() const RoleSelectSchema: ZodType = z.any() const RoleUpdateInputSchema: ZodType = z.any(); @Injectable() export class RoleRouter { constructor( private readonly trpc: TrpcService, private readonly roleService: RoleService, ) { } router = this.trpc.router({ create: this.trpc.protectProcedure .input(RoleCreateArgsSchema) .mutation(async ({ ctx, input }) => { const { staff } = ctx; return await this.roleService.create(input, staff); }), update: this.trpc.protectProcedure .input(RoleUpdateArgsSchema) .mutation(async ({ ctx, input }) => { const { staff } = ctx; return await this.roleService.update(input, staff); }), createMany: this.trpc.protectProcedure.input(z.array(RoleCreateManyInputSchema)) .mutation(async ({ ctx, input }) => { const { staff } = ctx; return await this.roleService.createMany({ data: input }, staff); }), softDeleteByIds: this.trpc.protectProcedure .input( z.object({ ids: z.array(z.string()), data: RoleUpdateInputSchema.optional() }), ) .mutation(async ({ input }) => { return await this.roleService.softDeleteByIds(input.ids, input.data); }), findFirst: this.trpc.procedure .input(RoleFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword .query(async ({ input }) => { return await this.roleService.findFirst(input); }), updateOrder: this.trpc.protectProcedure .input(UpdateOrderSchema) .mutation(async ({ input }) => { return this.roleService.updateOrder(input); }), findMany: this.trpc.procedure .input(RoleFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword .query(async ({ input }) => { return await this.roleService.findMany(input); }), findManyWithCursor: this.trpc.protectProcedure .input(z.object({ cursor: z.any().nullish(), take: z.number().optional(), where: RoleWhereInputSchema.optional(), select: RoleSelectSchema.optional() })) .query(async ({ ctx, input }) => { const { staff } = ctx; return await this.roleService.findManyWithCursor(input); }), findManyWithPagination: this.trpc.procedure .input(z.object({ page: z.number(), pageSize: z.number().optional(), where: RoleWhereInputSchema.optional(), select: RoleSelectSchema.optional() })) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword .query(async ({ input }) => { return await this.roleService.findManyWithPagination(input); }), }); }