fix(shifts): fix bank_code_id by type
This commit is contained in:
parent
feeb19bbf0
commit
8ad8076f4d
|
|
@ -94,6 +94,7 @@ export class ShiftsHelpersService {
|
||||||
date_only: Date;
|
date_only: Date;
|
||||||
norm: Normalized;
|
norm: Normalized;
|
||||||
bank_code_id: number;
|
bank_code_id: number;
|
||||||
|
comment?: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { timesheet_id, date_only, norm, bank_code_id } = params;
|
const { timesheet_id, date_only, norm, bank_code_id } = params;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { PrismaService } from "src/prisma/prisma.service";
|
||||||
import { toDateOnly } from "../helpers/shifts-date-time-helpers";
|
import { toDateOnly } from "../helpers/shifts-date-time-helpers";
|
||||||
import { UpsertAction } from "src/modules/shared/types/upsert-actions.types";
|
import { UpsertAction } from "src/modules/shared/types/upsert-actions.types";
|
||||||
import { ShiftsHelpersService } from "../helpers/shifts.helpers";
|
import { ShiftsHelpersService } from "../helpers/shifts.helpers";
|
||||||
|
import { BankCodesResolver } from "src/modules/shared/utils/resolve-bank-type-id.utils";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ShiftsCommandService extends BaseApprovalService<Shifts> {
|
export class ShiftsCommandService extends BaseApprovalService<Shifts> {
|
||||||
|
|
@ -16,6 +17,7 @@ export class ShiftsCommandService extends BaseApprovalService<Shifts> {
|
||||||
constructor(
|
constructor(
|
||||||
prisma: PrismaService,
|
prisma: PrismaService,
|
||||||
private readonly emailResolver: EmailToIdResolver,
|
private readonly emailResolver: EmailToIdResolver,
|
||||||
|
private readonly typeResolver: BankCodesResolver,
|
||||||
private readonly helpersService: ShiftsHelpersService,
|
private readonly helpersService: ShiftsHelpersService,
|
||||||
) { super(prisma); }
|
) { super(prisma); }
|
||||||
|
|
||||||
|
|
@ -99,7 +101,7 @@ export class ShiftsCommandService extends BaseApprovalService<Shifts> {
|
||||||
end_time: new_norm_shift.end_time,
|
end_time: new_norm_shift.end_time,
|
||||||
is_remote: new_norm_shift.is_remote,
|
is_remote: new_norm_shift.is_remote,
|
||||||
is_approved: new_norm_shift.is_approved,
|
is_approved: new_norm_shift.is_approved,
|
||||||
comment: new_norm_shift.comment ?? '',
|
comment: new_norm_shift.comment ?? null,
|
||||||
bank_code_id: new_bank_code_id,
|
bank_code_id: new_bank_code_id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -144,7 +146,7 @@ export class ShiftsCommandService extends BaseApprovalService<Shifts> {
|
||||||
start_time: new_norm_shift.start_time,
|
start_time: new_norm_shift.start_time,
|
||||||
end_time: new_norm_shift.end_time,
|
end_time: new_norm_shift.end_time,
|
||||||
is_remote: new_norm_shift.is_remote,
|
is_remote: new_norm_shift.is_remote,
|
||||||
comment: new_norm_shift.comment ?? '',
|
comment: new_norm_shift.comment ?? null,
|
||||||
bank_code_id: new_bank_code_id,
|
bank_code_id: new_bank_code_id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -169,13 +171,13 @@ export class ShiftsCommandService extends BaseApprovalService<Shifts> {
|
||||||
const { id: timesheet_id } = await this.helpersService.ensureTimesheet(tx, employee_id, date_only);
|
const { id: timesheet_id } = await this.helpersService.ensureTimesheet(tx, employee_id, date_only);
|
||||||
|
|
||||||
const old_norm_shift = await this.helpersService.normalizeRequired(dto.old_shift, 'old_shift');
|
const old_norm_shift = await this.helpersService.normalizeRequired(dto.old_shift, 'old_shift');
|
||||||
const old_bank_code_id = await this.helpersService.resolveBankIdRequired(tx, old_norm_shift.type, 'old_shift');
|
const old_bank_code_id = await this.typeResolver.findByType(old_norm_shift.type);
|
||||||
|
|
||||||
const existing = await this.helpersService.findExactOldShift(tx, {
|
const existing = await this.helpersService.findExactOldShift(tx, {
|
||||||
timesheet_id,
|
timesheet_id,
|
||||||
date_only,
|
date_only,
|
||||||
norm: old_norm_shift,
|
norm: old_norm_shift,
|
||||||
bank_code_id: old_bank_code_id,
|
bank_code_id: old_bank_code_id.id,
|
||||||
});
|
});
|
||||||
if(!existing) throw new NotFoundException('[SHIFT_STALE]- The shift was modified or deleted by someone else');
|
if(!existing) throw new NotFoundException('[SHIFT_STALE]- The shift was modified or deleted by someone else');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user