refactor(selects): moved select: lines to shared file
This commit is contained in:
parent
5e49bc5df6
commit
e7a50df5e5
|
|
@ -2,6 +2,7 @@ import { Injectable, NotFoundException } from "@nestjs/common";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
import { GetShiftDto } from "../dtos/shift-get.dto";
|
import { GetShiftDto } from "../dtos/shift-get.dto";
|
||||||
import { toStringFromDate, toStringFromHHmm } from "../../../../utils/date-time-helpers";
|
import { toStringFromDate, toStringFromHHmm } from "../../../../utils/date-time-helpers";
|
||||||
|
import { shift_select } from "src/time-and-attendance/utils/selects.utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _____________________________________________________________________________________
|
* _____________________________________________________________________________________
|
||||||
|
|
@ -26,17 +27,7 @@ export class ShiftsGetService {
|
||||||
|
|
||||||
const rows = await this.prisma.shifts.findMany({
|
const rows = await this.prisma.shifts.findMany({
|
||||||
where: { id: { in: shift_ids } },
|
where: { id: { in: shift_ids } },
|
||||||
select: {
|
select: shift_select,
|
||||||
id: true,
|
|
||||||
timesheet_id: true,
|
|
||||||
bank_code_id: true,
|
|
||||||
date: true,
|
|
||||||
start_time: true,
|
|
||||||
end_time: true,
|
|
||||||
is_remote: true,
|
|
||||||
is_approved: true,
|
|
||||||
comment: true,
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(rows.length !== shift_ids.length) {
|
if(rows.length !== shift_ids.length) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { updateShiftDto } from "../dtos/shift-update.dto";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
import { GetShiftDto } from "../dtos/shift-get.dto";
|
import { GetShiftDto } from "../dtos/shift-get.dto";
|
||||||
import { ShiftDto } from "../dtos/shift-create.dto";
|
import { ShiftDto } from "../dtos/shift-create.dto";
|
||||||
|
import { shift_select } from "src/time-and-attendance/utils/selects.utils";
|
||||||
|
|
||||||
type Normalized = { date: Date; start_time: Date; end_time: Date; };
|
type Normalized = { date: Date; start_time: Date; end_time: Date; };
|
||||||
|
|
||||||
|
|
@ -136,10 +137,7 @@ export class ShiftsUpsertService {
|
||||||
is_remote: dto.is_remote,
|
is_remote: dto.is_remote,
|
||||||
comment: dto.comment ?? undefined,
|
comment: dto.comment ?? undefined,
|
||||||
},
|
},
|
||||||
select: {
|
select: shift_select,
|
||||||
timesheet_id: true, bank_code_id: true, date: true,
|
|
||||||
start_time: true, end_time: true, is_remote: true, is_approved: true, comment: true,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
existing.push({ start_time: row.start_time, end_time: row.end_time });
|
existing.push({ start_time: row.start_time, end_time: row.end_time });
|
||||||
|
|
@ -181,17 +179,7 @@ export class ShiftsUpsertService {
|
||||||
const shift_ids = updates.map(update_shift => update_shift.id);
|
const shift_ids = updates.map(update_shift => update_shift.id);
|
||||||
const rows = await tx.shifts.findMany({
|
const rows = await tx.shifts.findMany({
|
||||||
where: { id: { in: shift_ids } },
|
where: { id: { in: shift_ids } },
|
||||||
select: {
|
select: shift_select,
|
||||||
id: true,
|
|
||||||
timesheet_id: true,
|
|
||||||
bank_code_id: true,
|
|
||||||
date: true,
|
|
||||||
start_time: true,
|
|
||||||
end_time: true,
|
|
||||||
is_remote: true,
|
|
||||||
is_approved: true,
|
|
||||||
comment: true,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const regroup_id = new Map(rows.map(r => [r.id, r]));
|
const regroup_id = new Map(rows.map(r => [r.id, r]));
|
||||||
|
|
||||||
|
|
@ -295,16 +283,7 @@ export class ShiftsUpsertService {
|
||||||
const row = await tx.shifts.update({
|
const row = await tx.shifts.update({
|
||||||
where: { id: planned.exist_shift.id },
|
where: { id: planned.exist_shift.id },
|
||||||
data,
|
data,
|
||||||
select: {
|
select: shift_select,
|
||||||
timesheet_id: true,
|
|
||||||
bank_code_id: true,
|
|
||||||
date: true,
|
|
||||||
start_time: true,
|
|
||||||
end_time: true,
|
|
||||||
is_remote: true,
|
|
||||||
is_approved: true,
|
|
||||||
comment: true,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const summary_new = await this.overtime.getWeekOvertimeSummary(row.timesheet_id, planned.exist_shift.date, tx);
|
const summary_new = await this.overtime.getWeekOvertimeSummary(row.timesheet_id, planned.exist_shift.date, tx);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { GetTimesheetsOverviewService } from "src/time-and-attendance/modules/ti
|
||||||
import { SchedulePresetsQueryService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service";
|
import { SchedulePresetsQueryService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service";
|
||||||
import { SchedulePresetsController } from "src/time-and-attendance/modules/time-tracker/schedule-presets/controller/schedule-presets.controller";
|
import { SchedulePresetsController } from "src/time-and-attendance/modules/time-tracker/schedule-presets/controller/schedule-presets.controller";
|
||||||
import { ExpensesArchivalService } from "src/time-and-attendance/modules/expenses/services/expenses-archival.service";
|
import { ExpensesArchivalService } from "src/time-and-attendance/modules/expenses/services/expenses-archival.service";
|
||||||
// import { LeaveRequestController } from "src/time-and-attendance/modules/leave-requests/controllers/leave-requests.controller";
|
|
||||||
import { BusinessLogicsModule } from "src/time-and-attendance/domains/business-logics.module";
|
import { BusinessLogicsModule } from "src/time-and-attendance/domains/business-logics.module";
|
||||||
import { ExpenseUpsertService } from "src/time-and-attendance/modules/expenses/services/expense-upsert.service";
|
import { ExpenseUpsertService } from "src/time-and-attendance/modules/expenses/services/expense-upsert.service";
|
||||||
import { ShiftsUpsertService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service";
|
import { ShiftsUpsertService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service";
|
||||||
|
|
@ -23,7 +22,6 @@ import { Module } from "@nestjs/common";
|
||||||
ShiftController,
|
ShiftController,
|
||||||
SchedulePresetsController,
|
SchedulePresetsController,
|
||||||
ExpenseController,
|
ExpenseController,
|
||||||
// LeaveRequestController,
|
|
||||||
|
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,17 @@ export const expense_select = {
|
||||||
is_approved: true,
|
is_approved: true,
|
||||||
} satisfies Prisma.ExpensesSelect;
|
} satisfies Prisma.ExpensesSelect;
|
||||||
|
|
||||||
|
export const shift_select = {
|
||||||
|
id: true,
|
||||||
|
timesheet_id: true,
|
||||||
|
bank_code_id: true,
|
||||||
|
date: true,
|
||||||
|
start_time: true,
|
||||||
|
end_time: true,
|
||||||
|
is_remote: true,
|
||||||
|
is_approved: true,
|
||||||
|
comment: true,
|
||||||
|
} satisfies Prisma.ShiftsSelect;
|
||||||
|
|
||||||
export const leaveRequestsSelect = {
|
export const leaveRequestsSelect = {
|
||||||
id: true,
|
id: true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user