70 lines
2.1 KiB
TypeScript
Executable File
70 lines
2.1 KiB
TypeScript
Executable File
import { Injectable } from '@nestjs/common';
|
|
import { TrpcService } from '@server/trpc/trpc.service';
|
|
import { CarService } from './car.service';
|
|
import { z, ZodType } from 'zod';
|
|
import { Prisma } from '@nice/common';
|
|
|
|
const CarCreateArgsSchema: ZodType<Prisma.CarCreateArgs> = z.any();
|
|
const CarUpdateArgsSchema: ZodType<Prisma.CarUpdateArgs> = z.any();
|
|
const CarFindManyArgsSchema: ZodType<Prisma.CarFindManyArgs> = z.any();
|
|
const CarWhereUniqueInputSchema: ZodType<Prisma.CarWhereUniqueInput> = z.any();
|
|
|
|
@Injectable()
|
|
export class CarRouter {
|
|
constructor(
|
|
private readonly trpc: TrpcService,
|
|
private readonly carService: CarService,
|
|
) {}
|
|
|
|
router = this.trpc.router({
|
|
create: this.trpc.protectProcedure
|
|
.input(CarCreateArgsSchema)
|
|
.mutation(async ({ input }) => {
|
|
return await this.carService.create(input);
|
|
}),
|
|
|
|
update: this.trpc.protectProcedure
|
|
.input(CarUpdateArgsSchema)
|
|
.mutation(async ({ input }) => {
|
|
return await this.carService.update(input);
|
|
}),
|
|
softDeleteByIds: this.trpc.protectProcedure
|
|
.input(
|
|
z.object({
|
|
ids: z.array(z.string()),
|
|
data: CarFindManyArgsSchema.nullish(),
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await this.carService.softDeleteByIds(input.ids);
|
|
}),
|
|
delete: this.trpc.protectProcedure
|
|
.input(CarWhereUniqueInputSchema)
|
|
.mutation(async ({ input }) => {
|
|
return await this.carService.delete({ where: input });
|
|
}),
|
|
|
|
findMany: this.trpc.procedure
|
|
.input(CarFindManyArgsSchema)
|
|
.query(async ({ input }) => {
|
|
return await this.carService.findMany(input);
|
|
}),
|
|
|
|
|
|
findWithScores: this.trpc.procedure
|
|
.input(z.number())
|
|
.query(async ({ input }) => {
|
|
return await this.carService.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.carService.search(input);
|
|
}),
|
|
});
|
|
} |