Merge pull request 'fix(imports): ajusted imports to remove relative paths' (#7) from dev/matthieu/refactor into main
Reviewed-on: Targo/targo_backend#7
This commit is contained in:
commit
8ab80fc2d8
|
|
@ -315,7 +315,7 @@ model AttachmentVariants {
|
|||
attachment_id Int
|
||||
attachment Attachments @relation("attachmentVariantAttachment",fields: [attachment_id], references: [id], onDelete: Cascade)
|
||||
variant String
|
||||
patch String
|
||||
path String
|
||||
bytes Int
|
||||
width Int?
|
||||
height Int?
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// import { Injectable, Logger } from "@nestjs/common";
|
||||
// import { Cron } from "@nestjs/schedule";
|
||||
// import { TimesheetArchiveService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service";
|
||||
// import { ExpensesArchivalService } from "src/time-and-attendance/modules/expenses/services/expenses-archival.service";
|
||||
// import { ShiftsArchivalService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-archival.service";
|
||||
// import { TimesheetArchiveService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service";
|
||||
// import { Injectable, Logger } from "@nestjs/common";
|
||||
// import { Cron } from "@nestjs/schedule";
|
||||
|
||||
// @Injectable()
|
||||
// export class ArchivalService {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,19 @@
|
|||
import { ScheduleModule } from "@nestjs/schedule";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { ArchivalAttachmentService } from "./services/archival-attachment.service";
|
||||
import { ArchivalAttachmentService } from "src/modules/attachments/services/archival-attachment.service";
|
||||
import { GarbargeCollectorService } from "src/modules/attachments/services/garbage-collector.service";
|
||||
import { AttachmentsController } from "src/modules/attachments/controllers/attachments.controller";
|
||||
import { DiskStorageService } from "src/modules/attachments/services/disk-storage.service";
|
||||
// import { ScheduleModule } from "@nestjs/schedule";
|
||||
import { VariantsQueue } from "src/modules/attachments/services/variants.queue";
|
||||
import { Module } from "@nestjs/common";
|
||||
import { GarbargeCollectorService } from "./services/garbage-collector.service";
|
||||
|
||||
@Module({
|
||||
imports: [ScheduleModule.forRoot()],
|
||||
// imports: [ScheduleModule.forRoot()],
|
||||
controllers: [ AttachmentsController],
|
||||
providers: [
|
||||
PrismaService,
|
||||
ArchivalAttachmentService,
|
||||
GarbargeCollectorService,
|
||||
DiskStorageService,
|
||||
VariantsQueue,
|
||||
],
|
||||
exports: [
|
||||
ArchivalAttachmentService,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { promises as fsp } from 'node:fs';
|
||||
import { createWriteStream, statSync, existsSync } from 'node:fs';
|
||||
|
|
@ -7,6 +8,7 @@ import { ATT_TMP_DIR, resolveAttachmentsRoot } from 'src/config/attachment.confi
|
|||
|
||||
export type SaveResult = { sha256:string, storage_path:string, size:number};
|
||||
|
||||
@Injectable()
|
||||
export class DiskStorageService {
|
||||
private root = resolveAttachmentsRoot();
|
||||
|
||||
|
|
@ -38,7 +40,7 @@ export class DiskStorageService {
|
|||
|
||||
const hash = createHash('sha256');
|
||||
const tmpOut = createWriteStream(tmpPath);
|
||||
input.on('date', (chunk) => hash.update(chunk));
|
||||
input.on('data', (chunk) => hash.update(chunk));
|
||||
await pipeline(input, tmpOut); //await end of writing stream
|
||||
|
||||
const sha = hash.digest('hex');
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { Injectable } from "@nestjs/common";
|
||||
import { Queue } from "bullmq";
|
||||
|
||||
@Injectable()
|
||||
export class VariantsQueue {
|
||||
private queue : Queue;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { Body, Controller, Delete, Param, ParseIntPipe, Patch, Post } from "@nestjs/common";
|
||||
import { CreateResult, ExpenseUpsertService, UpdateResult } from "../services/expense-upsert.service";
|
||||
import { Controller, Post, Param, ParseIntPipe, Body, Patch, Delete } from "@nestjs/common";
|
||||
import { CreateExpenseResult, UpdateExpenseResult } from "src/time-and-attendance/utils/type.utils";
|
||||
import { ExpenseUpsertService } from "src/time-and-attendance/modules/expenses/services/expense-upsert.service";
|
||||
import { updateExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-update.dto";
|
||||
import { ExpenseDto } from "../dtos/expense-create.dto";
|
||||
import { ExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-create.dto";
|
||||
|
||||
|
||||
@Controller('expense')
|
||||
|
|
@ -11,13 +12,13 @@ export class ExpenseController {
|
|||
@Post(':timesheet_id')
|
||||
create(
|
||||
@Param('timesheet_id', ParseIntPipe) timesheet_id: number,
|
||||
@Body() dto: ExpenseDto): Promise<CreateResult>{
|
||||
@Body() dto: ExpenseDto): Promise<CreateExpenseResult>{
|
||||
return this.upsert_service.createExpense(timesheet_id, dto);
|
||||
}
|
||||
|
||||
@Patch()
|
||||
update(
|
||||
@Body() body: { update :{ id: number; dto: updateExpenseDto }}): Promise<UpdateResult>{
|
||||
@Body() body: { update :{ id: number; dto: updateExpenseDto }}): Promise<UpdateExpenseResult>{
|
||||
return this.upsert_service.updateExpense(body.update);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { OmitType, PartialType } from "@nestjs/swagger";
|
||||
import { ExpenseDto } from "./expense-create.dto";
|
||||
import { ExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-create.dto";
|
||||
|
||||
export class updateExpenseDto extends PartialType (
|
||||
OmitType(ExpenseDto, ['is_approved', 'timesheet_id'] as const)
|
||||
|
|
|
|||
|
|
@ -1,18 +1,12 @@
|
|||
|
||||
import { CreateExpenseResult, UpdateExpensePayload, UpdateExpenseResult, DeleteExpenseResult, NormalizedExpense } from "src/time-and-attendance/utils/type.utils";
|
||||
import { toDateFromString, toStringFromDate } from "src/time-and-attendance/utils/date-time.utils";
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { updateExpenseDto } from "../dtos/expense-update.dto";
|
||||
import { GetExpenseDto } from "../dtos/expense-get.dto";
|
||||
import { expense_select } from "src/time-and-attendance/utils/selects.utils";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { ExpenseDto } from "../dtos/expense-create.dto";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { GetExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-get.dto";
|
||||
import { ExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-create.dto";
|
||||
|
||||
type Normalized = { date: Date; comment: string; supervisor_comment?: string; };
|
||||
|
||||
export type CreateResult = { ok: true; data: GetExpenseDto } | { ok: false; error: any };
|
||||
export type UpdatePayload = { id: number; dto: updateExpenseDto };
|
||||
export type UpdateResult = { ok: true; id: number; data: GetExpenseDto } | { ok: false; id: number; error: any };
|
||||
export type DeleteResult = { ok: true; id: number; } | { ok: false; id: number; error: any };
|
||||
|
||||
@Injectable()
|
||||
export class ExpenseUpsertService {
|
||||
|
|
@ -21,7 +15,7 @@ export class ExpenseUpsertService {
|
|||
//_________________________________________________________________
|
||||
// CREATE
|
||||
//_________________________________________________________________
|
||||
async createExpense(timesheet_id: number, dto: ExpenseDto): Promise<CreateResult> {
|
||||
async createExpense(timesheet_id: number, dto: ExpenseDto): Promise<CreateExpenseResult> {
|
||||
try {
|
||||
//normalize strings and dates
|
||||
const normed_expense = this.normalizeExpenseDto(dto);
|
||||
|
|
@ -71,7 +65,7 @@ export class ExpenseUpsertService {
|
|||
//_________________________________________________________________
|
||||
// UPDATE
|
||||
//_________________________________________________________________
|
||||
async updateExpense({id, dto}: UpdatePayload): Promise<UpdateResult> {
|
||||
async updateExpense({id, dto}: UpdateExpensePayload): Promise<UpdateExpenseResult> {
|
||||
try {
|
||||
//checks for modifications
|
||||
const data: Record<string, unknown> = {};
|
||||
|
|
@ -117,7 +111,7 @@ export class ExpenseUpsertService {
|
|||
//_________________________________________________________________
|
||||
// DELETE
|
||||
//_________________________________________________________________
|
||||
async deleteExpense(expense_id: number): Promise<DeleteResult> {
|
||||
async deleteExpense(expense_id: number): Promise<DeleteExpenseResult> {
|
||||
try {
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
const expense = await tx.expenses.findUnique({
|
||||
|
|
@ -139,7 +133,7 @@ export class ExpenseUpsertService {
|
|||
// LOCAL HELPERS
|
||||
//_________________________________________________________________
|
||||
//makes sure that comments are the right length the date is of Date type
|
||||
private normalizeExpenseDto(dto: ExpenseDto): Normalized {
|
||||
private normalizeExpenseDto(dto: ExpenseDto): NormalizedExpense {
|
||||
const date = toDateFromString(dto.date);
|
||||
const comment = this.truncate280(dto.comment);
|
||||
const supervisor_comment =
|
||||
|
|
@ -161,21 +155,4 @@ export class ExpenseUpsertService {
|
|||
if (Number.isNaN(parsed)) throw new Error(`Invalid value : ${value} for ${field}`);
|
||||
return parsed;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const expense_select = {
|
||||
id: true,
|
||||
timesheet_id: true,
|
||||
bank_code_id: true,
|
||||
attachment: true,
|
||||
date: true,
|
||||
amount: true,
|
||||
mileage: true,
|
||||
comment: true,
|
||||
supervisor_comment: true,
|
||||
is_approved: true,
|
||||
} satisfies Prisma.ExpensesSelect;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { Injectable } from "@nestjs/common";
|
||||
import { ExpensesArchive } from "@prisma/client";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class ExpensesArchivalService {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import { Controller, Param, Query, Body, Get, Post, BadRequestException, ParseIntPipe, Delete, Patch } from "@nestjs/common";
|
||||
import { SchedulePresetsCommandService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-command.service";
|
||||
import { SchedulePresetsUpsertService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-upsert.service";
|
||||
import { SchedulePresetsApplyService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-apply.service";
|
||||
import { SchedulePresetsQueryService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service";
|
||||
import { SchedulePresetsGetService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-get.service";
|
||||
import { SchedulePresetsUpdateDto } from "src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/update-schedule-presets.dto";
|
||||
import { SchedulePresetsDto } from "src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-presets.dto";
|
||||
|
||||
@Controller('schedule-presets')
|
||||
export class SchedulePresetsController {
|
||||
constructor(
|
||||
private readonly commandService: SchedulePresetsCommandService,
|
||||
private readonly upsertService: SchedulePresetsUpsertService,
|
||||
private readonly applyPresetsService: SchedulePresetsApplyService,
|
||||
private readonly queryService: SchedulePresetsQueryService,
|
||||
private readonly getService: SchedulePresetsGetService,
|
||||
){}
|
||||
|
||||
//used to create a schedule preset
|
||||
|
|
@ -19,7 +19,7 @@ export class SchedulePresetsController {
|
|||
@Param('employee_id', ParseIntPipe) employee_id: number,
|
||||
@Body() dto: SchedulePresetsDto,
|
||||
) {
|
||||
return await this.commandService.createPreset(employee_id, dto);
|
||||
return await this.upsertService.createPreset(employee_id, dto);
|
||||
}
|
||||
|
||||
//used to update an already existing schedule preset
|
||||
|
|
@ -28,7 +28,7 @@ export class SchedulePresetsController {
|
|||
@Param('preset_id', ParseIntPipe) preset_id: number,
|
||||
@Body() dto: SchedulePresetsUpdateDto,
|
||||
) {
|
||||
return await this.commandService.updatePreset(preset_id, dto);
|
||||
return await this.upsertService.updatePreset(preset_id, dto);
|
||||
}
|
||||
|
||||
//used to delete a schedule preset
|
||||
|
|
@ -36,7 +36,7 @@ export class SchedulePresetsController {
|
|||
async deletePreset(
|
||||
@Param('preset_id') preset_id: number,
|
||||
) {
|
||||
return await this.commandService.deletePreset(preset_id);
|
||||
return await this.upsertService.deletePreset(preset_id);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ export class SchedulePresetsController {
|
|||
async findListById(
|
||||
@Param('employee_id', ParseIntPipe) employee_id: number,
|
||||
) {
|
||||
return this.queryService.findSchedulePresets(employee_id);
|
||||
return this.getService.getSchedulePresets(employee_id);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ArrayMinSize, IsArray, IsBoolean, IsOptional, IsString } from "class-validator";
|
||||
import { SchedulePresetShiftsDto } from "./create-schedule-preset-shifts.dto";
|
||||
import { SchedulePresetShiftsDto } from "src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-preset-shifts.dto";
|
||||
|
||||
export class SchedulePresetsDto {
|
||||
@IsString()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { SchedulePresetsCommandService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-command.service";
|
||||
import { SchedulePresetsUpsertService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-upsert.service";
|
||||
import { SchedulePresetsApplyService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-apply.service";
|
||||
import { SchedulePresetsQueryService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service";
|
||||
import { SchedulePresetsGetService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-get.service";
|
||||
import { SchedulePresetsController } from "src/time-and-attendance/modules/time-tracker/schedule-presets/controller/schedule-presets.controller";
|
||||
import { SharedModule } from "src/time-and-attendance/modules/shared/shared.module";
|
||||
import { Module } from "@nestjs/common";
|
||||
|
|
@ -10,13 +10,13 @@ import { Module } from "@nestjs/common";
|
|||
imports: [SharedModule],
|
||||
controllers: [SchedulePresetsController],
|
||||
providers: [
|
||||
SchedulePresetsCommandService,
|
||||
SchedulePresetsQueryService,
|
||||
SchedulePresetsUpsertService,
|
||||
SchedulePresetsGetService,
|
||||
SchedulePresetsApplyService,
|
||||
],
|
||||
exports:[
|
||||
SchedulePresetsCommandService,
|
||||
SchedulePresetsQueryService,
|
||||
SchedulePresetsUpsertService,
|
||||
SchedulePresetsGetService,
|
||||
SchedulePresetsApplyService,
|
||||
],
|
||||
}) export class SchedulePresetsModule {}
|
||||
|
|
@ -4,10 +4,10 @@ import { Injectable } from "@nestjs/common";
|
|||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Injectable()
|
||||
export class SchedulePresetsQueryService {
|
||||
export class SchedulePresetsGetService {
|
||||
constructor( private readonly prisma: PrismaService ){}
|
||||
|
||||
async findSchedulePresets(employee_id: number): Promise<PresetResponse[]> {
|
||||
async getSchedulePresets(employee_id: number): Promise<PresetResponse[]> {
|
||||
try {
|
||||
const presets = await this.prisma.schedulePresets.findMany({
|
||||
where: { employee_id },
|
||||
|
|
@ -1,16 +1,13 @@
|
|||
import { Injectable, BadRequestException, NotFoundException, ConflictException } from "@nestjs/common";
|
||||
import { CreatePresetResult, DeletePresetResult, UpdatePresetResult } from "src/time-and-attendance/utils/type.utils";
|
||||
import { SchedulePresetsDto } from "src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-presets.dto";
|
||||
import { BankCodesResolver } from "src/time-and-attendance/modules/shared/utils/resolve-bank-type-id.utils";
|
||||
import { Prisma, Weekday } from "@prisma/client";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { toHHmmFromDate } from "src/time-and-attendance/utils/date-time.utils";
|
||||
|
||||
type DeleteResult = { ok: true; id: number; } | { ok: false; id: number; error: any };
|
||||
type CreateResult = { ok: true; } | { ok: false; error: any };
|
||||
type UpdateResult = { ok: true; id: number; data: SchedulePresetsDto } | { ok: false; id: number; error: any };
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
|
||||
@Injectable()
|
||||
export class SchedulePresetsCommandService {
|
||||
export class SchedulePresetsUpsertService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly typeResolver : BankCodesResolver,
|
||||
|
|
@ -18,7 +15,7 @@ export class SchedulePresetsCommandService {
|
|||
//_________________________________________________________________
|
||||
// CREATE
|
||||
//_________________________________________________________________
|
||||
async createPreset( employee_id: number, dto: SchedulePresetsDto): Promise<CreateResult> {
|
||||
async createPreset( employee_id: number, dto: SchedulePresetsDto): Promise<CreatePresetResult> {
|
||||
try {
|
||||
const shifts_data = await this.resolveAndBuildPresetShifts(dto);
|
||||
if(!shifts_data) throw new BadRequestException(`Employee with id: ${employee_id} or dto not found`);
|
||||
|
|
@ -49,7 +46,7 @@ export class SchedulePresetsCommandService {
|
|||
//_________________________________________________________________
|
||||
// UPDATE
|
||||
//_________________________________________________________________
|
||||
async updatePreset( preset_id: number, dto: SchedulePresetsDto ): Promise<UpdateResult> {
|
||||
async updatePreset( preset_id: number, dto: SchedulePresetsDto ): Promise<UpdatePresetResult> {
|
||||
try {
|
||||
const existing = await this.prisma.schedulePresets.findFirst({
|
||||
where: { id: preset_id },
|
||||
|
|
@ -137,7 +134,7 @@ export class SchedulePresetsCommandService {
|
|||
//_________________________________________________________________
|
||||
// DELETE
|
||||
//_________________________________________________________________
|
||||
async deletePreset( preset_id: number ): Promise <DeleteResult> {
|
||||
async deletePreset( preset_id: number ): Promise <DeletePresetResult> {
|
||||
try {
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
const preset = await tx.schedulePresets.findFirst({
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import { BadRequestException, Body, Controller, Delete, Param, Patch, Post } from "@nestjs/common";
|
||||
import { CreateResult, UpdateResult } from "src/time-and-attendance/utils/type.utils";
|
||||
import { CreateShiftResult, UpdateShiftResult } from "src/time-and-attendance/utils/type.utils";
|
||||
import { ShiftsUpsertService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service";
|
||||
import { UpdateShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-update.dto";
|
||||
import { ShiftDto } from "../dtos/shift-create.dto";
|
||||
import { ShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-create.dto";
|
||||
|
||||
|
||||
@Controller('shift')
|
||||
|
|
@ -11,7 +11,7 @@ export class ShiftController {
|
|||
|
||||
@Post('create')
|
||||
createBatch(
|
||||
@Body()dtos: ShiftDto[]): Promise<CreateResult[]> {
|
||||
@Body()dtos: ShiftDto[]): Promise<CreateShiftResult[]> {
|
||||
const list = Array.isArray(dtos) ? dtos : [];
|
||||
if(list.length === 0) throw new BadRequestException('Body is missing or invalid (create shifts)');
|
||||
return this.upsert_service.createShifts(dtos)
|
||||
|
|
@ -21,7 +21,7 @@ export class ShiftController {
|
|||
//change Body to receive dtos
|
||||
@Patch('update')
|
||||
updateBatch(
|
||||
@Body() dtos: UpdateShiftDto[]): Promise<UpdateResult[]>{
|
||||
@Body() dtos: UpdateShiftDto[]): Promise<UpdateShiftResult[]>{
|
||||
const list = Array.isArray(dtos) ? dtos: [];
|
||||
if(list.length === 0) throw new BadRequestException('Body is missing or invalid (update shifts)');
|
||||
return this.upsert_service.updateShifts(dtos);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { PartialType, OmitType } from "@nestjs/swagger";
|
||||
import { ShiftDto } from "./shift-create.dto";
|
||||
import { ShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-create.dto";
|
||||
import { IsInt } from "class-validator";
|
||||
|
||||
export class UpdateShiftDto extends PartialType(
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { toStringFromDate, toStringFromHHmm } from "../../../../utils/date-time.utils";
|
||||
import { toStringFromDate, toStringFromHHmm } from "src/time-and-attendance/utils/date-time.utils";
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { shift_select } from "src/time-and-attendance/utils/selects.utils";
|
||||
import { GetShiftDto } from "../dtos/shift-get.dto";
|
||||
import { GetShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-get.dto";
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* _____________________________________________________________________________________
|
||||
*
|
||||
*
|
||||
|
|
@ -15,6 +16,7 @@ import { GetShiftDto } from "../dtos/shift-get.dto";
|
|||
* _____________________________________________________________________________________
|
||||
*/
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ShiftsGetService {
|
||||
constructor(
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { CreateResult, NormedOk, NormedErr, UpdatePayload, UpdateResult, Normalized, UpdateChanges } from "src/time-and-attendance/utils/type.utils";
|
||||
import { overlaps, toDateFromString, toHHmmFromString, toStringFromDate, toStringFromHHmm } from "../../../../utils/date-time.utils";
|
||||
import { BadRequestException, ConflictException, Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { CreateShiftResult, NormedOk, NormedErr, UpdateShiftResult, UpdateShiftPayload, UpdateShiftChanges, Normalized } from "src/time-and-attendance/utils/type.utils";
|
||||
import { overlaps, toStringFromHHmm, toStringFromDate, toDateFromString, toHHmmFromString } from "src/time-and-attendance/utils/date-time.utils";
|
||||
import { Injectable, BadRequestException, ConflictException, NotFoundException } from "@nestjs/common";
|
||||
import { OvertimeService } from "src/time-and-attendance/domains/services/overtime.service";
|
||||
import { UpdateShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-update.dto";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { shift_select } from "src/time-and-attendance/utils/selects.utils";
|
||||
import { GetShiftDto } from "../dtos/shift-get.dto";
|
||||
import { ShiftDto } from "../dtos/shift-create.dto";
|
||||
import { GetShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-get.dto";
|
||||
import { ShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-create.dto";
|
||||
|
||||
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ export class ShiftsUpsertService {
|
|||
//checks for overlaping shifts
|
||||
//create new shifts
|
||||
//calculate overtime
|
||||
async createShifts(dtos: ShiftDto[]): Promise<CreateResult[]> {
|
||||
async createShifts(dtos: ShiftDto[]): Promise<CreateShiftResult[]> {
|
||||
if (!Array.isArray(dtos) || dtos.length === 0) return [];
|
||||
|
||||
const normed_shift: Array<NormedOk | NormedErr> = dtos.map((dto, index) => {
|
||||
|
|
@ -66,14 +66,14 @@ export class ShiftsUpsertService {
|
|||
});
|
||||
return dtos.map((_dto, key) =>
|
||||
indices.includes(key)
|
||||
? ({ ok: false, error: err } as CreateResult)
|
||||
? ({ ok: false, error: err } as CreateShiftResult)
|
||||
: ({ ok: false, error: new BadRequestException('Batch aborted due to overlaps in another date group') })
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.prisma.$transaction(async (tx) => {
|
||||
const results: CreateResult[] = Array.from({ length: dtos.length }, () => ({ ok: false, error: new Error('uninitialized') }));
|
||||
const results: CreateShiftResult[] = Array.from({ length: dtos.length }, () => ({ ok: false, error: new Error('uninitialized') }));
|
||||
|
||||
|
||||
normed_shift.forEach((x, i) => {
|
||||
|
|
@ -157,16 +157,16 @@ export class ShiftsUpsertService {
|
|||
// update shifts in DB
|
||||
// recalculate overtime after update
|
||||
// return an updated version to display
|
||||
async updateShifts(dtos: UpdateShiftDto[]): Promise<UpdateResult[]> {
|
||||
async updateShifts(dtos: UpdateShiftDto[]): Promise<UpdateShiftResult[]> {
|
||||
if (!Array.isArray(dtos) || dtos.length === 0) return [];
|
||||
|
||||
const updates: UpdatePayload[] = dtos.map((item) => {
|
||||
const updates: UpdateShiftPayload[] = dtos.map((item) => {
|
||||
const { id, ...rest } = item;
|
||||
if (!Number.isInteger(id)) {
|
||||
throw new BadRequestException('Update shift payload is missing a valid id');
|
||||
}
|
||||
|
||||
const changes: UpdateChanges = {};
|
||||
const changes: UpdateShiftChanges = {};
|
||||
if (rest.date !== undefined) changes.date = rest.date;
|
||||
if (rest.start_time !== undefined) changes.start_time = rest.start_time;
|
||||
if (rest.end_time !== undefined) changes.end_time = rest.end_time;
|
||||
|
|
@ -189,12 +189,12 @@ export class ShiftsUpsertService {
|
|||
const existing = regroup_id.get(update.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 UpdateResult)
|
||||
? ({ 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') }));
|
||||
}
|
||||
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 UpdateResult)
|
||||
? ({ 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') }));
|
||||
}
|
||||
}
|
||||
|
|
@ -249,7 +249,7 @@ export class ShiftsUpsertService {
|
|||
message: 'New shift overlaps with existing shift(s)',
|
||||
conflicts: [{ start_time: toStringFromHHmm(conflict.start), end_time: toStringFromHHmm(conflict.end), type: 'UNKNOWN' }],
|
||||
})
|
||||
} as UpdateResult)
|
||||
} as UpdateShiftResult)
|
||||
: ({ ok: false, id: exist.id, error: new BadRequestException('Batch aborted due to overlap in another update') })
|
||||
);
|
||||
}
|
||||
|
|
@ -271,7 +271,7 @@ export class ShiftsUpsertService {
|
|||
}
|
||||
}
|
||||
|
||||
const results: UpdateResult[] = [];
|
||||
const results: UpdateShiftResult[] = [];
|
||||
for (const planned of planned_updates) {
|
||||
const data: any = {};
|
||||
const { dto } = planned.update;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
|
||||
import { BusinessLogicsModule } from 'src/time-and-attendance/domains/business-logics.module';
|
||||
import { ShiftsUpsertService } from './services/shifts-upsert.service';
|
||||
import { ShiftsGetService } from './services/shifts-get.service';
|
||||
import { ShiftController } from './controllers/shift.controller';
|
||||
import { ShiftsUpsertService } from 'src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service';
|
||||
import { ShiftsGetService } from 'src/time-and-attendance/modules/time-tracker/shifts/services/shifts-get.service';
|
||||
import { ShiftController } from 'src/time-and-attendance/modules/time-tracker/shifts/controllers/shift.controller';
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { EmailToIdResolver } from "src/time-and-attendance/modules/shared/utils/resolve-email-id.utils";
|
||||
import { GetTimesheetsOverviewService } from "../services/timesheet-get-overview.service";
|
||||
import { GetTimesheetsOverviewService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-get-overview.service";
|
||||
import { BadRequestException, Controller, Get, Query} from "@nestjs/common";
|
||||
import { EmailToIdResolver } from "src/time-and-attendance/modules/shared/utils/resolve-email-id.utils";
|
||||
|
||||
@Controller('timesheets')
|
||||
export class TimesheetController {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Injectable } from "@nestjs/common";
|
||||
import { Prisma, Timesheets } from "@prisma/client";
|
||||
import { BaseApprovalService } from "src/common/shared/base-approval.service";
|
||||
import { Prisma, Timesheets } from "@prisma/client";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class TimesheetApprovalService extends BaseApprovalService<Timesheets>{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { NUMBER_OF_TIMESHEETS_TO_RETURN } from "src/time-and-attendance/utils/constants.utils";
|
||||
import { sevenDaysFrom, toStringFromDate, toHHmmFromDate, toDateFromString } from "src/time-and-attendance/utils/date-time.utils";
|
||||
import { NUMBER_OF_TIMESHEETS_TO_RETURN } from "src/time-and-attendance/utils/constants.utils";
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { TotalExpenses, TotalHours } from "src/time-and-attendance/utils/type.utils";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
|
||||
@Injectable()
|
||||
export class GetTimesheetsOverviewService {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { GetTimesheetsOverviewService } from './services/timesheet-get-overview.service';
|
||||
import { TimesheetArchiveService } from './services/timesheet-archive.service';
|
||||
import { TimesheetController } from './controllers/timesheet.controller';
|
||||
import { SharedModule } from '../../shared/shared.module';
|
||||
import { GetTimesheetsOverviewService } from 'src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-get-overview.service';
|
||||
import { TimesheetArchiveService } from 'src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service';
|
||||
import { TimesheetController } from 'src/time-and-attendance/modules/time-tracker/timesheets/controllers/timesheet.controller';
|
||||
import { SharedModule } from 'src/time-and-attendance/modules/shared/shared.module';
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { SchedulePresetsCommandService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-command.service";
|
||||
import { SchedulePresetsUpsertService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-upsert.service";
|
||||
import { GetTimesheetsOverviewService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-get-overview.service";
|
||||
import { SchedulePresetsQueryService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service";
|
||||
import { SchedulePresetsGetService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-get.service";
|
||||
import { SchedulePresetsApplyService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-apply.service";
|
||||
import { SchedulePresetsController } from "src/time-and-attendance/modules/time-tracker/schedule-presets/controller/schedule-presets.controller";
|
||||
import { BusinessLogicsModule } from "src/time-and-attendance/domains/business-logics.module";
|
||||
|
|
@ -31,8 +31,8 @@ import { Module } from "@nestjs/common";
|
|||
ShiftsGetService,
|
||||
ShiftsUpsertService,
|
||||
ExpenseUpsertService,
|
||||
SchedulePresetsCommandService,
|
||||
SchedulePresetsQueryService,
|
||||
SchedulePresetsUpsertService,
|
||||
SchedulePresetsGetService,
|
||||
SchedulePresetsApplyService,
|
||||
],
|
||||
exports: [],
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ export const NUMBER_OF_TIMESHEETS_TO_RETURN = 2;
|
|||
export const DAILY_LIMIT_HOURS = 8;
|
||||
export const WEEKLY_LIMIT_HOURS = 40;
|
||||
export const PAY_PERIOD_ANCHOR = 2023-12-17;
|
||||
export const ANCHOR_ISO = '2023-12-17'; // ancre date
|
||||
export const ANCHOR_ISO = '2023-12-17';
|
||||
export const PERIOD_DAYS = 14;
|
||||
export const PERIODS_PER_YEAR = 26;
|
||||
export const MS_PER_DAY = 86_400_000;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ import { UpdateShiftDto } from "src/time-and-attendance/modules/time-tracker/shi
|
|||
import { GetShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-get.dto";
|
||||
import { ShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-create.dto";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { SchedulePresetsDto } from "src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-presets.dto";
|
||||
import { GetExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-get.dto";
|
||||
import { updateExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-update.dto";
|
||||
|
||||
export type TotalHours = {
|
||||
regular: number;
|
||||
|
|
@ -29,11 +32,24 @@ export type ShiftWithOvertimeDto = {
|
|||
overtime: WeekOvertimeSummary;
|
||||
};
|
||||
|
||||
export type CreateResult = { ok: true; data: ShiftWithOvertimeDto } | { ok: false; error: any };
|
||||
export type UpdateChanges = Omit<UpdateShiftDto, 'id'>;
|
||||
export type UpdatePayload = { id: number; dto: UpdateChanges };
|
||||
export type UpdateResult = { ok: true; id: number; data: ShiftWithOvertimeDto } | { ok: false; id: number; error: any };
|
||||
export type DeleteResult = { ok: true; id: number; overtime: WeekOvertimeSummary } | { ok: false; id: number; error: any };
|
||||
export type CreateShiftResult = { ok: true; data: ShiftWithOvertimeDto } | { ok: false; error: any };
|
||||
export type UpdateShiftChanges = Omit<UpdateShiftDto, 'id'>;
|
||||
export type UpdateShiftPayload = { 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 };
|
||||
|
||||
export type DeletePresetResult = { ok: true; id: number; } | { ok: false; id: number; error: any };
|
||||
export type CreatePresetResult = { ok: true; } | { ok: false; error: any };
|
||||
export type UpdatePresetResult = { ok: true; id: number; data: SchedulePresetsDto } | { ok: false; id: number; error: any };
|
||||
|
||||
export type NormalizedExpense = { date: Date; comment: string; supervisor_comment?: string; };
|
||||
|
||||
export type CreateExpenseResult = { ok: true; data: GetExpenseDto } | { ok: false; error: any };
|
||||
export type UpdateExpensePayload = { id: number; dto: updateExpenseDto };
|
||||
export type UpdateExpenseResult = { ok: true; id: number; data: GetExpenseDto } | { ok: false; id: number; error: any };
|
||||
export type DeleteExpenseResult = { ok: true; id: number; } | { ok: false; id: number; error: any };
|
||||
|
||||
|
||||
|
||||
export type NormedOk = { index: number; dto: ShiftDto; normed: Normalized };
|
||||
export type NormedErr = { index: number; error: any };
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user