This commit is contained in:
ditiqi 2025-01-27 22:43:10 +08:00
parent 6b67107b8c
commit 8c87e39c6a
1 changed files with 84 additions and 76 deletions

View File

@ -3,84 +3,92 @@ import { TrpcService } from '@server/trpc/trpc.service';
import { Prisma, UpdateOrderSchema } from '@nice/common'; import { Prisma, UpdateOrderSchema } from '@nice/common';
import { CourseService } from './course.service'; import { CourseService } from './course.service';
import { z, ZodType } from 'zod'; import { z, ZodType } from 'zod';
const CourseCreateArgsSchema: ZodType<Prisma.CourseCreateArgs> = z.any() const CourseCreateArgsSchema: ZodType<Prisma.CourseCreateArgs> = z.any();
const CourseUpdateArgsSchema: ZodType<Prisma.CourseUpdateArgs> = z.any() const CourseUpdateArgsSchema: ZodType<Prisma.CourseUpdateArgs> = z.any();
const CourseCreateManyInputSchema: ZodType<Prisma.CourseCreateManyInput> = z.any() const CourseCreateManyInputSchema: ZodType<Prisma.CourseCreateManyInput> =
const CourseDeleteManyArgsSchema: ZodType<Prisma.CourseDeleteManyArgs> = z.any() z.any();
const CourseFindManyArgsSchema: ZodType<Prisma.CourseFindManyArgs> = z.any() const CourseDeleteManyArgsSchema: ZodType<Prisma.CourseDeleteManyArgs> =
const CourseFindFirstArgsSchema: ZodType<Prisma.CourseFindFirstArgs> = z.any() z.any();
const CourseWhereInputSchema: ZodType<Prisma.CourseWhereInput> = z.any() const CourseFindManyArgsSchema: ZodType<Prisma.CourseFindManyArgs> = z.any();
const CourseSelectSchema: ZodType<Prisma.CourseSelect> = z.any() const CourseFindFirstArgsSchema: ZodType<Prisma.CourseFindFirstArgs> = z.any();
const CourseWhereInputSchema: ZodType<Prisma.CourseWhereInput> = z.any();
const CourseSelectSchema: ZodType<Prisma.CourseSelect> = z.any();
@Injectable() @Injectable()
export class CourseRouter { export class CourseRouter {
constructor( constructor(
private readonly trpc: TrpcService, private readonly trpc: TrpcService,
private readonly courseService: CourseService, private readonly courseService: CourseService,
) { } ) {}
router = this.trpc.router({ router = this.trpc.router({
create: this.trpc.protectProcedure create: this.trpc.protectProcedure
.input(CourseCreateArgsSchema) .input(CourseCreateArgsSchema)
.mutation(async ({ ctx, input }) => { .mutation(async ({ ctx, input }) => {
const { staff } = ctx; 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;
return await this.courseService.createMany({ data: input }, staff); return await this.courseService.create(input, { staff });
}), }),
deleteMany: this.trpc.procedure update: this.trpc.protectProcedure
.input(CourseDeleteManyArgsSchema) .input(CourseUpdateArgsSchema)
.mutation(async ({ input }) => { .mutation(async ({ ctx, input }) => {
return await this.courseService.deleteMany(input); const { staff } = ctx;
}), return await this.courseService.update(input, { staff });
findFirst: this.trpc.procedure }),
.input(CourseFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword createMany: this.trpc.protectProcedure
.query(async ({ input }) => { .input(z.array(CourseCreateManyInputSchema))
return await this.courseService.findFirst(input); .mutation(async ({ ctx, input }) => {
}), const { staff } = ctx;
softDeleteByIds: this.trpc.protectProcedure
.input(z.object({ ids: z.array(z.string()) })) // expect input according to the schema return await this.courseService.createMany({ data: input }, staff);
.mutation(async ({ input }) => { }),
return this.courseService.softDeleteByIds(input.ids); deleteMany: this.trpc.procedure
}), .input(CourseDeleteManyArgsSchema)
updateOrder: this.trpc.protectProcedure .mutation(async ({ input }) => {
.input(UpdateOrderSchema) return await this.courseService.deleteMany(input);
.mutation(async ({ input }) => { }),
return this.courseService.updateOrder(input); findFirst: this.trpc.procedure
}), .input(CourseFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
findMany: this.trpc.procedure .query(async ({ input }) => {
.input(CourseFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword return await this.courseService.findFirst(input);
.query(async ({ input }) => { }),
return await this.courseService.findMany(input); softDeleteByIds: this.trpc.protectProcedure
}), .input(z.object({ ids: z.array(z.string()) })) // expect input according to the schema
findManyWithCursor: this.trpc.protectProcedure .mutation(async ({ input }) => {
.input(z.object({ return this.courseService.softDeleteByIds(input.ids);
cursor: z.any().nullish(), }),
take: z.number().optional(), updateOrder: this.trpc.protectProcedure
where: CourseWhereInputSchema.optional(), .input(UpdateOrderSchema)
select: CourseSelectSchema.optional() .mutation(async ({ input }) => {
})) return this.courseService.updateOrder(input);
.query(async ({ ctx, input }) => { }),
return await this.courseService.findManyWithCursor(input); findMany: this.trpc.procedure
}), .input(CourseFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
findManyWithPagination: this.trpc.procedure .query(async ({ input }) => {
.input(z.object({ return await this.courseService.findMany(input);
page: z.number().optional(), }),
pageSize: z.number().optional(), findManyWithCursor: this.trpc.protectProcedure
where: CourseWhereInputSchema.optional(), .input(
select: CourseSelectSchema.optional() z.object({
})) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword cursor: z.any().nullish(),
.query(async ({ input }) => { take: z.number().optional(),
return await this.courseService.findManyWithPagination(input); 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);
}),
});
} }