refs #5066 @3h fix back route so that the e2e does not fail
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
a378831149
commit
e54afb2321
|
@ -1,7 +1,14 @@
|
|||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('currentWarehouse', {
|
||||
description: 'Get the vehicles with the ones on the current warehouse first',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'filter',
|
||||
type: 'object',
|
||||
description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string`
|
||||
}],
|
||||
returns: {
|
||||
type: 'array',
|
||||
root: true
|
||||
|
@ -12,8 +19,9 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.currentWarehouse = async(ctx, options) => {
|
||||
Self.currentWarehouse = async(ctx, filter, options) => {
|
||||
const models = Self.app.models;
|
||||
const conn = Self.dataSource.connector;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
|
@ -34,15 +42,44 @@ module.exports = Self => {
|
|||
|
||||
if (!worker) throw new Error('User not found');
|
||||
|
||||
const query =
|
||||
/* const query =
|
||||
`SELECT v.id, v.numberPlate, v.warehouseFk
|
||||
FROM vehicle v
|
||||
ORDER BY warehouseFk = ${worker.warehouseFk} DESC`;
|
||||
ORDER BY warehouseFk = ${worker.warehouseFk} DESC`;*/
|
||||
|
||||
const result = await Self.rawSql(query, null, myOptions);
|
||||
let stmt = new ParameterizedSQL(
|
||||
`SELECT v.id, v.numberPlate, v.warehouseFk
|
||||
FROM vehicle v`,
|
||||
null, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return result;
|
||||
if (filter.order) {
|
||||
delete filter.order;
|
||||
|
||||
let order = 'ORDER BY warehouseFk = ' + worker.warehouseFk + ' DESC';
|
||||
|
||||
if (!filter.where) {
|
||||
stmt.merge(order);
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
} else {
|
||||
let limit = filter.limit;
|
||||
delete filter.limit;
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
stmt.merge(order);
|
||||
stmt.merge(conn.makeLimit({limit}));
|
||||
}
|
||||
|
||||
const result = await conn.executeStmt(stmt);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return result;
|
||||
} else {
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
|
||||
const result = await conn.executeStmt(stmt);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return result;
|
||||
}
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
<div>{{name}} - {{nickname}}</div>
|
||||
</tpl-item>
|
||||
</vn-autocomplete>
|
||||
{{$ctrl.route.vehicleFk}}
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
ng-model="$ctrl.route.vehicleFk"
|
||||
|
|
Loading…
Reference in New Issue