fix(schedule-preset): adjust services to use consistent dto and field names (mix of shifts and preset_shifts)
This commit is contained in:
parent
b6132c8b35
commit
cb52089db8
|
|
@ -1,9 +1,3 @@
|
|||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
||||
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
previewFeatures = ["views"]
|
||||
|
|
@ -22,7 +16,6 @@ model Users {
|
|||
phone_number String
|
||||
residence String?
|
||||
role Roles @default(GUEST)
|
||||
|
||||
employee Employees? @relation("UserEmployee")
|
||||
oauth_sessions OAuthSessions[] @relation("UserOAuthSessions")
|
||||
preferences Preferences? @relation("UserPreferences")
|
||||
|
|
@ -33,57 +26,52 @@ model Users {
|
|||
|
||||
model userModuleAccess {
|
||||
id Int @id @default(autoincrement())
|
||||
user Users @relation("UserModuleAccess", fields: [user_id], references: [id])
|
||||
user_id String @unique @db.Uuid
|
||||
|
||||
timesheets Boolean @default(false) //wich allows an employee to enter shifts and expenses
|
||||
timesheets_approval Boolean @default(false) //wich allows the approbation of timesheets by a supervisor or above
|
||||
employee_list Boolean @default(false) //wich shows the lists of employee to show names, emails, titles and profile picture
|
||||
employee_management Boolean @default(false) //wich offers CRUD for employees, schedule_presets and manage module access
|
||||
personal_profile Boolean @default(false) //wich governs profile details, preferances and dashboard access
|
||||
dashboard Boolean @default(false) //wich allows access to the main page of the app
|
||||
timesheets Boolean @default(false)
|
||||
timesheets_approval Boolean @default(false)
|
||||
employee_list Boolean @default(false)
|
||||
employee_management Boolean @default(false)
|
||||
personal_profile Boolean @default(false)
|
||||
dashboard Boolean @default(false)
|
||||
user Users @relation("UserModuleAccess", fields: [user_id], references: [id])
|
||||
|
||||
@@map("user_module_access")
|
||||
}
|
||||
|
||||
model Employees {
|
||||
id Int @id @default(autoincrement())
|
||||
user Users @relation("UserEmployee", fields: [user_id], references: [id])
|
||||
user_id String @unique @db.Uuid
|
||||
supervisor Employees? @relation("EmployeeSupervisor", fields: [supervisor_id], references: [id])
|
||||
supervisor_id Int?
|
||||
schedule_preset SchedulePresets? @relation("EmployeesSchedulePreset", fields: [schedule_preset_id], references: [id])
|
||||
schedule_preset_id Int?
|
||||
|
||||
external_payroll_id Int
|
||||
company_code Int
|
||||
first_work_day DateTime @db.Date
|
||||
last_work_day DateTime? @db.Date
|
||||
supervisor_id Int?
|
||||
job_title String?
|
||||
is_supervisor Boolean @default(false)
|
||||
|
||||
schedule_preset_id Int?
|
||||
schedule_preset SchedulePresets? @relation("EmployeesSchedulePreset", fields: [schedule_preset_id], references: [id])
|
||||
supervisor Employees? @relation("EmployeeSupervisor", fields: [supervisor_id], references: [id])
|
||||
crew Employees[] @relation("EmployeeSupervisor")
|
||||
timesheet Timesheets[] @relation("TimesheetEmployee")
|
||||
user Users @relation("UserEmployee", fields: [user_id], references: [id])
|
||||
leave_request LeaveRequests[] @relation("LeaveRequestEmployee")
|
||||
timesheet Timesheets[] @relation("TimesheetEmployee")
|
||||
|
||||
@@map("employees")
|
||||
}
|
||||
|
||||
model LeaveRequests {
|
||||
id Int @id @default(autoincrement())
|
||||
employee Employees @relation("LeaveRequestEmployee", fields: [employee_id], references: [id])
|
||||
employee_id Int
|
||||
bank_code BankCodes @relation("LeaveRequestBankCodes", fields: [bank_code_id], references: [id])
|
||||
bank_code_id Int
|
||||
|
||||
leave_type LeaveTypes
|
||||
comment String
|
||||
dates DateTime[] @db.Date
|
||||
approval_status LeaveApprovalStatus @default(PENDING)
|
||||
bank_code_id Int
|
||||
payable_hours Decimal? @db.Decimal(5, 2)
|
||||
requested_hours Decimal? @db.Decimal(5, 2)
|
||||
approval_status LeaveApprovalStatus @default(PENDING)
|
||||
leave_type LeaveTypes
|
||||
|
||||
archive LeaveRequestsArchive[] @relation("LeaveRequestToArchive")
|
||||
dates DateTime[] @db.Date
|
||||
bank_code BankCodes @relation("LeaveRequestBankCodes", fields: [bank_code_id], references: [id])
|
||||
employee Employees @relation("LeaveRequestEmployee", fields: [employee_id], references: [id])
|
||||
archive LeaveRequestsArchive? @relation("LeaveRequestToArchive")
|
||||
|
||||
@@unique([employee_id, leave_type, dates], name: "leave_per_employee_date")
|
||||
@@index([employee_id, dates])
|
||||
|
|
@ -92,45 +80,29 @@ model LeaveRequests {
|
|||
|
||||
model LeaveRequestsArchive {
|
||||
id Int @id @default(autoincrement())
|
||||
leave_request LeaveRequests @relation("LeaveRequestToArchive", fields: [leave_request_id], references: [id])
|
||||
leave_request_id Int
|
||||
|
||||
leave_request_id Int @unique
|
||||
archived_at DateTime @default(now())
|
||||
employee_id Int
|
||||
leave_type LeaveTypes
|
||||
comment String
|
||||
approval_status LeaveApprovalStatus
|
||||
date DateTime @db.Date
|
||||
payable_hours Decimal? @db.Decimal(5, 2)
|
||||
requested_hours Decimal? @db.Decimal(5, 2)
|
||||
comment String
|
||||
leave_type LeaveTypes
|
||||
approval_status LeaveApprovalStatus
|
||||
leave_request LeaveRequests @relation("LeaveRequestToArchive", fields: [leave_request_id], references: [id])
|
||||
|
||||
@@unique([leave_request_id])
|
||||
@@index([employee_id, date])
|
||||
@@map("leave_requests_archive")
|
||||
}
|
||||
|
||||
//pay-period vue
|
||||
view PayPeriods {
|
||||
pay_year Int
|
||||
pay_period_no Int
|
||||
label String
|
||||
payday DateTime @db.Date
|
||||
period_start DateTime @db.Date
|
||||
period_end DateTime @db.Date
|
||||
|
||||
@@map("pay_period")
|
||||
}
|
||||
|
||||
model Timesheets {
|
||||
id Int @id @default(autoincrement())
|
||||
employee Employees @relation("TimesheetEmployee", fields: [employee_id], references: [id])
|
||||
employee_id Int
|
||||
|
||||
start_date DateTime @db.Date
|
||||
is_approved Boolean @default(false)
|
||||
|
||||
shift Shifts[] @relation("ShiftTimesheet")
|
||||
start_date DateTime @db.Date
|
||||
expense Expenses[] @relation("ExpensesTimesheet")
|
||||
shift Shifts[] @relation("ShiftTimesheet")
|
||||
employee Employees @relation("TimesheetEmployee", fields: [employee_id], references: [id])
|
||||
archive TimesheetsArchive[] @relation("TimesheetsToArchive")
|
||||
|
||||
@@unique([employee_id, start_date], name: "employee_id_start_date")
|
||||
|
|
@ -139,12 +111,11 @@ model Timesheets {
|
|||
|
||||
model TimesheetsArchive {
|
||||
id Int @id @default(autoincrement())
|
||||
timesheet Timesheets @relation("TimesheetsToArchive", fields: [timesheet_id], references: [id])
|
||||
timesheet_id Int
|
||||
|
||||
archive_at DateTime @default(now())
|
||||
employee_id Int
|
||||
is_approved Boolean
|
||||
archive_at DateTime @default(now())
|
||||
timesheet Timesheets @relation("TimesheetsToArchive", fields: [timesheet_id], references: [id])
|
||||
|
||||
@@map("timesheets_archive")
|
||||
}
|
||||
|
|
@ -153,44 +124,41 @@ model SchedulePresets {
|
|||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
is_default Boolean @default(false)
|
||||
|
||||
shifts SchedulePresetShifts[] @relation("SchedulePresetShiftsSchedulePreset")
|
||||
employees Employees[] @relation("EmployeesSchedulePreset")
|
||||
shifts SchedulePresetShifts[] @relation("SchedulePresetShiftsSchedulePreset")
|
||||
|
||||
@@map("schedule_presets")
|
||||
}
|
||||
|
||||
model SchedulePresetShifts {
|
||||
id Int @id @default(autoincrement())
|
||||
preset SchedulePresets @relation("SchedulePresetShiftsSchedulePreset", fields: [preset_id], references: [id])
|
||||
preset_id Int
|
||||
bank_code BankCodes @relation("SchedulePresetShiftsBankCodes", fields: [bank_code_id], references: [id])
|
||||
bank_code_id Int
|
||||
|
||||
sort_order Int
|
||||
start_time DateTime @db.Time(0)
|
||||
end_time DateTime @db.Time(0)
|
||||
is_remote Boolean @default(false)
|
||||
week_day Weekday
|
||||
bank_code BankCodes @relation("SchedulePresetShiftsBankCodes", fields: [bank_code_id], references: [id])
|
||||
preset SchedulePresets @relation("SchedulePresetShiftsSchedulePreset", fields: [preset_id], references: [id])
|
||||
|
||||
@@unique([preset_id, week_day], name: "unique_preset_shift_per_day")
|
||||
@@unique([preset_id, week_day, sort_order])
|
||||
@@index([preset_id, week_day])
|
||||
@@map("schedule_preset_shifts")
|
||||
}
|
||||
|
||||
model Shifts {
|
||||
id Int @id @default(autoincrement())
|
||||
timesheet Timesheets @relation("ShiftTimesheet", fields: [timesheet_id], references: [id])
|
||||
timesheet_id Int
|
||||
bank_code BankCodes @relation("ShiftBankCodes", fields: [bank_code_id], references: [id])
|
||||
bank_code_id Int
|
||||
|
||||
date DateTime @db.Date
|
||||
start_time DateTime @db.Time(0)
|
||||
end_time DateTime @db.Time(0)
|
||||
bank_code_id Int
|
||||
is_approved Boolean @default(false)
|
||||
is_remote Boolean @default(false)
|
||||
comment String?
|
||||
|
||||
bank_code BankCodes @relation("ShiftBankCodes", fields: [bank_code_id], references: [id])
|
||||
timesheet Timesheets @relation("ShiftTimesheet", fields: [timesheet_id], references: [id])
|
||||
archive ShiftsArchive[] @relation("ShiftsToArchive")
|
||||
|
||||
@@unique([timesheet_id, date, start_time], name: "unique_ts_id_date_start_time")
|
||||
|
|
@ -199,16 +167,15 @@ model Shifts {
|
|||
|
||||
model ShiftsArchive {
|
||||
id Int @id @default(autoincrement())
|
||||
shift Shifts @relation("ShiftsToArchive", fields: [shift_id], references: [id])
|
||||
shift_id Int
|
||||
|
||||
archive_at DateTime @default(now())
|
||||
timesheet_id Int
|
||||
date DateTime @db.Date
|
||||
start_time DateTime @db.Time(0)
|
||||
end_time DateTime @db.Time(0)
|
||||
timesheet_id Int
|
||||
bank_code_id Int
|
||||
comment String?
|
||||
archive_at DateTime @default(now())
|
||||
shift Shifts @relation("ShiftsToArchive", fields: [shift_id], references: [id])
|
||||
|
||||
@@map("shifts_archive")
|
||||
}
|
||||
|
|
@ -219,31 +186,28 @@ model BankCodes {
|
|||
categorie String
|
||||
modifier Float
|
||||
bank_code String
|
||||
|
||||
shifts Shifts[] @relation("ShiftBankCodes")
|
||||
expenses Expenses[] @relation("ExpenseBankCodes")
|
||||
leaveRequests LeaveRequests[] @relation("LeaveRequestBankCodes")
|
||||
SchedulePresetShifts SchedulePresetShifts[] @relation("SchedulePresetShiftsBankCodes")
|
||||
shifts Shifts[] @relation("ShiftBankCodes")
|
||||
|
||||
@@map("bank_codes")
|
||||
}
|
||||
|
||||
model Expenses {
|
||||
id Int @id @default(autoincrement())
|
||||
timesheet Timesheets @relation("ExpensesTimesheet", fields: [timesheet_id], references: [id])
|
||||
timesheet_id Int
|
||||
bank_code BankCodes @relation("ExpenseBankCodes", fields: [bank_code_id], references: [id])
|
||||
bank_code_id Int
|
||||
attachment_record Attachments? @relation("ExpenseAttachment", fields: [attachment], references: [id], onDelete: SetNull)
|
||||
attachment Int?
|
||||
|
||||
date DateTime @db.Date
|
||||
amount Decimal? @db.Decimal(12, 2)
|
||||
mileage Decimal? @db.Decimal(12, 2)
|
||||
comment String
|
||||
supervisor_comment String?
|
||||
is_approved Boolean @default(false)
|
||||
|
||||
supervisor_comment String?
|
||||
bank_code_id Int
|
||||
comment String
|
||||
attachment Int?
|
||||
mileage Decimal? @db.Decimal(12, 2)
|
||||
attachment_record Attachments? @relation("ExpenseAttachment", fields: [attachment], references: [id])
|
||||
bank_code BankCodes @relation("ExpenseBankCodes", fields: [bank_code_id], references: [id])
|
||||
timesheet Timesheets @relation("ExpensesTimesheet", fields: [timesheet_id], references: [id])
|
||||
archive ExpensesArchive[] @relation("ExpensesToArchive")
|
||||
|
||||
@@unique([timesheet_id, date, amount, mileage], name: "unique_ts_id_date_amount_mileage")
|
||||
|
|
@ -252,38 +216,37 @@ model Expenses {
|
|||
|
||||
model ExpensesArchive {
|
||||
id Int @id @default(autoincrement())
|
||||
expense Expenses @relation("ExpensesToArchive", fields: [expense_id], references: [id])
|
||||
expense_id Int
|
||||
attachment_record Attachments? @relation("ExpenseArchiveAttachment", fields: [attachment], references: [id], onDelete: SetNull)
|
||||
attachment Int?
|
||||
|
||||
timesheet_id Int
|
||||
archived_at DateTime @default(now())
|
||||
bank_code_id Int
|
||||
date DateTime @db.Date
|
||||
amount Decimal? @db.Decimal(12, 2)
|
||||
mileage Decimal? @db.Decimal(12, 2)
|
||||
comment String?
|
||||
is_approved Boolean
|
||||
supervisor_comment String?
|
||||
bank_code_id Int
|
||||
comment String?
|
||||
attachment Int?
|
||||
mileage Decimal? @db.Decimal(12, 2)
|
||||
attachment_record Attachments? @relation("ExpenseArchiveAttachment", fields: [attachment], references: [id])
|
||||
expense Expenses @relation("ExpensesToArchive", fields: [expense_id], references: [id])
|
||||
|
||||
@@map("expenses_archive")
|
||||
}
|
||||
|
||||
model OAuthSessions {
|
||||
id String @id @default(cuid())
|
||||
user Users @relation("UserOAuthSessions", fields: [user_id], references: [id])
|
||||
user_id String @db.Uuid
|
||||
application String
|
||||
access_token String @unique
|
||||
refresh_token String @unique
|
||||
sid String @unique
|
||||
access_token_expiry DateTime
|
||||
refresh_token_expiry DateTime?
|
||||
is_revoked Boolean @default(false)
|
||||
scopes Json @default("[]")
|
||||
created_at DateTime @default(now())
|
||||
updated_at DateTime?
|
||||
sid String @unique
|
||||
user Users @relation("UserOAuthSessions", fields: [user_id], references: [id])
|
||||
|
||||
@@map("oauth_sessions")
|
||||
}
|
||||
|
|
@ -304,7 +267,6 @@ model Blobs {
|
|||
storage_path String
|
||||
refcount Int @default(0)
|
||||
created_at DateTime @default(now())
|
||||
|
||||
attachments Attachments[] @relation("AttachmnentBlob")
|
||||
|
||||
@@map("blobs")
|
||||
|
|
@ -312,22 +274,19 @@ model Blobs {
|
|||
|
||||
model Attachments {
|
||||
id Int @id @default(autoincrement())
|
||||
blob Blobs @relation("AttachmnentBlob", fields: [sha256], references: [sha256], onUpdate: Cascade)
|
||||
sha256 String @db.Char(64)
|
||||
|
||||
owner_type String //EXPENSES ou éventuellement autre chose comme scan ONU ou photos d'employés, etc
|
||||
owner_id String //expense_id, employee_id, etc
|
||||
original_name String
|
||||
owner_type String
|
||||
owner_id String
|
||||
status AttachmentStatus @default(ACTIVE)
|
||||
retention_policy RetentionPolicy
|
||||
created_by String
|
||||
created_at DateTime @default(now())
|
||||
|
||||
original_name String
|
||||
retention_policy RetentionPolicy
|
||||
AttachmentVariants AttachmentVariants[] @relation("attachmentVariantAttachment")
|
||||
blob Blobs @relation("AttachmnentBlob", fields: [sha256], references: [sha256])
|
||||
expenses Expenses[] @relation("ExpenseAttachment")
|
||||
expenses_archive ExpensesArchive[] @relation("ExpenseArchiveAttachment")
|
||||
|
||||
AttachmentVariants AttachmentVariants[] @relation("attachmentVariantAttachment")
|
||||
|
||||
@@index([owner_type, owner_id, created_at])
|
||||
@@index([sha256])
|
||||
@@map("attachments")
|
||||
|
|
@ -336,33 +295,43 @@ model Attachments {
|
|||
model AttachmentVariants {
|
||||
id Int @id @default(autoincrement())
|
||||
attachment_id Int
|
||||
attachment Attachments @relation("attachmentVariantAttachment", fields: [attachment_id], references: [id], onDelete: Cascade)
|
||||
variant String
|
||||
path String
|
||||
bytes Int
|
||||
width Int?
|
||||
height Int?
|
||||
created_at DateTime @default(now())
|
||||
path String
|
||||
attachment Attachments @relation("attachmentVariantAttachment", fields: [attachment_id], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([attachment_id, variant])
|
||||
@@map("attachment_variants")
|
||||
}
|
||||
|
||||
model Preferences {
|
||||
id Int @id @default(autoincrement())
|
||||
user Users @relation("UserPreferences", fields: [user_id], references: [id])
|
||||
user_id String @unique @db.Uuid
|
||||
|
||||
notifications Boolean @default(true)
|
||||
id Int @id @default(autoincrement())
|
||||
display_language String @default("fr-FR")
|
||||
is_dark_mode Boolean? @default(false)
|
||||
display_language String @default("fr-FR") //'fr-FR' | 'en-CA';
|
||||
is_lefty_mode Boolean @default(false)
|
||||
is_employee_list_grid Boolean @default(true)
|
||||
is_lefty_mode Boolean @default(false)
|
||||
is_timesheet_approval_grid Boolean @default(true)
|
||||
notifications Boolean @default(true)
|
||||
user Users @relation("UserPreferences", fields: [user_id], references: [id])
|
||||
|
||||
@@map("preferences")
|
||||
}
|
||||
|
||||
view PayPeriods {
|
||||
pay_year Int
|
||||
pay_period_no BigInt
|
||||
period_start DateTime @db.Date
|
||||
period_end DateTime @db.Date
|
||||
payday DateTime @db.Date
|
||||
label String
|
||||
|
||||
@@map("pay_period")
|
||||
}
|
||||
|
||||
enum AttachmentStatus {
|
||||
ACTIVE
|
||||
DELETED
|
||||
|
|
@ -399,14 +368,14 @@ enum Modules {
|
|||
}
|
||||
|
||||
enum LeaveTypes {
|
||||
SICK // maladie ou repos
|
||||
VACATION // paye
|
||||
UNPAID // non-paye
|
||||
BEREAVEMENT // deuil de famille
|
||||
PARENTAL // maternite/paternite/adoption
|
||||
LEGAL // obligations legales comme devoir de juree
|
||||
WEDDING // mariage
|
||||
HOLIDAY // férier
|
||||
SICK
|
||||
VACATION
|
||||
UNPAID
|
||||
BEREAVEMENT
|
||||
PARENTAL
|
||||
LEGAL
|
||||
WEDDING
|
||||
HOLIDAY
|
||||
|
||||
@@map("leave_types")
|
||||
}
|
||||
|
|
|
|||
79
prisma/views/public/PayPeriods.sql
Normal file
79
prisma/views/public/PayPeriods.sql
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
WITH anchor AS (
|
||||
SELECT
|
||||
'2023-12-17' :: date AS anchor_sunday
|
||||
),
|
||||
series AS (
|
||||
SELECT
|
||||
(gs.gs) :: date AS period_start,
|
||||
((gs.gs + '13 days' :: INTERVAL)) :: date AS period_end,
|
||||
((gs.gs + '18 days' :: INTERVAL)) :: date AS payday
|
||||
FROM
|
||||
generate_series(
|
||||
(
|
||||
(
|
||||
SELECT
|
||||
anchor.anchor_sunday
|
||||
FROM
|
||||
anchor
|
||||
)
|
||||
) :: timestamp WITH time zone,
|
||||
(((CURRENT_DATE + '1 mon' :: INTERVAL)) :: date) :: timestamp WITH time zone,
|
||||
'14 days' :: INTERVAL
|
||||
) gs(gs)
|
||||
),
|
||||
numbered AS (
|
||||
SELECT
|
||||
series.period_start,
|
||||
series.period_end,
|
||||
series.payday,
|
||||
(
|
||||
EXTRACT(
|
||||
year
|
||||
FROM
|
||||
series.payday
|
||||
)
|
||||
) :: integer AS pay_year,
|
||||
row_number() OVER (
|
||||
PARTITION BY (
|
||||
EXTRACT(
|
||||
year
|
||||
FROM
|
||||
series.payday
|
||||
)
|
||||
)
|
||||
ORDER BY
|
||||
series.payday
|
||||
) AS pay_period_no
|
||||
FROM
|
||||
series
|
||||
)
|
||||
SELECT
|
||||
pay_year,
|
||||
pay_period_no,
|
||||
period_start,
|
||||
period_end,
|
||||
payday,
|
||||
(
|
||||
(
|
||||
to_char(
|
||||
(period_start) :: timestamp WITH time zone,
|
||||
'YYYY-MM-DD' :: text
|
||||
) || '->' :: text
|
||||
) || to_char(
|
||||
(period_end) :: timestamp WITH time zone,
|
||||
'YYYY-MM-DD' :: text
|
||||
)
|
||||
) AS label
|
||||
FROM
|
||||
numbered
|
||||
WHERE
|
||||
(
|
||||
(
|
||||
payday >= ((CURRENT_DATE - '6 mons' :: INTERVAL)) :: date
|
||||
)
|
||||
AND (
|
||||
payday <= ((CURRENT_DATE + '1 mon' :: INTERVAL)) :: date
|
||||
)
|
||||
)
|
||||
ORDER BY
|
||||
period_start;
|
||||
|
|
@ -6,7 +6,7 @@ export class SchedulePresetsDto {
|
|||
@IsInt() id!: number;
|
||||
@IsString() name!: string;
|
||||
@IsBoolean() @IsOptional() is_default: boolean;
|
||||
@IsArray() @ArrayMinSize(1) preset_shifts: SchedulePresetShiftsDto[];
|
||||
@IsArray() @ArrayMinSize(1) shifts: SchedulePresetShiftsDto[];
|
||||
}
|
||||
|
||||
export class SchedulePresetShiftsDto {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export class SchedulePresetsCreateService {
|
|||
});
|
||||
if (existing) return { success: false, error: 'INVALID_SCHEDULE_PRESET' };
|
||||
|
||||
const normalized_shifts = dto.preset_shifts.map((shift) => ({
|
||||
const normalized_shifts = dto.shifts.map((shift) => ({
|
||||
...shift,
|
||||
start: toDateFromHHmm(shift.start_time),
|
||||
end: toDateFromHHmm(shift.end_time),
|
||||
|
|
@ -47,7 +47,7 @@ export class SchedulePresetsCreateService {
|
|||
}
|
||||
|
||||
//validate bank_code_id/type and map them
|
||||
const bank_code_results = await Promise.all(dto.preset_shifts.map((shift) =>
|
||||
const bank_code_results = await Promise.all(dto.shifts.map((shift) =>
|
||||
this.typeResolver.findBankCodeIDByType(shift.type),
|
||||
));
|
||||
for (const result of bank_code_results) {
|
||||
|
|
@ -68,7 +68,7 @@ export class SchedulePresetsCreateService {
|
|||
name: dto.name,
|
||||
is_default: dto.is_default ?? false,
|
||||
shifts: {
|
||||
create: dto.preset_shifts.map((shift, index) => {
|
||||
create: dto.shifts.map((shift, index) => {
|
||||
//validated bank_codes sent as a Result Array to access its data
|
||||
const result = bank_code_results[index] as { success: true, data: number };
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { Injectable } from "@nestjs/common";
|
|||
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
|
||||
import { PresetResponse, ShiftResponse } from "src/time-and-attendance/utils/type.utils";
|
||||
import { SchedulePresetsDto, SchedulePresetShiftsDto } from "../schedule-presets.dto";
|
||||
|
||||
import { Result } from "src/common/errors/result-error.factory";
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ export class SchedulePresetsGetService {
|
|||
private readonly prisma: PrismaService,
|
||||
) { }
|
||||
|
||||
async getSchedulePresets(): Promise<Result<PresetResponse[], string>> {
|
||||
async getSchedulePresets(): Promise<Result<SchedulePresetsDto[], string>> {
|
||||
try {
|
||||
const presets = await this.prisma.schedulePresets.findMany({
|
||||
orderBy: [{ is_default: 'desc' }, { name: 'asc' }],
|
||||
|
|
@ -25,11 +25,12 @@ export class SchedulePresetsGetService {
|
|||
});
|
||||
const hhmm = (date: Date) => date.toISOString().slice(11, 16);
|
||||
|
||||
const response: PresetResponse[] = presets.map((preset) => ({
|
||||
const response: SchedulePresetsDto[] = presets.map((preset) => ({
|
||||
id: preset.id,
|
||||
name: preset.name,
|
||||
is_default: preset.is_default,
|
||||
shifts: preset.shifts.map<ShiftResponse>((shift) => ({
|
||||
shifts: preset.shifts.map<Omit<SchedulePresetShiftsDto, 'id'>>((shift) => ({
|
||||
preset_id: shift.preset_id,
|
||||
week_day: shift.week_day,
|
||||
start_time: hhmm(shift.start_time),
|
||||
end_time: hhmm(shift.end_time),
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export class SchedulePresetUpdateService {
|
|||
},
|
||||
});
|
||||
if (!existing) return { success: false, error: `SCHEDULE_PRESET_NOT_FOUND` };
|
||||
const normalized_shifts = dto.preset_shifts.map((shift) => ({
|
||||
const normalized_shifts = dto.shifts.map((shift) => ({
|
||||
...shift,
|
||||
start: toDateFromHHmm(shift.start_time),
|
||||
end: toDateFromHHmm(shift.end_time),
|
||||
|
|
@ -44,7 +44,7 @@ export class SchedulePresetUpdateService {
|
|||
if (has_overlap) return { success: false, error: 'SCHEDULE_PRESET_OVERLAP' };
|
||||
}
|
||||
}
|
||||
const bank_code_results = await Promise.all(dto.preset_shifts.map((shift) =>
|
||||
const bank_code_results = await Promise.all(dto.shifts.map((shift) =>
|
||||
this.typeResolver.findBankCodeIDByType(shift.type),
|
||||
));
|
||||
for (const result of bank_code_results) {
|
||||
|
|
@ -69,7 +69,7 @@ export class SchedulePresetUpdateService {
|
|||
name: dto.name,
|
||||
is_default: dto.is_default ?? false,
|
||||
shifts: {
|
||||
create: dto.preset_shifts.map((shift, index) => {
|
||||
create: dto.shifts.map((shift, index) => {
|
||||
const result = bank_code_results[index] as { success: true, data: number };
|
||||
return {
|
||||
week_day: shift.week_day,
|
||||
|
|
|
|||
|
|
@ -23,19 +23,3 @@ export type NormalizedLeaveRequest = {
|
|||
bank_code_id: number;
|
||||
leave_type: LeaveTypes;
|
||||
}
|
||||
|
||||
export type ShiftResponse = {
|
||||
week_day: string;
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
is_remote: boolean;
|
||||
type: string;
|
||||
};
|
||||
|
||||
export type PresetResponse = {
|
||||
id: number;
|
||||
name: string;
|
||||
is_default: boolean;
|
||||
shifts: ShiftResponse[];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user