student-manage/apps/server/src/models/driver/driver.router.ts

70 lines
2.2 KiB
TypeScript
Raw Normal View History

2025-05-13 15:58:47 +08:00
import { Injectable } from '@nestjs/common';
import { TrpcService } from '@server/trpc/trpc.service';
import { DriverService } from './driver.service';
import { z, ZodType } from 'zod';
import { Prisma } from '@nice/common';
const CourseCreateArgsSchema: ZodType<Prisma.CarCreateArgs> = z.any();
const CourseUpdateArgsSchema: ZodType<Prisma.CarUpdateArgs> = z.any();
const CourseFindManyArgsSchema: ZodType<Prisma.CarFindManyArgs> = z.any();
const CourseWhereUniqueInputSchema: ZodType<Prisma.CarWhereUniqueInput> = z.any();
@Injectable()
export class DriverRouter {
constructor(
private readonly trpc: TrpcService,
private readonly driverService: DriverService,
) {}
router = this.trpc.router({
create: this.trpc.protectProcedure
.input(CourseCreateArgsSchema)
.mutation(async ({ input }) => {
return await this.driverService.create(input);
}),
// update: this.trpc.protectProcedure
// .input(CourseUpdateArgsSchema)
// .mutation(async ({ input }) => {
// return await this.driverService.update(input);
// }),
softDeleteByIds: this.trpc.protectProcedure
.input(
z.object({
ids: z.array(z.string()),
data: CourseUpdateArgsSchema.nullish(),
}),
)
.mutation(async ({ input }) => {
return await this.driverService.softDeleteByIds(input.ids);
}),
// delete: this.trpc.protectProcedure
// .input(CourseWhereUniqueInputSchema)
// .mutation(async ({ input }) => {
// return await this.driverService.delete({ where: input });
// }),
// findMany: this.trpc.procedure
// .input(CourseFindManyArgsSchema)
// .query(async ({ input }) => {
// return await this.driverService.findMany(input);
// }),
findWithScores: this.trpc.procedure
.input(z.number())
.query(async ({ input }) => {
return await this.driverService.findWithScores(input);
}),
search: this.trpc.procedure
.input(z.object({
name: z.string().optional(),
courseId: z.number().optional(),
limit: z.number().optional()
}))
.query(async ({ input }) => {
return await this.driverService.search(input);
}),
});
}