From ebfba823b05efd62f0f4bcfb1f742bbc1720350a Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 21 Feb 2025 14:59:02 +0100 Subject: [PATCH] fix: refs #6553 workerBusiness, workerDescriptor --- .../11454-orangeDracena/00-firstScript.sql | 3 + .../back/methods/worker/getWorkerBusiness.js | 258 ++++++++++++++++++ modules/worker/back/models/worker.js | 1 + 3 files changed, 262 insertions(+) create mode 100644 db/versions/11454-orangeDracena/00-firstScript.sql create mode 100644 modules/worker/back/methods/worker/getWorkerBusiness.js diff --git a/db/versions/11454-orangeDracena/00-firstScript.sql b/db/versions/11454-orangeDracena/00-firstScript.sql new file mode 100644 index 0000000000..05b2a8c059 --- /dev/null +++ b/db/versions/11454-orangeDracena/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Worker','getWorkerBusiness','READ','ALLOW','ROLE','hr'); diff --git a/modules/worker/back/methods/worker/getWorkerBusiness.js b/modules/worker/back/methods/worker/getWorkerBusiness.js new file mode 100644 index 0000000000..1f65973cab --- /dev/null +++ b/modules/worker/back/methods/worker/getWorkerBusiness.js @@ -0,0 +1,258 @@ +const {filter} = require('jszip'); +const {ContextExclusionPlugin} = require('webpack'); + +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const buildFilter = require('vn-loopback/util/filter').buildFilter; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; + +module.exports = Self => { + Self.remoteMethodCtx('getWorkerBusiness', { + description: 'Returns an array of business from an specified worker', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'The worker id', + http: {source: 'path'} + }, + { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string' + }, + { + arg: 'started', + type: 'date', + description: 'started', + http: {source: 'query'} + }, + { + arg: 'ended', + type: 'date', + description: 'ended', + http: {source: 'query'} + }, + { + arg: 'companyCodeFk', + type: 'string', + description: 'companyCodeFk', + http: {source: 'query'} + }, + { + arg: 'reasonEndFk', + type: 'number', + description: 'reasonEndFk', + http: {source: 'query'} + }, + { + arg: 'reasondEnd', + type: 'string', + description: 'reasondEnd', + http: {source: 'query'} + }, + { + arg: 'departmentFk', + type: 'number', + description: 'departmentFk', + http: {source: 'query'} + }, + { + arg: 'department', + type: 'string', + description: 'department', + http: {source: 'query'} + }, + { + arg: 'workerBusinessProfessionalCategoryFk', + type: 'number', + description: 'workerBusinessProfessionalCategoryFk', + http: {source: 'query'} + }, + { + arg: 'workerBusinessProfessionalCategory', + type: 'string', + description: 'workerBusinessProfessionalCategory', + http: {source: 'query'} + }, + { + arg: 'calendarTypeFk', + type: 'number', + description: 'calendarTypeFk', + http: {source: 'query'} + }, + { + arg: 'calendarType', + type: 'string', + description: 'calendarType', + http: {source: 'query'} + }, + { + arg: 'workcenterFk', + type: 'number', + description: 'workcenterFk', + http: {source: 'query'} + }, + { + arg: 'workCenter', + type: 'string', + description: 'workCenter', + http: {source: 'query'} + }, + { + arg: 'workerBusinessCategoryFk', + type: 'number', + description: 'WorkerBusinessCategoryFk', + http: {source: 'query'} + }, + { + arg: 'workerBusinessCategory', + type: 'string', + description: 'workerBusinessCategory', + http: {source: 'query'} + }, + { + arg: 'occupationCodeFk', + type: 'number', + description: 'occupationCodeFk', + http: {source: 'query'} + }, + { + arg: 'occupationCode', + type: 'string', + description: 'occupationCode', + http: {source: 'query'} + }, + { + arg: 'rate', + type: 'number', + description: 'rate', + http: {source: 'query'} + }, + { + arg: 'workerBusinessTypeFk', + type: 'number', + description: 'workerBusinessTypeFk', + http: {source: 'query'} + }, + { + arg: 'workerBusinessType', + type: 'string', + description: 'workerBusinessType', + http: {source: 'query'} + }, + { + arg: 'amount', + type: 'number', + description: 'amount', + http: {source: 'query'} + }, + { + arg: 'basicSalary', + type: 'number', + description: 'amount', + http: {source: 'query'} + }, + { + arg: 'notes', + type: 'string', + description: 'notes', + http: {source: 'query'} + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: '/:id/getWorkerBusiness', + verb: 'GET' + } + }); + + Self.getWorkerBusiness = async(ctx, id, filter, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + let conn = Self.dataSource.connector; + let where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'started': + case 'ended': + case 'companyCodeFk': + case 'reasonEndFk': + case 'reasondEnd': + case 'departmentFk': + case 'department': + case 'workerBusinessProfessionalCategoryFk': + case 'workerBusinessProfessionalCategory': + case 'calendarTypeFk': + case 'calendarType': + case 'workcenterFk': + case 'workCenter': + case 'workerBusinessCategoryFk': + case 'workerBusinessCategory': + case 'occupationCodeFk': + case 'occupationCode': + case 'rate': + case 'workerBusinessTypeFk': + case 'workerBusinessType': + case 'amount': + case 'basicSalary': + case 'notes': + } + }); + where = {...where, ...{workerFk: id}}; + filter = mergeFilters(filter, {where}); + + let stmts = []; + let stmt; + + stmt = new ParameterizedSQL( + `SELECT * FROM( + SELECT b.id, + b.workerFk, + b.started, + b.ended, + b.companyCodeFk, + b.reasonEndFk, + bre.reason, + b.departmentFk, + d.name departmentName, + b.occupationCodeFk, + oc.name occupationName, + b.workerBusinessProfessionalCategoryFk, + pf.description professionalDescription, + b.calendarTypeFk, + ct.description calendarTypeDescription, + b.workcenterFk, + wc.name workCenterName, + b.workerBusinessCategoryFk, + py.description payrollDescription, + b.workerBusinessTypeFk, + wt.name workerBusinessTypeName, + b.amount, + b.basicSalary, + b.notes + FROM business b + LEFT JOIN businessReasonEnd bre ON bre.id = b.reasonEndFk + LEFT JOIN occupationCode oc ON oc.code = b.occupationCodeFk + LEFT JOIN department d ON d.id = b.departmentFk + LEFT JOIN professionalCategory pf ON pf.id = b.workerBusinessProfessionalCategoryFk + JOIN calendarType ct ON ct.id = b.calendarTypeFk + LEFT JOIN workCenter wc ON wc.id = b.workcenterFk + LEFT JOIN payrollCategories py ON py.id = b.workerBusinessCategoryFk + LEFT JOIN workerBusinessType wt ON wt.id = b.workerBusinessTypeFk + ) sub + ` + ); + + stmt.merge(conn.makeSuffix(filter)); + stmts.push(stmt); + + let sql = ParameterizedSQL.join(stmts, ';'); + let result = await conn.executeStmt(sql, myOptions); + return result; + }; +}; diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 4895a6107f..2f8c28ef4b 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -21,6 +21,7 @@ module.exports = Self => { require('../methods/worker/setPassword')(Self); require('../methods/worker/getAvailablePda')(Self); require('../methods/worker/myTeam')(Self); + require('../methods/worker/getWorkerBusiness')(Self); Self.canModifyAbsenceInPast = async(ctx, time) => { const hasPrivs = await Self.app.models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE');