refs #5066 @3h fix back route so that the e2e does not fail
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Pau 2023-01-31 11:54:19 +01:00
parent a378831149
commit e54afb2321
2 changed files with 45 additions and 7 deletions

View File

@ -1,7 +1,14 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('currentWarehouse', { Self.remoteMethodCtx('currentWarehouse', {
description: 'Get the vehicles with the ones on the current warehouse first', description: 'Get the vehicles with the ones on the current warehouse first',
accessType: 'READ', accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'object',
description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string`
}],
returns: { returns: {
type: 'array', type: 'array',
root: true 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 models = Self.app.models;
const conn = Self.dataSource.connector;
const myOptions = {}; const myOptions = {};
let tx; let tx;
@ -34,15 +42,44 @@ module.exports = Self => {
if (!worker) throw new Error('User not found'); if (!worker) throw new Error('User not found');
const query = /* const query =
`SELECT v.id, v.numberPlate, v.warehouseFk `SELECT v.id, v.numberPlate, v.warehouseFk
FROM vehicle v 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(); if (filter.order) {
return result; 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) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;

View File

@ -21,6 +21,7 @@
<div>{{name}} - {{nickname}}</div> <div>{{name}} - {{nickname}}</div>
</tpl-item> </tpl-item>
</vn-autocomplete> </vn-autocomplete>
{{$ctrl.route.vehicleFk}}
<vn-autocomplete <vn-autocomplete
vn-one vn-one
ng-model="$ctrl.route.vehicleFk" ng-model="$ctrl.route.vehicleFk"