From 854a9b62af94160de9933c74e7d21a54407aa6cf Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 4 Mar 2024 09:21:41 +0100 Subject: [PATCH] fix: refs #6276 refactor updateInTime & changes --- back/methods/machine-worker/updateInTime.js | 10 +++++----- modules/item/back/methods/item-barcode/delete.js | 2 +- .../item/back/methods/item-shelving/getAlternative.js | 4 ++-- .../methods/item-shelving/specs/getAlternative.spec.js | 2 +- modules/ticket/back/methods/sale-tracking/setPicked.js | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/back/methods/machine-worker/updateInTime.js b/back/methods/machine-worker/updateInTime.js index cfeda4425..8f663302d 100644 --- a/back/methods/machine-worker/updateInTime.js +++ b/back/methods/machine-worker/updateInTime.js @@ -47,9 +47,10 @@ module.exports = Self => { } }, myOptions); + const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions); + const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000); + if (machineWorker) { - const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions); - const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000); const isHimself = userId == machineWorker.workerFk; const isSameMachine = machine.id == machineWorker.machineFk; @@ -62,10 +63,9 @@ module.exports = Self => { await machineWorker.updateAttributes({ outTime: Date.vnNew() }, myOptions); + } - if (hoursDifference >= maxHours) - await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions); - } else + if (!machineWorker || hoursDifference >= maxHours) await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions); if (tx) await tx.commit(); diff --git a/modules/item/back/methods/item-barcode/delete.js b/modules/item/back/methods/item-barcode/delete.js index b27782b1b..0eea651d3 100644 --- a/modules/item/back/methods/item-barcode/delete.js +++ b/modules/item/back/methods/item-barcode/delete.js @@ -1,7 +1,7 @@ module.exports = Self => { Self.remoteMethod('delete', { description: 'Delete an ItemBarcode by itemFk and code', - accessType: 'READ', + accessType: 'WRITE', accepts: [ { arg: 'barcode', diff --git a/modules/item/back/methods/item-shelving/getAlternative.js b/modules/item/back/methods/item-shelving/getAlternative.js index dd497d580..8108bfa6e 100644 --- a/modules/item/back/methods/item-shelving/getAlternative.js +++ b/modules/item/back/methods/item-shelving/getAlternative.js @@ -47,7 +47,7 @@ module.exports = Self => { return itemShelvings.map(itemShelving => { const item = itemShelving.item(); - const carros = alternatives.filter(alternative => alternative.itemFk == itemShelving.itemFk); + const shelvings = alternatives.filter(alternative => alternative.itemFk == itemShelving.itemFk); return { id: itemShelving.id, @@ -56,7 +56,7 @@ module.exports = Self => { size: item.size, longName: item.longName, quantity: itemShelving.visible, - carros + shelvings }; }); } diff --git a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js index 8c8d8a33d..3f4917477 100644 --- a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js +++ b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js @@ -13,7 +13,7 @@ describe('itemShelving getAlternative()', () => { const shelvingFk = 'HEJ'; const itemShelvings = await models.ItemShelving.getAlternative(shelvingFk); - expect(itemShelvings[0].carros.length).toEqual(0); + expect(itemShelvings[0].shelvings.length).toEqual(0); }); it('should return an empty list', async() => { diff --git a/modules/ticket/back/methods/sale-tracking/setPicked.js b/modules/ticket/back/methods/sale-tracking/setPicked.js index 990768197..828f6eb7e 100644 --- a/modules/ticket/back/methods/sale-tracking/setPicked.js +++ b/modules/ticket/back/methods/sale-tracking/setPicked.js @@ -73,7 +73,7 @@ module.exports = Self => { userFk: userId }, myOptions); - const itemShelving = await models.ItemShelving.findById(itemShelvingFk, myOptions); + const itemShelving = await models.ItemShelving.findById(itemShelvingFk, null, myOptions); await itemShelving.updateAttributes({visible: itemShelving.visible - quantity}, myOptions); @@ -86,8 +86,8 @@ module.exports = Self => { await Self.updateTracking(ctx, saleFk, originalQuantity, code, isChecked, null, isScanned, myOptions); try { - const buy = await models.Buy.findById(buyFk, myOptions); - if (buy.itemOriginalFk) await models.SaleBuy.create({saleFk, buyFk}, myOptions); + const {itemOriginalFk} = await models.Buy.findById(buyFk, {fields: ['itemOriginalFk']}, myOptions); + if (itemOriginalFk) await models.SaleBuy.create({saleFk, buyFk}, myOptions); } catch (e) { throw new UserError('The sale cannot be tracked'); }