import { Injectable } from '@nestjs/common'; import { TrpcService } from '@server/trpc/trpc.service'; import { Prisma, UpdateOrderSchema } from '@nicestack/common'; import { ResourceService } from './resource.service'; import { z, ZodType } from 'zod'; const ResourceCreateArgsSchema: ZodType = z.any() const ResourceCreateManyInputSchema: ZodType = z.any() const ResourceDeleteManyArgsSchema: ZodType = z.any() const ResourceFindManyArgsSchema: ZodType = z.any() const ResourceFindFirstArgsSchema: ZodType = z.any() const ResourceWhereInputSchema: ZodType = z.any() const ResourceSelectSchema: ZodType = z.any() @Injectable() export class ResourceRouter { constructor( private readonly trpc: TrpcService, private readonly resourceService: ResourceService, ) { } router = this.trpc.router({ create: this.trpc.protectProcedure .input(ResourceCreateArgsSchema) .mutation(async ({ ctx, input }) => { const { staff } = ctx; return await this.resourceService.create(input, staff); }), createMany: this.trpc.protectProcedure.input(z.array(ResourceCreateManyInputSchema)) .mutation(async ({ ctx, input }) => { const { staff } = ctx; return await this.resourceService.createMany({ data: input }, staff); }), deleteMany: this.trpc.procedure .input(ResourceDeleteManyArgsSchema) .mutation(async ({ input }) => { return await this.resourceService.deleteMany(input); }), findFirst: this.trpc.procedure .input(ResourceFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword .query(async ({ input }) => { return await this.resourceService.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.resourceService.softDeleteByIds(input.ids); }), updateOrder: this.trpc.protectProcedure .input(UpdateOrderSchema) .mutation(async ({ input }) => { return this.resourceService.updateOrder(input); }), findMany: this.trpc.procedure .input(ResourceFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword .query(async ({ input }) => { return await this.resourceService.findMany(input); }), findManyWithCursor: this.trpc.protectProcedure .input(z.object({ cursor: z.any().nullish(), take: z.number().nullish(), where: ResourceWhereInputSchema.nullish(), select: ResourceSelectSchema.nullish() })) .query(async ({ ctx, input }) => { const { staff } = ctx; return await this.resourceService.findManyWithCursor(input); }), }); }