71 lines
3.3 KiB
TypeScript
71 lines
3.3 KiB
TypeScript
![]() |
import { Injectable } from '@nestjs/common';
|
||
|
import { TrpcService } from '@server/trpc/trpc.service';
|
||
|
import { Prisma, UpdateOrderSchema } from '@nicestack/common';
|
||
|
import { SectionService } from './section.service';
|
||
|
import { z, ZodType } from 'zod';
|
||
|
const SectionCreateArgsSchema: ZodType<Prisma.SectionCreateArgs> = z.any()
|
||
|
const SectionCreateManyInputSchema: ZodType<Prisma.SectionCreateManyInput> = z.any()
|
||
|
const SectionDeleteManyArgsSchema: ZodType<Prisma.SectionDeleteManyArgs> = z.any()
|
||
|
const SectionFindManyArgsSchema: ZodType<Prisma.SectionFindManyArgs> = z.any()
|
||
|
const SectionFindFirstArgsSchema: ZodType<Prisma.SectionFindFirstArgs> = z.any()
|
||
|
const SectionWhereInputSchema: ZodType<Prisma.SectionWhereInput> = z.any()
|
||
|
const SectionSelectSchema: ZodType<Prisma.SectionSelect> = z.any()
|
||
|
|
||
|
@Injectable()
|
||
|
export class SectionRouter {
|
||
|
constructor(
|
||
|
private readonly trpc: TrpcService,
|
||
|
private readonly sectionService: SectionService,
|
||
|
) { }
|
||
|
router = this.trpc.router({
|
||
|
create: this.trpc.protectProcedure
|
||
|
.input(SectionCreateArgsSchema)
|
||
|
.mutation(async ({ ctx, input }) => {
|
||
|
const { staff } = ctx;
|
||
|
return await this.sectionService.create(input, staff);
|
||
|
}),
|
||
|
createMany: this.trpc.protectProcedure.input(z.array(SectionCreateManyInputSchema))
|
||
|
.mutation(async ({ ctx, input }) => {
|
||
|
const { staff } = ctx;
|
||
|
|
||
|
return await this.sectionService.createMany({ data: input }, staff);
|
||
|
}),
|
||
|
deleteMany: this.trpc.procedure
|
||
|
.input(SectionDeleteManyArgsSchema)
|
||
|
.mutation(async ({ input }) => {
|
||
|
return await this.sectionService.deleteMany(input);
|
||
|
}),
|
||
|
findFirst: this.trpc.procedure
|
||
|
.input(SectionFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
|
||
|
.query(async ({ input }) => {
|
||
|
return await this.sectionService.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.sectionService.softDeleteByIds(input.ids);
|
||
|
}),
|
||
|
updateOrder: this.trpc.protectProcedure
|
||
|
.input(UpdateOrderSchema)
|
||
|
.mutation(async ({ input }) => {
|
||
|
return this.sectionService.updateOrder(input);
|
||
|
}),
|
||
|
findMany: this.trpc.procedure
|
||
|
.input(SectionFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
|
||
|
.query(async ({ input }) => {
|
||
|
return await this.sectionService.findMany(input);
|
||
|
}),
|
||
|
findManyWithCursor: this.trpc.protectProcedure
|
||
|
.input(z.object({
|
||
|
cursor: z.any().nullish(),
|
||
|
take: z.number().nullish(),
|
||
|
where: SectionWhereInputSchema.nullish(),
|
||
|
select: SectionSelectSchema.nullish()
|
||
|
}))
|
||
|
.query(async ({ ctx, input }) => {
|
||
|
const { staff } = ctx;
|
||
|
return await this.sectionService.findManyWithCursor(input);
|
||
|
}),
|
||
|
});
|
||
|
}
|