2449 - Ticket basic show only available zones on autocomplete #382

Merged
joan merged 7 commits from 2449-ticket_basicData into dev 2020-09-23 13:14:17 +00:00
4 changed files with 70 additions and 3 deletions
Showing only changes of commit ae3d00bad1 - Show all commits

View File

@ -70,7 +70,7 @@
</vn-autocomplete>
<vn-autocomplete
vn-one
url="Zones"
url="Zones/includingExpired"
label="Zone"
show-field="name"
value-field="id"

View File

@ -245,8 +245,14 @@ class Controller extends Component {
}
zoneWhere() {
if (this.agencyModeId)
return {agencyModeFk: this.agencyModeId};
if (this.ticket.agencyModeFk) {
return {
shipped: this.ticket.shipped,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk
};
}
return {};
}
}

View File

@ -0,0 +1,60 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethod('includingExpired', {
description: 'Returns a list of agencies from a warehouse',
accepts: [{
arg: 'filter',
type: 'Object',
description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string`
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/includingExpired`,
verb: 'GET'
}
});
Self.includingExpired = async filter => {
const conn = Self.dataSource.connector;
const where = filter.where;
// filter = mergeFilters(filter, {where});
const stmts = [];
let stmt;
console.log(where);
if (where.agencyModeFk) {
stmt = new ParameterizedSQL(`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
where.shipped,
where.addressFk,
where.agencyModeFk,
where.warehouseFk,
true]);
stmts.push(stmt);
}
stmt = new ParameterizedSQL(
`SELECT id, name, agencyModeFk
FROM vn.zone z`);
if (where.agencyModeFk)
stmt.merge(`JOIN tmp.zoneGetLanded zgl ON zgl.zoneFk = z.id`);
stmt.merge(conn.makePagination(filter));
let index;
if (stmts.length)
index = stmts.push(stmt) - 1;
else stmts.push(stmt);
const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql);
return index ? result[index] : result;
};
};

View File

@ -5,6 +5,7 @@ module.exports = Self => {
require('../methods/zone/toggleIsIncluded')(Self);
require('../methods/zone/getUpcomingDeliveries')(Self);
require('../methods/zone/deleteZone')(Self);
require('../methods/zone/includingExpired')(Self);
Self.validatesPresenceOf('agencyModeFk', {
message: `Agency cannot be blank`