book_manage/apps/server/src/models/enrollment/enrollment.router.ts

71 lines
3.4 KiB
TypeScript
Raw Normal View History

2024-12-31 15:57:32 +08:00
import { Injectable } from '@nestjs/common';
import { TrpcService } from '@server/trpc/trpc.service';
import { Prisma, UpdateOrderSchema } from '@nicestack/common';
import { EnrollmentService } from './enrollment.service';
import { z, ZodType } from 'zod';
const EnrollmentCreateArgsSchema: ZodType<Prisma.EnrollmentCreateArgs> = z.any()
const EnrollmentCreateManyInputSchema: ZodType<Prisma.EnrollmentCreateManyInput> = z.any()
const EnrollmentDeleteManyArgsSchema: ZodType<Prisma.EnrollmentDeleteManyArgs> = z.any()
const EnrollmentFindManyArgsSchema: ZodType<Prisma.EnrollmentFindManyArgs> = z.any()
const EnrollmentFindFirstArgsSchema: ZodType<Prisma.EnrollmentFindFirstArgs> = z.any()
const EnrollmentWhereInputSchema: ZodType<Prisma.EnrollmentWhereInput> = z.any()
const EnrollmentSelectSchema: ZodType<Prisma.EnrollmentSelect> = z.any()
@Injectable()
export class EnrollmentRouter {
constructor(
private readonly trpc: TrpcService,
private readonly enrollmentService: EnrollmentService,
) { }
router = this.trpc.router({
create: this.trpc.protectProcedure
.input(EnrollmentCreateArgsSchema)
.mutation(async ({ ctx, input }) => {
const { staff } = ctx;
return await this.enrollmentService.create(input, staff);
}),
createMany: this.trpc.protectProcedure.input(z.array(EnrollmentCreateManyInputSchema))
.mutation(async ({ ctx, input }) => {
const { staff } = ctx;
return await this.enrollmentService.createMany({ data: input }, staff);
}),
deleteMany: this.trpc.procedure
.input(EnrollmentDeleteManyArgsSchema)
.mutation(async ({ input }) => {
return await this.enrollmentService.deleteMany(input);
}),
findFirst: this.trpc.procedure
.input(EnrollmentFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
.query(async ({ input }) => {
return await this.enrollmentService.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.enrollmentService.softDeleteByIds(input.ids);
}),
updateOrder: this.trpc.protectProcedure
.input(UpdateOrderSchema)
.mutation(async ({ input }) => {
return this.enrollmentService.updateOrder(input);
}),
findMany: this.trpc.procedure
.input(EnrollmentFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
.query(async ({ input }) => {
return await this.enrollmentService.findMany(input);
}),
findManyWithCursor: this.trpc.protectProcedure
.input(z.object({
cursor: z.any().nullish(),
take: z.number().nullish(),
where: EnrollmentWhereInputSchema.nullish(),
select: EnrollmentSelectSchema.nullish()
}))
.query(async ({ ctx, input }) => {
const { staff } = ctx;
return await this.enrollmentService.findManyWithCursor(input);
}),
});
}