diff --git a/src/main.ts b/src/main.ts index 7c06222..fbe5afd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,6 +19,8 @@ import { writeFileSync } from 'fs'; import * as session from 'express-session'; import * as passport from 'passport'; +const SESSION_TOKEN_DURATION_MINUTES = 180 + async function bootstrap() { const app = await NestFactory.create(AppModule); @@ -37,7 +39,7 @@ async function bootstrap() { saveUninitialized: false, rolling: true, cookie: { - maxAge: 30 * 60 * 1000, + maxAge: SESSION_TOKEN_DURATION_MINUTES * 60 * 1000, // property maxAge requires milliseconds httpOnly: true, } })) diff --git a/src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto.ts b/src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto.ts index 0dd4505..aef90e3 100644 --- a/src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto.ts +++ b/src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto.ts @@ -7,5 +7,5 @@ export class UpdateShiftDto extends PartialType( OmitType(ShiftDto, ['is_approved', 'timesheet_id'] as const), ) { @IsInt() - id!: number; + shift_id!: number; } diff --git a/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts b/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts index e1d36f4..77e34f8 100644 --- a/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts +++ b/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts @@ -239,8 +239,9 @@ export class ShiftsUpsertService { if (!Array.isArray(dtos) || dtos.length === 0) return []; const updates: UpdateShiftPayload[] = await Promise.all(dtos.map((item) => { - const { id, ...rest } = item; - if (!Number.isInteger(id)) throw new ConflictException({ error_code: 'INVALID_SHIFT'}); + const { shift_id, ...rest } = item; + console.log('id received: ', shift_id); + if (!Number.isInteger(shift_id)) throw new ConflictException({ error_code: 'INVALID_SHIFT'}); const changes: UpdateShiftChanges = {}; if (rest.date !== undefined) changes.date = rest.date; @@ -250,11 +251,11 @@ export class ShiftsUpsertService { if (rest.is_remote !== undefined) changes.is_remote = rest.is_remote; if (rest.comment !== undefined) changes.comment = rest.comment; - return { id, dto: changes }; + return { shift_id, dto: changes }; })); return this.prisma.$transaction(async (tx) => { - const shift_ids = updates.map(update_shift => update_shift.id); + const shift_ids = updates.map(update_shift => update_shift.shift_id); const rows = await tx.shifts.findMany({ where: { id: { in: shift_ids } }, select: shift_select, @@ -262,21 +263,21 @@ export class ShiftsUpsertService { const regroup_id = new Map(rows.map(r => [r.id, r])); for (const update of updates) { - const existing = regroup_id.get(update.id); + const existing = regroup_id.get(update.shift_id); if (!existing) { - return updates.map(exist => exist.id === update.id - ? ({ ok: false, id: update.id, error: new NotFoundException(`Shift with id: ${update.id} not found`) } as UpdateShiftResult) - : ({ ok: false, id: exist.id, error: new BadRequestException('Batch aborted due to missing shift') })); + return updates.map(exist => exist.shift_id === update.shift_id + ? ({ ok: false, id: update.shift_id, error: new NotFoundException(`Shift with id: ${update.shift_id} not found`) } as UpdateShiftResult) + : ({ ok: false, id: exist.shift_id, error: new BadRequestException('Batch aborted due to missing shift') })); } if (existing.is_approved) { - return updates.map(exist => exist.id === update.id - ? ({ ok: false, id: update.id, error: new BadRequestException('Approved shift cannot be updated') } as UpdateShiftResult) - : ({ ok: false, id: exist.id, error: new BadRequestException('Batch aborted due to approved shift in update set') })); + return updates.map(exist => exist.shift_id === update.shift_id + ? ({ ok: false, id: update.shift_id, error: new BadRequestException('Approved shift cannot be updated') } as UpdateShiftResult) + : ({ ok: false, id: exist.shift_id, error: new BadRequestException('Batch aborted due to approved shift in update set') })); } } const planned_updates = updates.map(update => { - const exist_shift = regroup_id.get(update.id)!; + const exist_shift = regroup_id.get(update.shift_id)!; const date_string = update.dto.date ?? toStringFromDate(exist_shift.date); const start_string = update.dto.start_time ?? toStringFromHHmm(exist_shift.start_time); const end_string = update.dto.end_time ?? toStringFromHHmm(exist_shift.end_time); @@ -325,9 +326,9 @@ export class ShiftsUpsertService { ); if (conflict) { return updates.map(exist => - exist.id === planned.exist_shift.id + exist.shift_id === planned.exist_shift.id ? ({ - ok: false, id: exist.id, error:{ + ok: false, id: exist.shift_id, error:{ error_code: 'SHIFT_OVERLAP', conflicts: { start_time: toStringFromHHmm(conflict.start), @@ -336,7 +337,7 @@ export class ShiftsUpsertService { }, } } as UpdateShiftResult) - : ({ ok: false, id: exist.id, error: new BadRequestException('Batch aborted due to overlap in another update') }) + : ({ ok: false, id: exist.shift_id, error: new BadRequestException('Batch aborted due to overlap in another update') }) ); } } @@ -369,7 +370,7 @@ export class ShiftsUpsertService { }, }; - return updates.map(exist => ({ ok: false, id: exist.id, error: error })); + return updates.map(exist => ({ ok: false, id: exist.shift_id, error: error })); } } } diff --git a/src/time-and-attendance/utils/type.utils.ts b/src/time-and-attendance/utils/type.utils.ts index c9613bb..a4844bf 100644 --- a/src/time-and-attendance/utils/type.utils.ts +++ b/src/time-and-attendance/utils/type.utils.ts @@ -33,8 +33,8 @@ export type ShiftWithOvertimeDto = { }; export type CreateShiftResult = { ok: true; data: ShiftWithOvertimeDto } | { ok: false; error: any }; -export type UpdateShiftChanges = Omit; -export type UpdateShiftPayload = { id: number; dto: UpdateShiftChanges }; +export type UpdateShiftChanges = Omit; +export type UpdateShiftPayload = { shift_id: number; dto: UpdateShiftChanges }; export type UpdateShiftResult = { ok: true; id: number; data: ShiftWithOvertimeDto } | { ok: false; id: number; error: any }; export type DeleteShiftResult = { ok: true; id: number; overtime: WeekOvertimeSummary } | { ok: false; id: number; error: any };