From d6a27741b53c30de3999faa81212867c674ba427 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Jul 2023 09:50:56 +0200 Subject: [PATCH] a --- .../back/methods/worker/getItemTypeWorker.js | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 modules/worker/back/methods/worker/getItemTypeWorker.js diff --git a/modules/worker/back/methods/worker/getItemTypeWorker.js b/modules/worker/back/methods/worker/getItemTypeWorker.js deleted file mode 100644 index b1f49ae99..000000000 --- a/modules/worker/back/methods/worker/getItemTypeWorker.js +++ /dev/null @@ -1,65 +0,0 @@ -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.remoteMethod('getItemTypeWorker', { - description: 'Returns the workers that appear in itemType', - accessType: 'READ', - accepts: [{ - arg: 'filter', - type: 'Object', - description: 'Filter defining where and paginated data', - required: true - }], - returns: { - type: ['object'], - root: true - }, - http: { - path: `/getItemTypeWorker`, - verb: 'GET' - } - }); - - Self.getItemTypeWorker = async(filter, options) => { - const myOptions = {}; - const conn = Self.dataSource.connector; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - const query = - `SELECT DISTINCT u.id, w.firstName, w.lastName, u.nickname, u.name - FROM itemType it - JOIN worker w ON w.id = it.workerFk - JOIN account.user u ON u.id = w.id`; - - let stmt = new ParameterizedSQL(query); - - let clientFilter = Object.assign({}, filter); - clientFilter.where = buildFilter(filter.where, (param, value) => { - switch (param) { - case 'role': - return {'r.name': value}; - case 'firstName': - return {or: [ - {'w.firstName': {like: `%${value}%`}}, - {'w.lastName': {like: `%${value}%`}}, - {'u.name': {like: `%${value}%`}}, - {'u.nickname': {like: `%${value}%`}} - ]}; - case 'id': - return {'w.id': value}; - } - }); - - let myFilter = { - where: {'u.active': true} - }; - - myFilter = mergeFilters(myFilter, clientFilter); - stmt.merge(conn.makeSuffix(myFilter)); - return conn.executeStmt(stmt); - }; -};