From f044809f306805ac422e5f22338003e1cc56e5c2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 15 Mar 2024 15:45:47 +0100 Subject: [PATCH] feat: refs #6951 to create back --- db/routines/vn/procedures/ticket_CloneAll.sql | 2 +- .../00-aclTicketClone.sql | 2 + modules/ticket/back/methods/ticket/clone.js | 54 +++++++++++++++++++ modules/ticket/back/models/ticket-methods.js | 2 + modules/ticket/back/models/ticket.js | 1 - 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 db/versions/10957-goldenAnthurium/00-aclTicketClone.sql create mode 100644 modules/ticket/back/methods/ticket/clone.js diff --git a/db/routines/vn/procedures/ticket_CloneAll.sql b/db/routines/vn/procedures/ticket_CloneAll.sql index d56a47a33..a2d775a8f 100644 --- a/db/routines/vn/procedures/ticket_CloneAll.sql +++ b/db/routines/vn/procedures/ticket_CloneAll.sql @@ -15,7 +15,7 @@ BEGIN SET vNewShipped = IFNULL(vNewShipped, util.VN_CURDATE()); - CALL ticket_Clone(vTicketFk, vNewTicketFk, vWithWarehouse); + CALL ticket_Clone(vTicketFk, vNewTicketFk); UPDATE ticket SET landed = TIMESTAMPADD(DAY, DATEDIFF(vNewShipped, shipped), landed), diff --git a/db/versions/10957-goldenAnthurium/00-aclTicketClone.sql b/db/versions/10957-goldenAnthurium/00-aclTicketClone.sql new file mode 100644 index 000000000..6387b77b0 --- /dev/null +++ b/db/versions/10957-goldenAnthurium/00-aclTicketClone.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) + VALUES('Ticket', 'clone', 'WRITE', 'ALLOW', 'ROLE', 'administrative'); \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/clone.js b/modules/ticket/back/methods/ticket/clone.js new file mode 100644 index 000000000..535c6fc7c --- /dev/null +++ b/modules/ticket/back/methods/ticket/clone.js @@ -0,0 +1,54 @@ +module.exports = Self => { + Self.remoteMethodCtx('clone', { + description: 'clone a ticket and return the new ticket id', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'The ticket id', + http: {source: 'path'} + }, { + arg: 'shipped', + type: 'date', + }, { + arg: 'withWarehouse', + type: 'boolean', + } + ], + returns: { + type: 'number', + root: true + }, + http: { + path: `/:id/clone`, + verb: 'POST' + } + }); + + Self.clone = async(ctx, id, shipped, withWarehouse, options) => { + const myOptions = {userId: ctx.req.accessToken.userId}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const [, [{clonedTicketId}]] = await Self.rawSql(` + CALL vn.ticket_CloneAll(?, ?, ?, @clonedTicketId); + SELECT @clonedTicketId clonedTicketId;`, + [id, shipped, withWarehouse], myOptions); + + if (tx) await tx.commit(); + return clonedTicketId; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index d204a8102..0ae2ce3b4 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -46,4 +46,6 @@ module.exports = function(Self) { require('../methods/ticket/invoiceTicketsAndPdf')(Self); require('../methods/ticket/docuwareDownload')(Self); require('../methods/ticket/myLastModified')(Self); + require('../methods/ticket/addSaleByCode')(Self); + require('../methods/ticket/clone')(Self); }; diff --git a/modules/ticket/back/models/ticket.js b/modules/ticket/back/models/ticket.js index 51a8372e3..1930765fb 100644 --- a/modules/ticket/back/models/ticket.js +++ b/modules/ticket/back/models/ticket.js @@ -1,5 +1,4 @@ module.exports = Self => { require('./ticket-methods')(Self); require('../methods/ticket/state')(Self); - require('../methods/ticket/addSaleByCode')(Self); };