29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { Prisma, PrismaClient } from "@prisma/client";
|
|
import { NotFoundException } from "@nestjs/common";
|
|
import { PrismaService } from "src/prisma/prisma.service";
|
|
import { ShiftKey } from "src/time-and-attendance/utils/type.utils";
|
|
|
|
type Tx = Prisma.TransactionClient | PrismaClient;
|
|
|
|
export class ShiftIdResolver {
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
readonly findShiftIdByData = async ( key: ShiftKey, client?: Tx ): Promise<{id:number}> => {
|
|
const db = client ?? this.prisma;
|
|
const shift = await db.shifts.findFirst({
|
|
where: {
|
|
timesheet_id: key.timesheet_id,
|
|
bank_code_id: key.bank_code_id,
|
|
date: key.date,
|
|
start_time: key.start_time,
|
|
end_time: key.end_time,
|
|
is_remote: key.is_remote,
|
|
comment: key.comment,
|
|
},
|
|
select: { id: true },
|
|
});
|
|
|
|
if(!shift) throw new NotFoundException(`shift not found`);
|
|
return { id: shift.id };
|
|
};
|
|
} |