feat(collection): setQuantitySale
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e958453831
commit
dc78cd2dc5
|
@ -3,19 +3,19 @@ module.exports = Self => {
|
|||
description: 'Update sale quantity',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'sale',
|
||||
type: 'Number',
|
||||
arg: 'saleId',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The sale id'
|
||||
},
|
||||
{
|
||||
arg: 'quantity',
|
||||
type: 'Number',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The quantity to picked'
|
||||
}],
|
||||
returns: {
|
||||
type: 'Object',
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
|
@ -24,8 +24,11 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.setQuantitySale = async(sale, quantity, options) => {
|
||||
Self.setQuantitySale = async(ctx, options) => {
|
||||
const args = ctx.args;
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
|
@ -37,8 +40,9 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
query = `CALL vn.sale_setQuantity(?,?)`;
|
||||
const result = await Self.rawSql(query, [sale, quantity]);
|
||||
const sale = await models.Sale.findById(args.saleId, null, myOptions);
|
||||
|
||||
const result = await sale.updateAttribute('quantity', args.quantity, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('setQuantitySale()', () => {
|
||||
fdescribe('setQuantitySale()', () => {
|
||||
it('should change quantity sale', async() => {
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
const saleId = 30;
|
||||
const newQuantity = 10;
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const saleId = 30;
|
||||
const newQuantity = 5;
|
||||
const originalSale = await models.Sale.findById(saleId);
|
||||
const ctx = {
|
||||
args: {
|
||||
saleId: saleId,
|
||||
quantity: newQuantity
|
||||
}
|
||||
};
|
||||
|
||||
await models.Collection.setQuantitySale(saleId, newQuantity, options);
|
||||
const updateSale = await models.Sale.findById(saleId);
|
||||
const originalSale = await models.Sale.findById(30, null, options);
|
||||
|
||||
await models.Collection.setQuantitySale(ctx, options);
|
||||
const updateSale = await models.Sale.findById(30, null, options);
|
||||
|
||||
expect(updateSale.quantity).toBeLessThan(originalSale.quantity);
|
||||
expect(updateSale.quantity).toEqual(newQuantity);
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
INSERT INTO salix.ACL
|
||||
(model, property, accessType, permission, principalType, principalId)
|
||||
VALUES('Collection', 'setQuantitySale', '*', 'ALLOW', 'ROLE', 'employee');
|
Loading…
Reference in New Issue