232001_test_to_dev #1535

Merged
alexm merged 7 commits from 232001_test_to_dev into dev 2023-05-18 05:31:40 +00:00
6 changed files with 18 additions and 10 deletions
Showing only changes of commit 7704256079 - Show all commits

View File

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

View File

@ -100,7 +100,7 @@ module.exports = Self => {
} }
if (!args.shipped && args.landed) { 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); address.id, args.agencyModeId, args.warehouseId, myOptions);
args.shipped = (shippedResult && shippedResult.shipped) || args.landed; 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); const isDeliveryBoss = await models.VnUser.hasRole(userId, 'deliveryBoss', myOptions);
if (!isDeliveryBoss) { if (!isDeliveryBoss) {
const zoneShipped = await models.Agency.getShipped( const zoneShipped = await models.Agency.getShipped(
ctx,
args.landed, args.landed,
args.addressId, args.addressId,
args.agencyModeId, args.agencyModeId,

View File

@ -1,7 +1,7 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('getShipped', { Self.remoteMethodCtx('getShipped', {
description: 'Returns the first shipped possible for params', description: 'Returns the first shipped possible for params',
accessType: 'READ', accessType: 'READ',
accepts: [{ 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 = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const stmts = []; 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( stmts.push(new ParameterizedSQL(
`CALL vn.zone_getShipped(?, ?, ?, TRUE)`, [ `CALL vn.zone_getShipped(?, ?, ?, ?)`, [
landed, landed,
addressFk, 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()', () => { describe('agency getShipped()', () => {
const employeeId = 1;
const ctx = {req: {accessToken: {userId: employeeId}}};
it('should return a shipment date', async() => { it('should return a shipment date', async() => {
const landed = Date.vnNew(); const landed = Date.vnNew();
landed.setDate(landed.getDate() + 1); landed.setDate(landed.getDate() + 1);
@ -12,8 +15,7 @@ describe('agency getShipped()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await models.Agency.getShipped(ctx, landed, addressFk, agencyModeFk, warehouseFk, options);
const result = await models.Agency.getShipped(landed, addressFk, agencyModeFk, warehouseFk, options);
expect(result).toBeDefined(); expect(result).toBeDefined();
@ -37,7 +39,7 @@ describe('agency getShipped()', () => {
try { try {
const options = {transaction: tx}; 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(); expect(result).toBeUndefined();