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

73 lines
2.0 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'
}
});
Self.getLanded = async(ctx, shipped, addressFk, agencyModeFk, warehouseFk, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
2020-09-23 09:21:25 +00:00
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const roles = await models.VnUser.getRoles(userId);
2020-10-20 08:19:12 +00:00
const canSeeExpired = roles.filter(role =>
role == 'productionBoss' || role == 'administrative'
);
2020-09-23 09:21:25 +00:00
let showExpired = false;
2020-10-20 08:19:12 +00:00
if (canSeeExpired.length) showExpired = true;
2020-09-23 09:21:25 +00:00
const stmts = [];
2019-05-30 06:41:08 +00:00
stmts.push(new ParameterizedSQL(
'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
));
const rsIndex = stmts.push('SELECT * FROM tmp.zoneGetLanded') - 1;
stmts.push('DROP TEMPORARY TABLE tmp.zoneGetLanded');
2019-05-30 06:41:08 +00:00
const sql = ParameterizedSQL.join(stmts, ';');
const landed = await Self.rawStmt(sql, myOptions);
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
};
};