From 7d6a33d79a525a38935db22f1c32bfdc87a1f27d Mon Sep 17 00:00:00 2001 From: Ainki Date: Thu, 26 Mar 2020 13:12:59 +0100 Subject: [PATCH] change some names an methods --- back/methods/collection/collectionFaults.js | 4 +- .../collection/collectionUpdateSale.js | 42 --------- .../{collectionGet.js => getCollection.js} | 10 +-- back/methods/collection/getSectors.js | 4 +- .../{collectionNew.js => newCollection.js} | 10 ++- .../collection/updateCollectionSale.js | 89 +++++++++++++++++++ back/models/collection.js | 6 +- 7 files changed, 108 insertions(+), 57 deletions(-) delete mode 100644 back/methods/collection/collectionUpdateSale.js rename back/methods/collection/{collectionGet.js => getCollection.js} (69%) rename back/methods/collection/{collectionNew.js => newCollection.js} (93%) create mode 100644 back/methods/collection/updateCollectionSale.js diff --git a/back/methods/collection/collectionFaults.js b/back/methods/collection/collectionFaults.js index ac5186575..395c7e581 100644 --- a/back/methods/collection/collectionFaults.js +++ b/back/methods/collection/collectionFaults.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethodCtx('collectionFaults', { + Self.remoteMethod('collectionFaults', { description: 'Update sale of a collection', accessType: 'WRITE', accepts: [{ @@ -28,7 +28,7 @@ module.exports = Self => { } }); - Self.collectionFaults = async(ctx, shelvingFk, quantity, itemFk) => { + Self.collectionFaults = async(shelvingFk, quantity, itemFk) => { query = `CALL vn.collection_faults(?,?,?)`; return await Self.rawSql(query, [shelvingFk, quantity, itemFk]); }; diff --git a/back/methods/collection/collectionUpdateSale.js b/back/methods/collection/collectionUpdateSale.js deleted file mode 100644 index 7204dad22..000000000 --- a/back/methods/collection/collectionUpdateSale.js +++ /dev/null @@ -1,42 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('collectionUpdateSale', { - 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: 'ticketFk', - type: 'Number', - required: true, - description: 'The ticket id' - }, { - arg: 'stateFk', - type: 'Number', - required: true, - description: 'The state id' - }], - returns: { - type: 'Object', - root: true - }, - http: { - path: `/collectionUpdateSale`, - verb: 'POST' - } - }); - - Self.collectionUpdateSale = async(ctx, sale, originalQuantity, ticketFk, stateFk) => { - const userId = ctx.req.accessToken.userId; - - query = `CALL vn.collection_updateSale(?,?,?,?,?)`; - return await Self.rawSql(query, [sale, originalQuantity, userId, stateFk, ticketFk]); - }; -}; diff --git a/back/methods/collection/collectionGet.js b/back/methods/collection/getCollection.js similarity index 69% rename from back/methods/collection/collectionGet.js rename to back/methods/collection/getCollection.js index ff98c55d5..caf9cc521 100644 --- a/back/methods/collection/collectionGet.js +++ b/back/methods/collection/getCollection.js @@ -1,18 +1,18 @@ module.exports = Self => { - Self.remoteMethodCtx('collectionGet', { + Self.remoteMethodCtx('getCollection', { description: 'Get pending collections from a worker', - accessType: 'WRITE', + accessType: 'READ', returns: { type: 'Object', root: true }, http: { - path: `/collectionGet`, - verb: 'POST' + path: `/getCollection`, + verb: 'GET' } }); - Self.collectionGet = async ctx => { + Self.getCollection = async ctx => { const userId = ctx.req.accessToken.userId; const query = `CALL vn.collection_get(?)`; const [result] = await Self.rawSql(query, [userId]); diff --git a/back/methods/collection/getSectors.js b/back/methods/collection/getSectors.js index c5da7ec13..d844e5097 100644 --- a/back/methods/collection/getSectors.js +++ b/back/methods/collection/getSectors.js @@ -1,14 +1,14 @@ module.exports = Self => { Self.remoteMethodCtx('getSectors', { description: 'Get all sectors', - accessType: 'WRITE', + accessType: 'READ', returns: { type: 'Object', root: true }, http: { path: `/getSectors`, - verb: 'POST' + verb: 'GET' } }); diff --git a/back/methods/collection/collectionNew.js b/back/methods/collection/newCollection.js similarity index 93% rename from back/methods/collection/collectionNew.js rename to back/methods/collection/newCollection.js index d22a0b7fe..31e419b67 100644 --- a/back/methods/collection/collectionNew.js +++ b/back/methods/collection/newCollection.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethodCtx('collectionNew', { + Self.remoteMethodCtx('newCollection', { description: 'Make a new collection of tickets', accessType: 'WRITE', accepts: [{ @@ -23,12 +23,12 @@ module.exports = Self => { root: true }, http: { - path: `/collectionNew`, + path: `/newCollection`, verb: 'POST' } }); - Self.collectionNew = async(ctx, collectionFk, sectorFk, vWagons) => { + Self.newCollection = async(ctx, collectionFk, sectorFk, vWagons) => { let query = ''; if (!collectionFk) { @@ -85,6 +85,10 @@ module.exports = Self => { sale['saleFk'] = sales[x]['saleFk']; sale['itemFk'] = sales[x]['itemFk']; sale['quantity'] = sales[x]['quantity']; + if (sales[x]['quantityPicked'] != null) + sale['quantityPicked'] = sales[x]['quantityPicked']; + else + sale['quantityPicked'] = 0; sale['longName'] = sales[x]['longName']; sale['size'] = sales[x]['size']; sale['color'] = sales[x]['color']; diff --git a/back/methods/collection/updateCollectionSale.js b/back/methods/collection/updateCollectionSale.js new file mode 100644 index 000000000..01575c972 --- /dev/null +++ b/back/methods/collection/updateCollectionSale.js @@ -0,0 +1,89 @@ +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, sale, originalQuantity, quantity, quantityPicked, ticketFk, stateFk, isNicho, shelvingFk, itemFk, sectorFk) => { + const userId = ctx.req.accessToken.userId; + + if (originalQuantity == quantity) { + query = `CALL vn.collection_updateSale(?,?,?,?,?)`; + await Self.rawSql(query, [sale, originalQuantity, userId, stateFk, ticketFk]); + } + + if (!isNicho) { + query = `CALL vn.collection_faults(?,?,?)`; + await Self.rawSql(query, [shelvingFk, quantityPicked, itemFk]); + } else { + query = `CALL vn.sector_getWarehouse(?)`; + const [result] = await Self.rawSql(query, [sectorFk]); + + query = `CALL vn.itemPlacementSave(?,?,?)`; + await Self.rawSql(query, [shelvingFk, quantityPicked, result[0]['warehouseFk']]); + } + query = `CALL vn.sale_updateOriginalQuantity(?,?)`; + return await Self.rawSql(query, [sale, quantity]); + }; +}; diff --git a/back/models/collection.js b/back/models/collection.js index aad0b4196..d3670d56b 100644 --- a/back/models/collection.js +++ b/back/models/collection.js @@ -1,7 +1,7 @@ module.exports = Self => { - require('../methods/collection/collectionGet')(Self); - require('../methods/collection/collectionNew')(Self); + require('../methods/collection/getCollection')(Self); + require('../methods/collection/newCollection')(Self); require('../methods/collection/getSectors')(Self); - require('../methods/collection/collectionUpdateSale')(Self); + require('../methods/collection/updateCollectionSale')(Self); require('../methods/collection/collectionFaults')(Self); };