75 lines
2.3 KiB
TypeScript
Executable File
75 lines
2.3 KiB
TypeScript
Executable File
import { Injectable } from '@nestjs/common';
|
|
import { TrpcService } from '@server/trpc/trpc.service';
|
|
import { StudentService } from './student.service';
|
|
import { z, ZodType } from 'zod';
|
|
import { Prisma } from '@nice/common';
|
|
|
|
const StudentCreateArgsSchema: ZodType<Prisma.StudentCreateArgs> = z.any();
|
|
const StudentUpdateArgsSchema: ZodType<Prisma.StudentUpdateArgs> = z.any();
|
|
const StudentFindManyArgsSchema: ZodType<Prisma.StudentFindManyArgs> = z.any();
|
|
const StudentWhereUniqueInputSchema: ZodType<Prisma.StudentWhereUniqueInput> = z.any();
|
|
|
|
@Injectable()
|
|
export class StudentRouter {
|
|
constructor(
|
|
private readonly trpc: TrpcService,
|
|
private readonly studentService: StudentService,
|
|
) {}
|
|
|
|
router = this.trpc.router({
|
|
create: this.trpc.procedure
|
|
.input(StudentCreateArgsSchema)
|
|
.mutation(async ({ input }) => {
|
|
return await this.studentService.create(input);
|
|
}),
|
|
|
|
update: this.trpc.procedure
|
|
.input(StudentUpdateArgsSchema)
|
|
.mutation(async ({ input }) => {
|
|
return await this.studentService.update(input);
|
|
}),
|
|
softDeleteByIds: this.trpc.procedure
|
|
.input(
|
|
z.object({
|
|
ids: z.array(z.string()),
|
|
data: StudentUpdateArgsSchema.nullish(),
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await this.studentService.softDeleteByIds(input.ids);
|
|
}),
|
|
delete: this.trpc.procedure
|
|
.input(StudentWhereUniqueInputSchema)
|
|
.mutation(async ({ input }) => {
|
|
return await this.studentService.delete({ where: input });
|
|
}),
|
|
|
|
findMany: this.trpc.procedure
|
|
.input(StudentFindManyArgsSchema)
|
|
.query(async ({ input }) => {
|
|
return await this.studentService.findMany(input);
|
|
}),
|
|
|
|
findByClass: this.trpc.procedure
|
|
.input(z.number())
|
|
.query(async ({ input }) => {
|
|
return await this.studentService.findByClass(input);
|
|
}),
|
|
|
|
findWithScores: this.trpc.procedure
|
|
.input(z.number())
|
|
.query(async ({ input }) => {
|
|
return await this.studentService.findWithScores(input);
|
|
}),
|
|
|
|
search: this.trpc.procedure
|
|
.input(z.object({
|
|
name: z.string().optional(),
|
|
classId: z.number().optional(),
|
|
limit: z.number().optional()
|
|
}))
|
|
.query(async ({ input }) => {
|
|
return await this.studentService.search(input);
|
|
}),
|
|
});
|
|
} |