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',
|
||||
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 = {
|
||||
|
|
Loading…
Reference in New Issue