From b01e4894c9c3a46e3385be2ebeaeb55589fd2aea Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 26 Dec 2024 17:02:37 +0100 Subject: [PATCH] feat: refs #7119 remove vehicleStateFk argument from filter method and simplify search logic --- modules/route/back/methods/vehicle/filter.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/modules/route/back/methods/vehicle/filter.js b/modules/route/back/methods/vehicle/filter.js index b6ba306ac..a6cec0294 100644 --- a/modules/route/back/methods/vehicle/filter.js +++ b/modules/route/back/methods/vehicle/filter.js @@ -42,9 +42,6 @@ module.exports = Self => { }, { arg: 'isKmTruckRate', type: 'boolean' - }, { - arg: 'vehicleStateFk', - type: 'number' }], returns: { type: ['object'], @@ -56,17 +53,15 @@ module.exports = Self => { } }); - Self.filter = async(filter, search, id, description, companyFk, tradeMark, numberPlate, warehouseFk, chassis, leasing, countryCodeFk, isKmTruckRate, vehicleStateFk, options) => { - const models = Self.app.models; + Self.filter = async(filter, search, id, description, companyFk, tradeMark, numberPlate, warehouseFk, chassis, leasing, countryCodeFk, isKmTruckRate, options) => { const myOptions = {}; const myWhere = {}; - const ids = []; const {limit, order, skip, where} = filter; if (typeof options == 'object') Object.assign(myOptions, options); - if (search) myWhere.or = [{id: search}, {numberPlate: {like: `%${numberPlate}%`}}]; - if (id) ids.push(id); + if (search) myWhere.or = [{id: search}, {numberPlate: {like: `%${search}%`}}]; + if (id) myWhere.id = id; if (description) myWhere.description = {like: `%${description}%`}; if (companyFk) myWhere.companyFk = companyFk; if (tradeMark) myWhere.tradeMark = {like: `%${tradeMark}%`}; @@ -76,14 +71,7 @@ module.exports = Self => { if (leasing) myWhere.leasing = {like: `%${leasing}%`}; if (countryCodeFk) myWhere.countryCodeFk = countryCodeFk; if (isKmTruckRate) myWhere.isKmTruckRate = isKmTruckRate; - if (vehicleStateFk) { - ids.push(...await models.VehicleEvent.find({ - fields: ['vehicleFk', 'vehicleStateFk'], - where: {vehicleStateFk}}).map(v => v.vehicleFk)); - } - const idsLeng = ids.length; - if (idsLeng) myWhere.id = idsLeng == 1 ? ids[0] : {inq: ids}; Object.assign(where || {}, myWhere); const myFilter = {