diff --git a/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js b/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js index ca559f853..e635f61a9 100644 --- a/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js +++ b/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js @@ -1,8 +1,15 @@ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; + module.exports = Self => { Self.remoteMethodCtx('getItemTypeWorker', { description: 'Returns the workers that appear in itemType', accessType: 'READ', - accepts: [], + accepts: [{ + arg: 'filter', + type: 'Object', + description: 'Filter defining where and paginated data', + required: true + }], returns: { type: ['object'], root: true @@ -13,8 +20,9 @@ module.exports = Self => { } }); - Self.getItemTypeWorker = async(ctx, options) => { + Self.getItemTypeWorker = async(ctx, filter, options) => { const myOptions = {}; + const conn = Self.dataSource.connector; let tx; if (typeof options == 'object') @@ -32,11 +40,25 @@ module.exports = Self => { JOIN worker w ON w.id = it.workerFk JOIN account.user u ON u.id = w.id`; - const result = await Self.rawSql(query); + let stmt = new ParameterizedSQL(query); + + if (filter.where) { + const value = filter.where.firstName; + const myFilter = { + where: {or: [ + {'w.firstName': {like: `%${value}%`}}, + {'w.lastName': {like: `%${value}%`}}, + {'u.name': {like: `%${value}%`}}, + {'u.nickname': {like: `%${value}%`}} + ]} + }; + + stmt.merge(conn.makeSuffix(myFilter)); + } if (tx) await tx.commit(); - return result; + return conn.executeStmt(stmt); } catch (e) { if (tx) await tx.rollback(); throw e;