master to test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-05-11 08:00:49 +02:00
parent 9ab850b34d
commit 7704256079
6 changed files with 18 additions and 10 deletions

View File

@ -124,6 +124,7 @@ module.exports = Self => {
const isDeliveryBoss = await models.VnUser.hasRole(userId, 'deliveryBoss', myOptions);
if (!isDeliveryBoss) {
const zoneShipped = await models.Agency.getShipped(
ctx,
args.landed,
args.addressFk,
args.agencyModeFk,

View File

@ -100,7 +100,7 @@ module.exports = Self => {
}
if (!args.shipped && args.landed) {
const shippedResult = await models.Agency.getShipped(args.landed,
const shippedResult = await models.Agency.getShipped(ctx, args.landed,
address.id, args.agencyModeId, args.warehouseId, myOptions);
args.shipped = (shippedResult && shippedResult.shipped) || args.landed;
}

View File

@ -81,6 +81,7 @@ module.exports = Self => {
const isDeliveryBoss = await models.VnUser.hasRole(userId, 'deliveryBoss', myOptions);
if (!isDeliveryBoss) {
const zoneShipped = await models.Agency.getShipped(
ctx,
args.landed,
args.addressId,
args.agencyModeId,

View File

@ -1,7 +1,7 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('getShipped', {
Self.remoteMethodCtx('getShipped', {
description: 'Returns the first shipped possible for params',
accessType: 'READ',
accepts: [{
@ -34,18 +34,22 @@ module.exports = Self => {
}
});
Self.getShipped = async(landed, addressFk, agencyModeFk, warehouseFk, options) => {
Self.getShipped = async(ctx, landed, addressFk, agencyModeFk, warehouseFk, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const stmts = [];
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const isProductionAssistant = await models.VnUser.hasRole(userId, 'productionAssi', myOptions);
stmts.push(new ParameterizedSQL(
`CALL vn.zone_getShipped(?, ?, ?, TRUE)`, [
`CALL vn.zone_getShipped(?, ?, ?, ?)`, [
landed,
addressFk,
agencyModeFk
agencyModeFk,
isProductionAssistant
]
));

View File

@ -1,6 +1,9 @@
const {models} = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('agency getShipped()', () => {
const employeeId = 1;
const ctx = {req: {accessToken: {userId: employeeId}}};
it('should return a shipment date', async() => {
const landed = Date.vnNew();
landed.setDate(landed.getDate() + 1);
@ -12,8 +15,7 @@ describe('agency getShipped()', () => {
try {
const options = {transaction: tx};
const result = await models.Agency.getShipped(landed, addressFk, agencyModeFk, warehouseFk, options);
const result = await models.Agency.getShipped(ctx, landed, addressFk, agencyModeFk, warehouseFk, options);
expect(result).toBeDefined();
@ -37,7 +39,7 @@ describe('agency getShipped()', () => {
try {
const options = {transaction: tx};
const result = await models.Agency.getShipped(landed, addressFk, agencyModeFk, warehouseFk, options);
const result = await models.Agency.getShipped(ctx, landed, addressFk, agencyModeFk, warehouseFk, options);
expect(result).toBeUndefined();