refs#5066 @2h order vehicles by user warehouse
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
87d4964438
commit
a378831149
|
@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/vehicle/currentWarehouse')(Self);
|
||||||
|
};
|
|
@ -24,7 +24,7 @@
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-one
|
vn-one
|
||||||
ng-model="$ctrl.route.vehicleFk"
|
ng-model="$ctrl.route.vehicleFk"
|
||||||
url="Vehicles"
|
url="Vehicles/currentWarehouse"
|
||||||
show-field="numberPlate"
|
show-field="numberPlate"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
label="Vehicle">
|
label="Vehicle">
|
||||||
|
|
Loading…
Reference in New Issue