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

68 lines
1.8 KiB
JavaScript

const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethodCtx('getLanded', {
description: 'Returns the first shipped and landed possible for params',
accessType: 'READ',
accepts: [{
arg: 'shipped',
type: 'date',
required: true
},
{
arg: 'addressFk',
type: 'number',
required: true
},
{
arg: 'agencyModeFk',
type: 'number',
required: true
},
{
arg: 'warehouseFk',
type: 'number',
required: true
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/getLanded`,
verb: 'get'
}
});
Self.getLanded = async(ctx, shipped, addressFk, agencyModeFk, warehouseFk) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const roles = await models.Account.getRoles(userId);
const canSeeExpired = roles.filter(role =>
role == 'productionBoss' || role == 'administrative'
);
let showExpired = false;
if (canSeeExpired.length) showExpired = true;
let stmts = [];
stmts.push(new ParameterizedSQL(
`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
shipped,
addressFk,
agencyModeFk,
warehouseFk,
showExpired
]
));
let rsIndex = stmts.push(
`SELECT * FROM tmp.zoneGetLanded`) - 1;
stmts.push(`DROP TEMPORARY TABLE tmp.zoneGetLanded`);
let sql = ParameterizedSQL.join(stmts, ';');
let landed = await Self.rawStmt(sql);
return landed[rsIndex][0];
};
};