From fb3f3c64c9c19baab8fee929ec8414485f82ee1b Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 19 Dec 2022 09:59:03 +0100 Subject: [PATCH 01/13] refs #4858 --- back/methods/chat/sendCheckingPresence.js | 4 +++- back/methods/chat/sendQueued.js | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 3bc022429..5520abb7c 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -43,7 +43,7 @@ module.exports = Self => { if (!recipient) throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`); - await models.Chat.create({ + const chat = await models.Chat.create({ senderFk: sender.id, recipient: `@${recipient.name}`, dated: new Date(), @@ -52,6 +52,8 @@ module.exports = Self => { status: 0, attempts: 0 }); + console.log(chat); + await models.Chat.sendQueued(chat.id); return true; }; diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index 66fbfcdc5..cbe963235 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -3,7 +3,11 @@ module.exports = Self => { Self.remoteMethodCtx('sendQueued', { description: 'Send a RocketChat message', accessType: 'WRITE', - accepts: [], + accepts: [{ + arg: 'id', + type: 'number', + description: 'The message id' + }], returns: { type: 'object', root: true @@ -14,17 +18,20 @@ module.exports = Self => { } }); - Self.sendQueued = async() => { + Self.sendQueued = async id => { const models = Self.app.models; const maxAttempts = 3; const sentStatus = 1; const errorStatus = 2; + let filter = { + status: {neq: sentStatus}, + attempts: {lt: maxAttempts} + }; + // NOTA: Igual se deberia transaccionar por si coincidiera que en el momento que se esta enviando directamente + // tambien se esta ejecutando la cola que no lo envie dos veces. const chats = await models.Chat.find({ - where: { - status: {neq: sentStatus}, - attempts: {lt: maxAttempts} - } + where: id ? {id} : filter }); for (let chat of chats) { From d85717ca0466fea7d7ab409fdbd9c630efa32ae8 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 4 Jan 2023 11:23:06 +0100 Subject: [PATCH 02/13] feat: chat in real time --- back/methods/chat/send.js | 2 +- back/methods/chat/sendCheckingPresence.js | 39 ++++++++++++++++++++--- back/methods/chat/sendQueued.js | 31 +++++++++--------- db/changes/230201/00-chatRefactor.sql | 16 ++++++++++ 4 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 db/changes/230201/00-chatRefactor.sql diff --git a/back/methods/chat/send.js b/back/methods/chat/send.js index c5c8feead..7fda97c82 100644 --- a/back/methods/chat/send.js +++ b/back/methods/chat/send.js @@ -36,7 +36,7 @@ module.exports = Self => { dated: new Date(), checkUserStatus: 0, message: message, - status: 0, + status: 'pending', attempts: 0 }); diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 5520abb7c..604c471d7 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -27,11 +27,17 @@ module.exports = Self => { Self.sendCheckingPresence = async(ctx, recipientId, message, options) => { if (!recipientId) return false; + let tx; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + const models = Self.app.models; const userId = ctx.req.accessToken.userId; const sender = await models.Account.findById(userId); @@ -49,12 +55,37 @@ module.exports = Self => { dated: new Date(), checkUserStatus: 1, message: message, - status: 0, + status: 'sending', attempts: 0 - }); - console.log(chat); - await models.Chat.sendQueued(chat.id); + }, myOptions); + + try { + await Self.sendCheckingUserStatus(chat); + await updateChat(chat, 'sent', myOptions); + } catch (error) { + await updateChat(chat, 'error', error, myOptions); + } + + if (tx) await tx.commit(); return true; }; + + /** + * Update status and attempts of a chat + * + * @param {object} chat - The chat + * @param {string} status - The new status + * @param {string} error - The error + * @param {object} options - Query options + * @return {Promise} - The request promise + */ + + async function updateChat(chat, status, error, options) { + return chat.updateAttributes({ + status: status, + attempts: ++chat.attempts, + error: error + }, options); + } }; diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index cbe963235..dcd530873 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -3,11 +3,6 @@ module.exports = Self => { Self.remoteMethodCtx('sendQueued', { description: 'Send a RocketChat message', accessType: 'WRITE', - accepts: [{ - arg: 'id', - type: 'number', - description: 'The message id' - }], returns: { type: 'object', root: true @@ -18,20 +13,25 @@ module.exports = Self => { } }); - Self.sendQueued = async id => { + Self.sendQueued = async() => { const models = Self.app.models; const maxAttempts = 3; - const sentStatus = 1; - const errorStatus = 2; - let filter = { - status: {neq: sentStatus}, - attempts: {lt: maxAttempts} - }; + const sentStatus = 'sent'; + const sendingStatus = 'sending'; + const errorStatus = 'error'; - // NOTA: Igual se deberia transaccionar por si coincidiera que en el momento que se esta enviando directamente - // tambien se esta ejecutando la cola que no lo envie dos veces. const chats = await models.Chat.find({ - where: id ? {id} : filter + where: { + status: { + neq: { + and: [ + sentStatus, + sendingStatus + ] + } + }, + attempts: {lt: maxAttempts} + } }); for (let chat of chats) { @@ -137,6 +137,7 @@ module.exports = Self => { * @param {string} error - The error * @return {Promise} - The request promise */ + async function updateChat(chat, status, error) { return chat.updateAttributes({ status: status, diff --git a/db/changes/230201/00-chatRefactor.sql b/db/changes/230201/00-chatRefactor.sql new file mode 100644 index 000000000..66d1bf3bf --- /dev/null +++ b/db/changes/230201/00-chatRefactor.sql @@ -0,0 +1,16 @@ +ALTER TABLE `vn`.`chat` ADD statusNew enum('pending','sent','error','sending') DEFAULT 'pending' NOT NULL; + +UPDATE `vn`.`chat` + SET statusNew = 'pending' +WHERE status = 0; + +UPDATE `vn`.`chat` + SET statusNew = 'sent' +WHERE status = 1; + +UPDATE `vn`.`chat` + SET statusNew = 'error' +WHERE status = 2; + +ALTER TABLE `vn`.`chat` CHANGE status status__ tinyint(1) DEFAULT NULL NULL; +ALTER TABLE `vn`.`chat` CHANGE statusNew status enum('pending','sent','error','sending') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'pending' NOT NULL; From 44055775cb278ed4720d3008b7b89cef5ea11e92 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 6 Feb 2023 10:11:41 +0100 Subject: [PATCH 03/13] fix: not use variables and direct send in send --- back/methods/chat/send.js | 11 +++++++++-- back/methods/chat/sendQueued.js | 18 +++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/back/methods/chat/send.js b/back/methods/chat/send.js index 21e25c1f0..5e3821677 100644 --- a/back/methods/chat/send.js +++ b/back/methods/chat/send.js @@ -30,16 +30,23 @@ module.exports = Self => { const recipient = to.replace('@', ''); if (sender.name != recipient) { - await models.Chat.create({ + const chat = await models.Chat.create({ senderFk: sender.id, recipient: to, dated: Date.vnNew(), checkUserStatus: 0, message: message, - status: 'pending', + status: 'sending', attempts: 0 }); + try { + await Self.sendMessage(chat.senderFk, chat.recipient, chat.message); + await updateChat(chat, 'sent'); + } catch (error) { + await updateChat(chat, 'error', error); + } + return true; } diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index dcd530873..ad8363627 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -15,22 +15,18 @@ module.exports = Self => { Self.sendQueued = async() => { const models = Self.app.models; - const maxAttempts = 3; - const sentStatus = 'sent'; - const sendingStatus = 'sending'; - const errorStatus = 'error'; const chats = await models.Chat.find({ where: { status: { neq: { and: [ - sentStatus, - sendingStatus + 'sent', + 'sending' ] } }, - attempts: {lt: maxAttempts} + attempts: {lt: 3} } }); @@ -38,16 +34,16 @@ module.exports = Self => { if (chat.checkUserStatus) { try { await Self.sendCheckingUserStatus(chat); - await updateChat(chat, sentStatus); + await updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, errorStatus, error); + await updateChat(chat, 'error', error); } } else { try { await Self.sendMessage(chat.senderFk, chat.recipient, chat.message); - await updateChat(chat, sentStatus); + await updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, errorStatus, error); + await updateChat(chat, 'error', error); } } } From f06fc92ae80dd38cb9e4afcbd34ef75e3ba791fb Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 8 Feb 2023 15:15:26 +0100 Subject: [PATCH 04/13] refactor(chat): not use transactions --- back/methods/chat/send.js | 4 +-- back/methods/chat/sendCheckingPresence.js | 43 ++++------------------- back/methods/chat/sendQueued.js | 7 ++-- 3 files changed, 12 insertions(+), 42 deletions(-) diff --git a/back/methods/chat/send.js b/back/methods/chat/send.js index 5e3821677..79b20e307 100644 --- a/back/methods/chat/send.js +++ b/back/methods/chat/send.js @@ -42,9 +42,9 @@ module.exports = Self => { try { await Self.sendMessage(chat.senderFk, chat.recipient, chat.message); - await updateChat(chat, 'sent'); + await Self.updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, 'error', error); + await Self.updateChat(chat, 'error', error); } return true; diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index cabd3d85e..3eaf6b86b 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -24,24 +24,13 @@ module.exports = Self => { } }); - Self.sendCheckingPresence = async(ctx, recipientId, message, options) => { + Self.sendCheckingPresence = async(ctx, recipientId, message) => { if (!recipientId) return false; - let tx; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - const models = Self.app.models; const userId = ctx.req.accessToken.userId; - const sender = await models.Account.findById(userId); - const recipient = await models.Account.findById(recipientId, null, myOptions); + const sender = await models.Account.findById(userId, {fields: ['id']}); + const recipient = await models.Account.findById(recipientId, null); // Prevent sending messages to yourself if (recipientId == userId) return false; @@ -57,35 +46,15 @@ module.exports = Self => { message: message, status: 'sending', attempts: 0 - }, myOptions); + }); try { await Self.sendCheckingUserStatus(chat); - await updateChat(chat, 'sent', myOptions); + await Self.updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, 'error', error, myOptions); + await Self.updateChat(chat, 'error', error); } - if (tx) await tx.commit(); - return true; }; - - /** - * Update status and attempts of a chat - * - * @param {object} chat - The chat - * @param {string} status - The new status - * @param {string} error - The error - * @param {object} options - Query options - * @return {Promise} - The request promise - */ - - async function updateChat(chat, status, error, options) { - return chat.updateAttributes({ - status: status, - attempts: ++chat.attempts, - error: error - }, options); - } }; diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index ad8363627..8a0bdee34 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -131,16 +131,17 @@ module.exports = Self => { * @param {object} chat - The chat * @param {string} status - The new status * @param {string} error - The error + * @param {object} options - Query options * @return {Promise} - The request promise - */ + */ - async function updateChat(chat, status, error) { + Self.updateChat = async(chat, status, error) => { return chat.updateAttributes({ status: status, attempts: ++chat.attempts, error: error }); - } + }; /** * Returns the current user status on Rocketchat From 1b8ed05f71b7e7edb0b67f19405374172215d5b2 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 15 Mar 2023 13:28:28 +0100 Subject: [PATCH 05/13] =?UTF-8?q?refs=20#5395=20feat:=20modificado=20order?= =?UTF-8?q?By,=20a=C3=B1adida=20columna=20importa=20y=20corregidos=20error?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back/methods/claim-state/isEditable.js | 16 +++++++------- .../methods/travel/extraCommunityFilter.js | 2 ++ .../travel/front/extra-community/index.html | 21 ++++++++----------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/modules/claim/back/methods/claim-state/isEditable.js b/modules/claim/back/methods/claim-state/isEditable.js index 2d0a8dc44..ad51d543a 100644 --- a/modules/claim/back/methods/claim-state/isEditable.js +++ b/modules/claim/back/methods/claim-state/isEditable.js @@ -26,13 +26,13 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - - const state = await models.ClaimState.findById(id, { - include: { - relation: 'writeRole' - } - }, myOptions); - const roleWithGrants = state && state.writeRole().name; - return await models.Account.hasRole(userId, roleWithGrants, myOptions); + + const state = await models.ClaimState.findById(id, { + include: { + relation: 'writeRole' + } + }, myOptions); + const roleWithGrants = state && state.writeRole().name; + return await models.Account.hasRole(userId, roleWithGrants, myOptions); }; }; diff --git a/modules/travel/back/methods/travel/extraCommunityFilter.js b/modules/travel/back/methods/travel/extraCommunityFilter.js index 027261c4b..5ee51de8e 100644 --- a/modules/travel/back/methods/travel/extraCommunityFilter.js +++ b/modules/travel/back/methods/travel/extraCommunityFilter.js @@ -130,6 +130,7 @@ module.exports = Self => { SUM(b.stickers) AS stickers, s.id AS cargoSupplierFk, s.nickname AS cargoSupplierNickname, + s.name AS supplierName, CAST(SUM(b.weight * b.stickers) as DECIMAL(10,0)) as loadedKg, CAST(SUM(vc.aerealVolumetricDensity * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000) as DECIMAL(10,0)) as volumeKg FROM travel t @@ -167,6 +168,7 @@ module.exports = Self => { SUM(b.stickers) AS stickers, e.evaNotes, e.notes, + e.invoiceAmount, CAST(SUM(b.weight * b.stickers) AS DECIMAL(10,0)) as loadedkg, CAST(SUM(vc.aerealVolumetricDensity * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000) AS DECIMAL(10,0)) as volumeKg FROM tmp.travel tr diff --git a/modules/travel/front/extra-community/index.html b/modules/travel/front/extra-community/index.html index ee8dcdf98..73e62b174 100644 --- a/modules/travel/front/extra-community/index.html +++ b/modules/travel/front/extra-community/index.html @@ -3,7 +3,7 @@ url="Travels/extraCommunityFilter" filter="::$ctrl.filter" data="travels" - order="shipped ASC, landed ASC, travelFk, loadPriority, agencyModeFk, evaNotes" + order="landed ASC, shipped ASC, travelFk, loadPriority, agencyModeFk, supplierName, evaNotes" limit="20" auto-load="true"> @@ -48,6 +48,9 @@ Agency + + Amount + Reference @@ -107,6 +110,7 @@ {{::travel.cargoSupplierNickname}} + {{::travel.agencyModeName}} @@ -157,22 +161,15 @@ {{::entry.supplierName}} + {{::entry.invoiceAmount | currency: 'EUR': 2}} - {{::entry.ref}} + {{::entry.invoiceNumber}} {{::entry.stickers}} {{::entry.loadedkg}} {{::entry.volumeKg}} - - - {{::entry.notes}} - - - - - {{::entry.evaNotes}} - - + + From d1f0ae386540126412fa75148e9a644e3638bb3f Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 21 Mar 2023 11:26:25 +0100 Subject: [PATCH 06/13] refs #4858 fix: filtro corregido --- back/methods/chat/sendCheckingPresence.js | 3 +++ back/methods/chat/sendQueued.js | 19 +++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 3eaf6b86b..29232490a 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -38,6 +38,9 @@ module.exports = Self => { if (!recipient) throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`); + if (process.env.NODE_ENV == 'test') + message = `[Test:Environment to user ${userId}] ` + message; + const chat = await models.Chat.create({ senderFk: sender.id, recipient: `@${recipient.name}`, diff --git a/back/methods/chat/sendQueued.js b/back/methods/chat/sendQueued.js index 8a0bdee34..ef1a417ab 100644 --- a/back/methods/chat/sendQueued.js +++ b/back/methods/chat/sendQueued.js @@ -19,12 +19,11 @@ module.exports = Self => { const chats = await models.Chat.find({ where: { status: { - neq: { - and: [ - 'sent', - 'sending' - ] - } + nin: [ + 'sent', + 'sending' + ] + }, attempts: {lt: 3} } @@ -34,16 +33,16 @@ module.exports = Self => { if (chat.checkUserStatus) { try { await Self.sendCheckingUserStatus(chat); - await updateChat(chat, 'sent'); + await Self.updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, 'error', error); + await Self.updateChat(chat, 'error', error); } } else { try { await Self.sendMessage(chat.senderFk, chat.recipient, chat.message); - await updateChat(chat, 'sent'); + await Self.updateChat(chat, 'sent'); } catch (error) { - await updateChat(chat, 'error', error); + await Self.updateChat(chat, 'error', error); } } } From 4141a9735600521fc172539aa8d2b1c266249701 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 21 Mar 2023 11:37:26 +0100 Subject: [PATCH 07/13] refs #4858 fix: backTest --- back/methods/chat/spec/sendQueued.spec.js | 4 ++-- db/changes/{230201 => 231201}/00-chatRefactor.sql | 0 db/dump/fixtures.sql | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename db/changes/{230201 => 231201}/00-chatRefactor.sql (100%) diff --git a/back/methods/chat/spec/sendQueued.spec.js b/back/methods/chat/spec/sendQueued.spec.js index ed791756b..67cd47f4a 100644 --- a/back/methods/chat/spec/sendQueued.spec.js +++ b/back/methods/chat/spec/sendQueued.spec.js @@ -10,7 +10,7 @@ describe('Chat sendCheckingPresence()', () => { const chat = { checkUserStatus: 1, - status: 0, + status: 'pending', attempts: 0 }; @@ -27,7 +27,7 @@ describe('Chat sendCheckingPresence()', () => { const chat = { checkUserStatus: 0, - status: 0, + status: 'pending', attempts: 0 }; diff --git a/db/changes/230201/00-chatRefactor.sql b/db/changes/231201/00-chatRefactor.sql similarity index 100% rename from db/changes/230201/00-chatRefactor.sql rename to db/changes/231201/00-chatRefactor.sql diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 2145f8429..e6e998d59 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2631,8 +2631,8 @@ INSERT INTO `vn`.`supplierAgencyTerm` (`agencyFk`, `supplierFk`, `minimumPackage INSERT INTO `vn`.`chat` (`senderFk`, `recipient`, `dated`, `checkUserStatus`, `message`, `status`, `attempts`) VALUES - (1101, '@PetterParker', util.VN_CURDATE(), 1, 'First test message', 0, 0), - (1101, '@PetterParker', util.VN_CURDATE(), 0, 'Second test message', 0, 0); + (1101, '@PetterParker', util.VN_CURDATE(), 1, 'First test message', 0, 'sent'), + (1101, '@PetterParker', util.VN_CURDATE(), 0, 'Second test message', 0, 'pending'); INSERT INTO `vn`.`mobileAppVersionControl` (`appName`, `version`, `isVersionCritical`) From 1d0024c5382e5512613bae9d93388527f255fb87 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 21 Mar 2023 14:08:34 +0100 Subject: [PATCH 08/13] =?UTF-8?q?refs=20#5013=20feat:=20a=C3=B1adida=20obs?= =?UTF-8?q?ervacion=20para=20cada=20ticket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/changes/231201/00-observationType.sql | 2 ++ print/templates/reports/invoice/invoice.html | 11 +++++++++++ print/templates/reports/invoice/sql/tickets.sql | 9 ++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 db/changes/231201/00-observationType.sql diff --git a/db/changes/231201/00-observationType.sql b/db/changes/231201/00-observationType.sql new file mode 100644 index 000000000..20e3608e4 --- /dev/null +++ b/db/changes/231201/00-observationType.sql @@ -0,0 +1,2 @@ +INSERT INTO `vn`.`observationType` (`description`, `code`, `hasNewBornMessage`) +VALUES ('Factura', 'invocieOut', '0'); diff --git a/print/templates/reports/invoice/invoice.html b/print/templates/reports/invoice/invoice.html index 2d180878a..2c37126fc 100644 --- a/print/templates/reports/invoice/invoice.html +++ b/print/templates/reports/invoice/invoice.html @@ -119,6 +119,16 @@ {{ticketSubtotal(ticket) | currency('EUR', $i18n.locale)}} + +
+
+
{{$t('observations')}}
+
+
{{ticket.description}}
+
+
+
+ @@ -251,6 +261,7 @@ +