refactor(routes): ajusted routes on Patch functions

This commit is contained in:
Matthieu Haineault 2025-08-25 13:14:19 -04:00
parent 301d5f2c9d
commit 72f6cc8a9e
6 changed files with 54 additions and 58 deletions

View File

@ -464,24 +464,36 @@
] ]
}, },
"get": { "get": {
"operationId": "TimesheetsController_findAll", "operationId": "TimesheetsController_getPeriodByQuery",
"parameters": [], "parameters": [
"responses": { {
"201": { "name": "year",
"description": "List of timesheet found", "required": true,
"content": { "in": "query",
"application/json": { "schema": {
"schema": { "type": "number"
"type": "array",
"items": {
"$ref": "#/components/schemas/CreateTimesheetDto"
}
}
}
} }
}, },
"400": { {
"description": "List of timesheets not found" "name": "period_no",
"required": true,
"in": "query",
"schema": {
"type": "number"
}
},
{
"name": "email",
"required": true,
"in": "query",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": ""
} }
}, },
"security": [ "security": [
@ -489,7 +501,6 @@
"access-token": [] "access-token": []
} }
], ],
"summary": "Find all timesheets",
"tags": [ "tags": [
"Timesheets" "Timesheets"
] ]
@ -618,7 +629,7 @@
] ]
} }
}, },
"/timesheets/{id}/approval": { "/timesheets/approval/{id}": {
"patch": { "patch": {
"operationId": "TimesheetsController_approve", "operationId": "TimesheetsController_approve",
"parameters": [ "parameters": [
@ -840,7 +851,7 @@
] ]
} }
}, },
"/Expenses/{id}/approval": { "/Expenses/approval/{id}": {
"patch": { "patch": {
"operationId": "ExpensesController_approve", "operationId": "ExpensesController_approve",
"parameters": [ "parameters": [
@ -1062,7 +1073,7 @@
] ]
} }
}, },
"/shifts/{id}/approval": { "/shifts/approval/{id}": {
"patch": { "patch": {
"operationId": "ShiftsController_approve", "operationId": "ShiftsController_approve",
"parameters": [ "parameters": [
@ -1206,7 +1217,7 @@
"schema": { "schema": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/components/schemas/CreateLeaveRequestsDto" "$ref": "#/components/schemas/LeaveRequestViewDto"
} }
} }
} }
@ -1246,7 +1257,7 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "#/components/schemas/CreateLeaveRequestsDto" "$ref": "#/components/schemas/LeaveRequestViewDto"
} }
} }
} }
@ -1293,7 +1304,7 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "#/components/schemas/CreateLeaveRequestsDto" "$ref": "#/components/schemas/LeaveRequestViewDto"
} }
} }
} }
@ -1350,7 +1361,7 @@
] ]
} }
}, },
"/leave-requests/{id}/approval": { "/leave-requests/approval/{id}": {
"patch": { "patch": {
"operationId": "LeaveRequestController_updateApproval", "operationId": "LeaveRequestController_updateApproval",
"parameters": [ "parameters": [
@ -2646,16 +2657,6 @@
"CreateLeaveRequestsDto": { "CreateLeaveRequestsDto": {
"type": "object", "type": "object",
"properties": { "properties": {
"id": {
"type": "number",
"example": 1,
"description": "Leave request`s unique id(auto-incremented)"
},
"employee_id": {
"type": "number",
"example": "4655867",
"description": "Employee`s id"
},
"bank_code_id": { "bank_code_id": {
"type": "number", "type": "number",
"example": 7, "example": 7,
@ -2667,13 +2668,11 @@
"description": "type of leave request for an accounting perception" "description": "type of leave request for an accounting perception"
}, },
"start_date_time": { "start_date_time": {
"format": "date-time",
"type": "string", "type": "string",
"example": "22/06/2463", "example": "22/06/2463",
"description": "Leave request`s start date" "description": "Leave request`s start date"
}, },
"end_date_time": { "end_date_time": {
"format": "date-time",
"type": "string", "type": "string",
"example": "25/03/3019", "example": "25/03/3019",
"description": "Leave request`s end date" "description": "Leave request`s end date"
@ -2690,8 +2689,6 @@
} }
}, },
"required": [ "required": [
"id",
"employee_id",
"bank_code_id", "bank_code_id",
"leave_type", "leave_type",
"start_date_time", "start_date_time",
@ -2700,19 +2697,13 @@
"approval_status" "approval_status"
] ]
}, },
"LeaveRequestViewDto": {
"type": "object",
"properties": {}
},
"UpdateLeaveRequestsDto": { "UpdateLeaveRequestsDto": {
"type": "object", "type": "object",
"properties": { "properties": {
"id": {
"type": "number",
"example": 1,
"description": "Leave request`s unique id(auto-incremented)"
},
"employee_id": {
"type": "number",
"example": "4655867",
"description": "Employee`s id"
},
"bank_code_id": { "bank_code_id": {
"type": "number", "type": "number",
"example": 7, "example": 7,
@ -2724,13 +2715,11 @@
"description": "type of leave request for an accounting perception" "description": "type of leave request for an accounting perception"
}, },
"start_date_time": { "start_date_time": {
"format": "date-time",
"type": "string", "type": "string",
"example": "22/06/2463", "example": "22/06/2463",
"description": "Leave request`s start date" "description": "Leave request`s start date"
}, },
"end_date_time": { "end_date_time": {
"format": "date-time",
"type": "string", "type": "string",
"example": "25/03/3019", "example": "25/03/3019",
"description": "Leave request`s end date" "description": "Leave request`s end date"

View File

@ -65,7 +65,7 @@ export class ExpensesController {
return this.expensesService.remove(id); return this.expensesService.remove(id);
} }
@Patch(':id/approval') @Patch('approval/:id')
//@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) //@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
async approve(@Param('id', ParseIntPipe) id: number, @Body('is_approved', ParseBoolPipe) isApproved: boolean) { async approve(@Param('id', ParseIntPipe) id: number, @Body('is_approved', ParseBoolPipe) isApproved: boolean) {
return this.expensesApprovalService.updateApproval(id, isApproved); return this.expensesApprovalService.updateApproval(id, isApproved);

View File

@ -64,7 +64,7 @@ export class LeaveRequestController {
} }
//remove emp_id and use email //remove emp_id and use email
@Patch(':id/approval') @Patch('approval/:id')
updateApproval( @Param('id', ParseIntPipe) id: number, updateApproval( @Param('id', ParseIntPipe) id: number,
@Body('is_approved', ParseBoolPipe) is_approved: boolean): Promise<LeaveRequestViewDto> { @Body('is_approved', ParseBoolPipe) is_approved: boolean): Promise<LeaveRequestViewDto> {
const approvalStatus = is_approved ? const approvalStatus = is_approved ?

View File

@ -96,7 +96,14 @@ export class PayPeriodsQueryService {
const crew = await this.resolveCrew(supervisor.id, include_subtree); // [{ id, first_name, last_name }] const crew = await this.resolveCrew(supervisor.id, include_subtree); // [{ id, first_name, last_name }]
const crew_ids = crew.map(c => c.id); const crew_ids = crew.map(c => c.id);
// seed names map for employee without data // seed names map for employee without data
const seed_names = new Map<number, string>(crew.map(crew => [crew.id, `${crew.first_name} ${crew.last_name}`.trim()])); const seed_names = new Map<number, { name: string; email: string }>(
crew.map(crew => [
crew.id,
{ name:`${crew.first_name} ${crew.last_name}`.trim(),
email: crew.email }
]
)
);
// 4) overview build // 4) overview build
return this.buildOverview({ return this.buildOverview({
@ -112,7 +119,7 @@ export class PayPeriodsQueryService {
private async buildOverview( private async buildOverview(
period: { period_start: string | Date; period_end: string | Date; payday: string | Date; period: { period_start: string | Date; period_end: string | Date; payday: string | Date;
period_no: number; pay_year: number; label: string; }, period_no: number; pay_year: number; label: string; },
options?: { filtered_employee_ids?: number[]; seed_names?: Map<number, string> }, options?: { filtered_employee_ids?: number[]; seed_names?: Map<number, {name: string, email: string}>}
): Promise<PayPeriodOverviewDto> { ): Promise<PayPeriodOverviewDto> {
const toDateString = (d: Date) => d.toISOString().slice(0, 10); const toDateString = (d: Date) => d.toISOString().slice(0, 10);
const toMoney = (v: any) => (typeof v === "object" && "toNumber" in v ? v.toNumber() : (v as number)); const toMoney = (v: any) => (typeof v === "object" && "toNumber" in v ? v.toNumber() : (v as number));
@ -184,9 +191,9 @@ export class PayPeriodsQueryService {
// seed for employee without data // seed for employee without data
if (options?.seed_names) { if (options?.seed_names) {
for (const [id, name] of options.seed_names.entries()) { for (const [id, {name, email}] of options.seed_names.entries()) {
by_employee.set(id, { by_employee.set(id, {
email: '', email,
employee_name: name, employee_name: name,
regular_hours: 0, regular_hours: 0,
evening_hours: 0, evening_hours: 0,

View File

@ -67,7 +67,7 @@ export class ShiftsController {
return this.shiftsService.remove(id); return this.shiftsService.remove(id);
} }
@Patch(':id/approval') @Patch('approval/:id')
//@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) //@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
async approve(@Param('id', ParseIntPipe) id: number, @Body('is_approved', ParseBoolPipe) isApproved: boolean) { async approve(@Param('id', ParseIntPipe) id: number, @Body('is_approved', ParseBoolPipe) isApproved: boolean) {
return this.shiftsApprovalService.updateApproval(id, isApproved); return this.shiftsApprovalService.updateApproval(id, isApproved);

View File

@ -70,7 +70,7 @@ export class TimesheetsController {
return this.timesheetsQuery.remove(id); return this.timesheetsQuery.remove(id);
} }
@Patch(':id/approval') @Patch('approval/:id')
//@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) //@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
async approve(@Param('id', ParseIntPipe) id: number, @Body('is_approved', ParseBoolPipe) isApproved: boolean) { async approve(@Param('id', ParseIntPipe) id: number, @Body('is_approved', ParseBoolPipe) isApproved: boolean) {
return this.timesheetsCommand.updateApproval(id, isApproved); return this.timesheetsCommand.updateApproval(id, isApproved);