feat: refs #7119 remove vehicleStateFk argument from filter method and simplify search logic
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
f8c1e2aacf
commit
b01e4894c9
|
@ -42,9 +42,6 @@ module.exports = Self => {
|
||||||
}, {
|
}, {
|
||||||
arg: 'isKmTruckRate',
|
arg: 'isKmTruckRate',
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
}, {
|
|
||||||
arg: 'vehicleStateFk',
|
|
||||||
type: 'number'
|
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
type: ['object'],
|
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) => {
|
Self.filter = async(filter, search, id, description, companyFk, tradeMark, numberPlate, warehouseFk, chassis, leasing, countryCodeFk, isKmTruckRate, options) => {
|
||||||
const models = Self.app.models;
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
const myWhere = {};
|
const myWhere = {};
|
||||||
const ids = [];
|
|
||||||
const {limit, order, skip, where} = filter;
|
const {limit, order, skip, where} = filter;
|
||||||
|
|
||||||
if (typeof options == 'object') Object.assign(myOptions, options);
|
if (typeof options == 'object') Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (search) myWhere.or = [{id: search}, {numberPlate: {like: `%${numberPlate}%`}}];
|
if (search) myWhere.or = [{id: search}, {numberPlate: {like: `%${search}%`}}];
|
||||||
if (id) ids.push(id);
|
if (id) myWhere.id = id;
|
||||||
if (description) myWhere.description = {like: `%${description}%`};
|
if (description) myWhere.description = {like: `%${description}%`};
|
||||||
if (companyFk) myWhere.companyFk = companyFk;
|
if (companyFk) myWhere.companyFk = companyFk;
|
||||||
if (tradeMark) myWhere.tradeMark = {like: `%${tradeMark}%`};
|
if (tradeMark) myWhere.tradeMark = {like: `%${tradeMark}%`};
|
||||||
|
@ -76,14 +71,7 @@ module.exports = Self => {
|
||||||
if (leasing) myWhere.leasing = {like: `%${leasing}%`};
|
if (leasing) myWhere.leasing = {like: `%${leasing}%`};
|
||||||
if (countryCodeFk) myWhere.countryCodeFk = countryCodeFk;
|
if (countryCodeFk) myWhere.countryCodeFk = countryCodeFk;
|
||||||
if (isKmTruckRate) myWhere.isKmTruckRate = isKmTruckRate;
|
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);
|
Object.assign(where || {}, myWhere);
|
||||||
|
|
||||||
const myFilter = {
|
const myFilter = {
|
||||||
|
|
Loading…
Reference in New Issue