2024-09-03 20:19:33 +08:00
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { TrpcService } from '@server/trpc/trpc.service';
|
|
|
|
import { StaffService } from './staff.service'; // Adjust the import path as necessary
|
2025-01-06 08:45:23 +08:00
|
|
|
import { StaffMethodSchema, Prisma, UpdateOrderSchema } from '@nice/common';
|
2024-12-30 08:26:40 +08:00
|
|
|
import { z, ZodType } from 'zod';
|
|
|
|
import { StaffRowService } from './staff.row.service';
|
|
|
|
const StaffCreateArgsSchema: ZodType<Prisma.StaffCreateArgs> = z.any();
|
|
|
|
const StaffUpdateArgsSchema: ZodType<Prisma.StaffUpdateArgs> = z.any();
|
|
|
|
const StaffFindFirstArgsSchema: ZodType<Prisma.StaffFindFirstArgs> = z.any();
|
|
|
|
const StaffDeleteManyArgsSchema: ZodType<Prisma.StaffDeleteManyArgs> = z.any();
|
|
|
|
const StaffWhereInputSchema: ZodType<Prisma.StaffWhereInput> = z.any();
|
|
|
|
const StaffSelectSchema: ZodType<Prisma.StaffSelect> = z.any();
|
2025-02-06 16:32:52 +08:00
|
|
|
const StaffUpdateInputSchema: ZodType<Prisma.StaffUpdateInput> = z.any();
|
2024-12-30 08:26:40 +08:00
|
|
|
const StaffFindManyArgsSchema: ZodType<Prisma.StaffFindManyArgs> = z.any();
|
2024-09-03 20:19:33 +08:00
|
|
|
@Injectable()
|
|
|
|
export class StaffRouter {
|
|
|
|
constructor(
|
|
|
|
private readonly trpc: TrpcService,
|
|
|
|
private readonly staffService: StaffService,
|
2025-02-06 16:32:52 +08:00
|
|
|
private readonly staffRowService: StaffRowService,
|
|
|
|
) {}
|
2024-09-03 20:19:33 +08:00
|
|
|
|
|
|
|
router = this.trpc.router({
|
|
|
|
create: this.trpc.procedure
|
2024-12-30 08:26:40 +08:00
|
|
|
.input(StaffCreateArgsSchema) // Assuming StaffMethodSchema.create is the Zod schema for creating staff
|
2024-09-03 20:19:33 +08:00
|
|
|
.mutation(async ({ input }) => {
|
|
|
|
return await this.staffService.create(input);
|
|
|
|
}),
|
|
|
|
|
|
|
|
update: this.trpc.procedure
|
2024-12-30 08:26:40 +08:00
|
|
|
.input(StaffUpdateArgsSchema) // Assuming StaffMethodSchema.update is the Zod schema for updating staff
|
2024-09-03 20:19:33 +08:00
|
|
|
.mutation(async ({ input }) => {
|
|
|
|
return await this.staffService.update(input);
|
|
|
|
}),
|
2024-12-30 08:26:40 +08:00
|
|
|
updateUserDomain: this.trpc.protectProcedure
|
|
|
|
.input(
|
|
|
|
z.object({
|
2025-02-06 16:32:52 +08:00
|
|
|
domainId: z.string(),
|
2024-12-30 08:26:40 +08:00
|
|
|
}),
|
|
|
|
)
|
|
|
|
.mutation(async ({ input, ctx }) => {
|
|
|
|
return await this.staffService.updateUserDomain(input, ctx.staff);
|
2024-09-03 20:19:33 +08:00
|
|
|
}),
|
2024-12-30 08:26:40 +08:00
|
|
|
softDeleteByIds: this.trpc.protectProcedure
|
|
|
|
.input(
|
|
|
|
z.object({
|
|
|
|
ids: z.array(z.string()),
|
|
|
|
data: StaffUpdateInputSchema.nullish(),
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.mutation(async ({ input }) => {
|
|
|
|
return await this.staffService.softDeleteByIds(input.ids, input.data);
|
2024-09-03 20:19:33 +08:00
|
|
|
}),
|
|
|
|
findByDept: this.trpc.procedure
|
2024-12-30 08:26:40 +08:00
|
|
|
.input(StaffMethodSchema.findByDept)
|
2024-09-03 20:19:33 +08:00
|
|
|
.query(async ({ input }) => {
|
|
|
|
return await this.staffService.findByDept(input);
|
|
|
|
}),
|
|
|
|
findMany: this.trpc.procedure
|
2024-12-30 08:26:40 +08:00
|
|
|
.input(StaffFindManyArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
|
2024-09-03 20:19:33 +08:00
|
|
|
.query(async ({ input }) => {
|
|
|
|
return await this.staffService.findMany(input);
|
2024-12-30 08:26:40 +08:00
|
|
|
}),
|
|
|
|
getRows: this.trpc.protectProcedure
|
|
|
|
.input(StaffMethodSchema.getRows)
|
|
|
|
.query(async ({ input, ctx }) => {
|
|
|
|
return await this.staffRowService.getRows(input, ctx.staff);
|
|
|
|
}),
|
|
|
|
findFirst: this.trpc.protectProcedure
|
|
|
|
.input(StaffFindFirstArgsSchema)
|
|
|
|
.query(async ({ ctx, input }) => {
|
|
|
|
const { staff } = ctx;
|
|
|
|
return await this.staffService.findFirst(input);
|
|
|
|
}),
|
2025-02-06 16:32:52 +08:00
|
|
|
updateOrder: this.trpc.protectProcedure
|
|
|
|
.input(UpdateOrderSchema)
|
|
|
|
.mutation(async ({ input }) => {
|
|
|
|
return this.staffService.updateOrder(input);
|
|
|
|
}),
|
2024-09-03 20:19:33 +08:00
|
|
|
});
|
|
|
|
}
|