refs#5066 @2h order vehicles by user warehouse
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Pau 2023-01-31 09:21:07 +01:00
parent 87d4964438
commit a378831149
3 changed files with 55 additions and 1 deletions

View File

@ -0,0 +1,51 @@
module.exports = Self => {
Self.remoteMethodCtx('currentWarehouse', {
description: 'Get the vehicles with the ones on the current warehouse first',
accessType: 'READ',
returns: {
type: 'array',
root: true
},
http: {
path: `/currentWarehouse`,
verb: 'GET'
}
});
Self.currentWarehouse = async(ctx, options) => {
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
let worker = await models.UserConfig.findOne({
where: {
userFk: ctx.req.accessToken.userId
},
}, myOptions);
if (!worker) throw new Error('User not found');
const query =
`SELECT v.id, v.numberPlate, v.warehouseFk
FROM vehicle v
ORDER BY warehouseFk = ${worker.warehouseFk} DESC`;
const result = await Self.rawSql(query, null, myOptions);
if (tx) await tx.commit();
return result;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/vehicle/currentWarehouse')(Self);
};

View File

@ -24,7 +24,7 @@
<vn-autocomplete
vn-one
ng-model="$ctrl.route.vehicleFk"
url="Vehicles"
url="Vehicles/currentWarehouse"
show-field="numberPlate"
value-field="id"
label="Vehicle">