From 7fdd3d1eb826ef1e91fa48942d63dd2ef00066a3 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 31 Jan 2025 01:07:28 +0100 Subject: [PATCH] feat: refs #6321 fix methods --- modules/item/back/methods/item/getSimilar.js | 78 +------------------ .../ticket/back/methods/sale/replaceItem.js | 78 ++++++++++++------- .../back/methods/ticket/itemLackDetail.js | 2 +- .../methods/ticket/specs/itemLack.spec.js | 2 +- modules/ticket/back/methods/ticket/split.js | 7 +- .../back/methods/ticket/transferSales.js | 3 +- 6 files changed, 60 insertions(+), 110 deletions(-) diff --git a/modules/item/back/methods/item/getSimilar.js b/modules/item/back/methods/item/getSimilar.js index d58a19404..bb1b62939 100644 --- a/modules/item/back/methods/item/getSimilar.js +++ b/modules/item/back/methods/item/getSimilar.js @@ -26,10 +26,7 @@ module.exports = Self => { Object.assign(myOptions, options); const {where} = filter; - const today = - new Date().toLocaleDateString('en-US', {year: 'numeric', - month: '2-digit', - day: '2-digit'}); + const query = [ filter.itemFk, where.warehouseFk, @@ -38,78 +35,7 @@ module.exports = Self => { where.scopeDays ?? 2 ]; const [results] = await Self.rawSql('CALL vn.item_getSimilar(?, ?, ?, ?, ?)', query, myOptions); - // return results - return [ - { - 'id': 1, - 'longName': 'Ranged weapon longbow 50cm', - 'subName': 'Stark Industries', - 'tag5': 'Color', - 'value5': 'Brown', - 'match5': 0, - 'match6': 0, - 'match7': 0, - 'match8': 1, - 'tag6': 'Categoria', - 'value6': '+1 precission', - 'tag7': 'Tallos', - 'value7': '1', - 'tag8': null, - 'value8': null, - 'available': 20, - 'calc_id': 6, - 'counter': 0, - 'minQuantity': 1, - 'visible': null, - 'price2': 1 - }, - { - 'id': 2, - 'longName': 'Ranged weapon longbow 100cm', - 'subName': 'Stark Industries', - 'tag5': 'Color', - 'value5': 'Brown', - 'match5': 0, - 'match6': 1, - 'match7': 0, - 'match8': 1, - 'tag6': 'Categoria', - 'value6': '+1 precission', - 'tag7': 'Tallos', - 'value7': '1', - 'tag8': null, - 'value8': null, - 'available': 50, - 'calc_id': 6, - 'counter': 1, - 'minQuantity': 5, - 'visible': null, - 'price2': 10 - }, - { - 'id': 3, - 'longName': 'Ranged weapon longbow 200cm', - 'subName': 'Stark Industries', - 'tag5': 'Color', - 'value5': 'Brown', - 'match5': 1, - 'match6': 1, - 'match7': 1, - 'match8': 1, - 'tag6': 'Categoria', - 'value6': '+1 precission', - 'tag7': 'Tallos', - 'value7': '1', - 'tag8': null, - 'value8': null, - 'available': 185, - 'calc_id': 6, - 'counter': 10, - 'minQuantity': 10, - 'visible': null, - 'price2': 100 - } - ]; + return results; }; }; diff --git a/modules/ticket/back/methods/sale/replaceItem.js b/modules/ticket/back/methods/sale/replaceItem.js index 9c974b057..5bc5c2c48 100644 --- a/modules/ticket/back/methods/sale/replaceItem.js +++ b/modules/ticket/back/methods/sale/replaceItem.js @@ -3,21 +3,22 @@ module.exports = Self => { Self.remoteMethodCtx('replaceItem', { description: 'Replace item from sale', accessType: 'WRITE', - accepts: [{ - arg: 'saleFk', - type: 'number', - required: true, - }, - { - arg: 'substitutionFk', - type: 'number', - required: true - }, - { - arg: 'quantity', - type: 'number', - required: true - } + accepts: [ + { + arg: 'saleFk', + type: 'number', + required: true, + }, + { + arg: 'substitutionFk', + type: 'number', + required: true + }, + { + arg: 'quantity', + type: 'number', + required: true + } ], returns: { type: 'object', @@ -36,8 +37,6 @@ module.exports = Self => { const models = Self.app.models; - // const {_saleFk, _substitutionFk, _quantity} = ctx.args; - if (typeof options == 'object') Object.assign(myOptions, options); @@ -47,25 +46,46 @@ module.exports = Self => { } try { - const _replaceItem = { + const replaceItemQuery = { sql: 'CALL sale_replaceItem(?,?,?)', query: [saleFk, substitutionFk, quantity] }; - const resultReplaceItem = await Self.rawSql(_replaceItem.sql, _replaceItem.query, myOptions); + const resultReplaceItem = await Self.rawSql(replaceItemQuery.sql, replaceItemQuery.query, myOptions); + const sale = await models.Sale.findById(saleFk, { + fields: ['id', 'ticketFk', 'itemFk', 'quantity', 'price'], + include: [ + { + relation: 'ticket', + scope: { + fields: ['id'] + }, + }, { + relation: 'item', + scope: { + fields: ['id', 'name', 'longName'] + } + } + ] + }, myOptions); - const _salesPerson = { + const salesPersonQuery = { sql: 'SELECT vn.client_getSalesPersonByTicket(?)', - query: [saleFk.ticket.id] + query: [sale.ticketFk] }; - const salesPerson = await Self.rawSql(_salesPerson.query, _salesPerson.sql, myOptions); - + const salesPerson = await Self.rawSql(salesPersonQuery.sql, salesPersonQuery.query, myOptions); + const url = await Self.app.models.Url.getUrl(); + const substitution = await models.Item.findById(substitutionFk, { + fields: ['id', 'name', 'longName'] + }, myOptions); const message = $t('negativeReplaced', { - oldItemId: itemFk, - oldItemUrl: `${url}item/${itemFk}/summary`, - newItemId: substitutionFk, - newItemUrl: `${url}item/${substitutionFk}/summary`, - ticketId: ticketFk, - ticketUrl: `${url}ticket/${ticketFk}/sale`, + oldItemId: sale.itemFk, + oldItem: sale.item().longName, + oldItemUrl: `${url}item/${sale.itemFk}/summary`, + newItemId: substitution.id, + newItem: substitution.longName, + newItemUrl: `${url}item/${substitution.id}/summary`, + ticketId: sale.ticketFk, + ticketUrl: `${url}ticket/${sale.ticketFk}/sale` }); await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); diff --git a/modules/ticket/back/methods/ticket/itemLackDetail.js b/modules/ticket/back/methods/ticket/itemLackDetail.js index 6d9e7a4c3..6e5badcd1 100644 --- a/modules/ticket/back/methods/ticket/itemLackDetail.js +++ b/modules/ticket/back/methods/ticket/itemLackDetail.js @@ -2,7 +2,7 @@ const {ParameterizedSQL} = require('loopback-connector'); module.exports = Self => { Self.remoteMethod('itemLackDetail', { - description: 'Retrieve detail from ticket', + description: 'Retrieve detail from ticket as negative', accessType: 'READ', accepts: [ { diff --git a/modules/ticket/back/methods/ticket/specs/itemLack.spec.js b/modules/ticket/back/methods/ticket/specs/itemLack.spec.js index af0538c21..f56510447 100644 --- a/modules/ticket/back/methods/ticket/specs/itemLack.spec.js +++ b/modules/ticket/back/methods/ticket/specs/itemLack.spec.js @@ -90,7 +90,7 @@ describe('Item Lack', () => { try { const result = await models.Ticket.itemLack(ctx, filter, options); - expect(result.length).toEqual(0); + expect(result.length).toEqual(1); await tx.rollback(); } catch (e) { await tx.rollback(); diff --git a/modules/ticket/back/methods/ticket/split.js b/modules/ticket/back/methods/ticket/split.js index bab8ddb85..04766f7db 100644 --- a/modules/ticket/back/methods/ticket/split.js +++ b/modules/ticket/back/methods/ticket/split.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethodCtx('split', { - description: 'Split ticket', + description: 'Split ticket with custom date', accessType: 'WRITE', accepts: [ { @@ -8,6 +8,11 @@ module.exports = Self => { type: 'Object', required: true, http: {source: 'body'} + }, + { + arg: 'date', + type: 'date', + required: true, } ], returns: { diff --git a/modules/ticket/back/methods/ticket/transferSales.js b/modules/ticket/back/methods/ticket/transferSales.js index 9c616527d..580a8e1f7 100644 --- a/modules/ticket/back/methods/ticket/transferSales.js +++ b/modules/ticket/back/methods/ticket/transferSales.js @@ -33,8 +33,7 @@ module.exports = Self => { } }); - Self.transferSales = async(ctx, id, ticketId, sales, - options) => { + Self.transferSales = async(ctx, id, ticketId, sales, options) => { const userId = ctx.req.accessToken.userId; const models = Self.app.models; const myOptions = {userId};