add
This commit is contained in:
parent
6b67107b8c
commit
8c87e39c6a
|
@ -3,26 +3,29 @@ 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 });
|
return await this.courseService.create(input, { staff });
|
||||||
}),
|
}),
|
||||||
update: this.trpc.protectProcedure
|
update: this.trpc.protectProcedure
|
||||||
|
@ -31,7 +34,8 @@ export class CourseRouter {
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
return await this.courseService.update(input, { staff });
|
return await this.courseService.update(input, { staff });
|
||||||
}),
|
}),
|
||||||
createMany: this.trpc.protectProcedure.input(z.array(CourseCreateManyInputSchema))
|
createMany: this.trpc.protectProcedure
|
||||||
|
.input(z.array(CourseCreateManyInputSchema))
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
|
|
||||||
|
@ -63,22 +67,26 @@ export class CourseRouter {
|
||||||
return await this.courseService.findMany(input);
|
return await this.courseService.findMany(input);
|
||||||
}),
|
}),
|
||||||
findManyWithCursor: this.trpc.protectProcedure
|
findManyWithCursor: this.trpc.protectProcedure
|
||||||
.input(z.object({
|
.input(
|
||||||
|
z.object({
|
||||||
cursor: z.any().nullish(),
|
cursor: z.any().nullish(),
|
||||||
take: z.number().optional(),
|
take: z.number().optional(),
|
||||||
where: CourseWhereInputSchema.optional(),
|
where: CourseWhereInputSchema.optional(),
|
||||||
select: CourseSelectSchema.optional()
|
select: CourseSelectSchema.optional(),
|
||||||
}))
|
}),
|
||||||
|
)
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
return await this.courseService.findManyWithCursor(input);
|
return await this.courseService.findManyWithCursor(input);
|
||||||
}),
|
}),
|
||||||
findManyWithPagination: this.trpc.procedure
|
findManyWithPagination: this.trpc.procedure
|
||||||
.input(z.object({
|
.input(
|
||||||
|
z.object({
|
||||||
page: z.number().optional(),
|
page: z.number().optional(),
|
||||||
pageSize: z.number().optional(),
|
pageSize: z.number().optional(),
|
||||||
where: CourseWhereInputSchema.optional(),
|
where: CourseWhereInputSchema.optional(),
|
||||||
select: CourseSelectSchema.optional()
|
select: CourseSelectSchema.optional(),
|
||||||
})) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
|
}),
|
||||||
|
) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
return await this.courseService.findManyWithPagination(input);
|
return await this.courseService.findManyWithPagination(input);
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue