3570-feat(setQuantitySale): back route and test #869
|
@ -0,0 +1,34 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('setSaleQuantity', {
|
||||
description: 'Update sale quantity',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'saleId',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The sale id'
|
||||
},
|
||||
{
|
||||
arg: 'quantity',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The quantity to picked'
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/setSaleQuantity`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.setSaleQuantity = async ctx => {
|
||||
const args = ctx.args;
|
||||
const models = Self.app.models;
|
||||
|
||||
const sale = await models.Sale.findById(args.saleId,);
|
||||
return await sale.updateAttribute('quantity', args.quantity);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,23 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('setSaleQuantity()', () => {
|
||||
it('should change quantity sale', async() => {
|
||||
const saleId = 30;
|
||||
const newQuantity = 10;
|
||||
|
||||
const ctx = {
|
||||
args: {
|
||||
saleId: saleId,
|
||||
quantity: newQuantity
|
||||
}
|
||||
};
|
||||
|
||||
const originalSale = await models.Sale.findById(saleId);
|
||||
|
||||
await models.Collection.setSaleQuantity(ctx);
|
||||
const updateSale = await models.Sale.findById(saleId);
|
||||
|
||||
expect(updateSale.quantity).toBeLessThan(originalSale.quantity);
|
||||
expect(updateSale.quantity).toEqual(newQuantity);
|
||||
});
|
||||
});
|
|
@ -1,62 +0,0 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('updateCollectionSale()', () => {
|
||||
it('should return a new collection', async() => {
|
||||
const sectorOneWarehouseID = 1;
|
||||
let ctx = {req: {accessToken: {userId: 1106}}};
|
||||
ctx.args = {
|
||||
sale: 1,
|
||||
originalQuantity: 5,
|
||||
quantity: 5,
|
||||
quantityPicked: 5,
|
||||
ticketFk: 1,
|
||||
stateFk: 4,
|
||||
isNicho: false,
|
||||
shelvingFk: 'UXN',
|
||||
itemFk: 1,
|
||||
sectorFk: 1
|
||||
};
|
||||
let originalSaleTracking = await app.models.SaleTracking.findOne({
|
||||
where: {
|
||||
saleFk: ctx.args.sale,
|
||||
stateFk: ctx.args.stateFk
|
||||
}
|
||||
});
|
||||
let itemPlacement = await app.models.ItemPlacement.findOne({
|
||||
where: {
|
||||
itemFk: ctx.args.itemFk,
|
||||
warehouseFk: sectorOneWarehouseID
|
||||
}
|
||||
});
|
||||
const originalSale = await app.models.Sale.findById(ctx.args.sale);
|
||||
const originalItemShelving = await app.models.ItemShelving.findOne({where: {shelvingFk: ctx.args.shelvingFk, itemFk: ctx.args.itemFk}});
|
||||
const originalTicketLastState = await app.models.TicketLastState.findById(ctx.args.ticketFk);
|
||||
|
||||
let response = await app.models.Collection.updateCollectionSale(ctx);
|
||||
|
||||
expect(response.length).toBeGreaterThan(0);
|
||||
expect(response[0][0].id).toEqual(1);
|
||||
expect(response[0][0].quantity).toEqual(5);
|
||||
|
||||
// restores
|
||||
if (originalSaleTracking)
|
||||
await originalSaleTracking.save();
|
||||
else {
|
||||
originalSaleTracking = await app.models.SaleTracking.findOne({
|
||||
where: {
|
||||
saleFk: ctx.args.sale,
|
||||
stateFk: ctx.args.stateFk
|
||||
}
|
||||
});
|
||||
await originalSaleTracking.destroy();
|
||||
}
|
||||
await originalSale.save();
|
||||
const itemShelvingsToDestroy = await app.models.ItemShelving.find({where: {shelvingFk: ctx.args.shelvingFk, itemFk: ctx.args.itemFk}});
|
||||
for (itemShelving of itemShelvingsToDestroy)
|
||||
await itemShelving.destroy();
|
||||
|
||||
await originalItemShelving.save();
|
||||
await originalTicketLastState.save();
|
||||
await itemPlacement.save();
|
||||
});
|
||||
});
|
|
@ -1,90 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('updateCollectionSale', {
|
||||
description: 'Update sale of a collection',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'sale',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The sale id'
|
||||
}, {
|
||||
arg: 'originalQuantity',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The quantity to sale'
|
||||
},
|
||||
{
|
||||
arg: 'quantity',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The quantity to picked'
|
||||
},
|
||||
{
|
||||
arg: 'quantityPicked',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The quantity to picked'
|
||||
}, {
|
||||
arg: 'ticketFk',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The ticket id'
|
||||
}, {
|
||||
arg: 'stateFk',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The state id'
|
||||
}, {
|
||||
arg: 'isNicho',
|
||||
type: 'Boolean',
|
||||
required: true,
|
||||
description: 'Determine if sale is picked from nicho or not'
|
||||
}, {
|
||||
arg: 'shelvingFk',
|
||||
type: 'String',
|
||||
required: false,
|
||||
description: 'The shelving id'
|
||||
}, {
|
||||
arg: 'itemFk',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The item id'
|
||||
}, {
|
||||
arg: 'sectorFk',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The sector id'
|
||||
}],
|
||||
returns: {
|
||||
type: 'Object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/updateCollectionSale`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateCollectionSale = async ctx => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const args = ctx.args;
|
||||
|
||||
if (args.originalQuantity == args.quantity) {
|
||||
query = `CALL vn.collection_updateSale(?,?,?,?,?)`;
|
||||
await Self.rawSql(query, [args.sale, args.originalQuantity, userId, args.stateFk, args.ticketFk]);
|
||||
}
|
||||
|
||||
if (!args.isNicho) {
|
||||
query = `CALL vn.collection_faults(?,?,?)`;
|
||||
await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, args.itemFk]);
|
||||
} else {
|
||||
query = `CALL vn.sector_getWarehouse(?)`;
|
||||
const [result] = await Self.rawSql(query, [args.sectorFk]);
|
||||
|
||||
query = `CALL vn.itemPlacementSave(?,?,?)`;
|
||||
await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, result[0]['warehouseFk']]);
|
||||
}
|
||||
query = `CALL vn.sale_updateOriginalQuantity(?,?)`;
|
||||
return await Self.rawSql(query, [args.sale, args.quantity]);
|
||||
};
|
||||
};
|
|
@ -2,6 +2,6 @@ module.exports = Self => {
|
|||
require('../methods/collection/getCollection')(Self);
|
||||
require('../methods/collection/newCollection')(Self);
|
||||
require('../methods/collection/getSectors')(Self);
|
||||
require('../methods/collection/updateCollectionSale')(Self);
|
||||
require('../methods/collection/setSaleQuantity')(Self);
|
||||
require('../methods/collection/collectionFaults')(Self);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
INSERT INTO salix.ACL
|
||||
(model, property, accessType, permission, principalType, principalId)
|
||||
VALUES('Collection', 'setSaleQuantity', '*', 'ALLOW', 'ROLE', 'employee');
|
|
@ -120,5 +120,6 @@
|
|||
"This item is not available": "This item is not available",
|
||||
"Deny buy request": "Purchase request for ticket id [{{ticketId}}]({{{url}}}) has been rejected. Reason: {{observation}}",
|
||||
"The type of business must be filled in basic data": "The type of business must be filled in basic data",
|
||||
"The worker has hours recorded that day": "The worker has hours recorded that day"
|
||||
"The worker has hours recorded that day": "The worker has hours recorded that day",
|
||||
"isWithoutNegatives": "isWithoutNegatives"
|
||||
}
|
Loading…
Reference in New Issue