salix/modules/zone/back/methods/agency/getLanded.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-05-30 06:41:08 +00:00
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
2019-01-25 10:58:50 +00:00
module.exports = Self => {
2020-09-23 09:21:25 +00:00
Self.remoteMethodCtx('getLanded', {
2019-01-25 10:58:50 +00:00
description: 'Returns the first shipped and landed possible for params',
accessType: 'READ',
accepts: [{
2019-05-30 06:41:08 +00:00
arg: 'shipped',
type: 'date',
required: true
},
{
arg: 'addressFk',
type: 'number',
required: true
},
{
arg: 'agencyModeFk',
type: 'number',
required: true
},
{
arg: 'warehouseFk',
type: 'number',
required: true
2019-01-25 10:58:50 +00:00
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/getLanded`,
verb: 'get'
}
});
2020-09-23 09:21:25 +00:00
Self.getLanded = async(ctx, shipped, addressFk, agencyModeFk, warehouseFk) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
let showExpired = false;
if (isProductionBoss) showExpired = true;
2019-05-30 06:41:08 +00:00
let stmts = [];
stmts.push(new ParameterizedSQL(
2020-06-05 08:01:21 +00:00
`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
shipped,
addressFk,
agencyModeFk,
2020-06-05 08:01:21 +00:00
warehouseFk,
2020-09-23 09:21:25 +00:00
showExpired
2019-05-30 06:41:08 +00:00
]
));
let rsIndex = stmts.push(
`SELECT * FROM tmp.zoneGetLanded`) - 1;
stmts.push(`DROP TEMPORARY TABLE tmp.zoneGetLanded`);
2019-05-30 06:41:08 +00:00
let sql = ParameterizedSQL.join(stmts, ';');
let landed = await Self.rawStmt(sql);
2019-01-25 10:58:50 +00:00
2019-05-30 06:41:08 +00:00
return landed[rsIndex][0];
2019-01-25 10:58:50 +00:00
};
};