From 56201f4c1a44b950f841cec64b97f853b1a17358 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 10 Nov 2022 13:37:16 +0100 Subject: [PATCH] Start implementing method refs #3681 @3h --- back/methods/dms/saveSign.js | 75 +++++++++++++++++++ back/models/dms.js | 1 + db/changes/10502-november/00-ACL_saveSign.sql | 1 + .../01-add_data_to_hedera.config.sql | 30 ++++++++ 4 files changed, 107 insertions(+) create mode 100644 back/methods/dms/saveSign.js create mode 100644 db/changes/10502-november/00-ACL_saveSign.sql create mode 100644 db/changes/10502-november/01-add_data_to_hedera.config.sql diff --git a/back/methods/dms/saveSign.js b/back/methods/dms/saveSign.js new file mode 100644 index 000000000..dc8564a18 --- /dev/null +++ b/back/methods/dms/saveSign.js @@ -0,0 +1,75 @@ +module.exports = Self => { + Self.remoteMethodCtx('saveSign', { + description: 'Save sign', + accessType: 'WRITE', + accepts: + [ + { + arg: 'singContent', + type: 'string', + required: true, + description: 'The sign content' + }, { + arg: 'tickets', + type: ['number'], + required: true, + description: 'The tickets' + }, { + arg: 'signedTime', + type: 'date', + description: 'The signed time' + }, { + arg: 'addressFk', + type: 'number', + required: true, + description: 'The address fk' + } + ], + returns: { + type: 'Object', + root: true + }, + http: { + path: `/saveSign`, + verb: 'POST' + } + }); + + Self.saveSign = async(ctx, signContent, tickets, signedTime, addressFk) => { + const userId = ctx.req.accessToken.userId; + + let dmsDir = await Self.rawSql(`SELECT dmsDir FROM hedera.config`); + + let image; + + let alertLevels = []; + + for (let i = 0; i < tickets.length; i++) { + let call = `SELECT alertLevel FROM vn.ticketState WHERE ticketFk = ${tickets[i]}`; + let result = await Self.rawSql(call); + + alertLevels.push(result[0].alertLevel); + } + + signedTime ? signedTime != undefined : signedTime = new Date(); + + let tx = await Self.beginTransaction({}); + + try { + if (tx) await tx.commit(); + + return { + success: true, + signContent: signContent, + tickets: tickets, + signedTime: signedTime, + addressFk: addressFk, + dmsDir: dmsDir, + alertLevels: alertLevels + }; + } catch (err) { + await tx.rollback(); + throw err; + } + }; +}; diff --git a/back/models/dms.js b/back/models/dms.js index 24c072f56..fc586201f 100644 --- a/back/models/dms.js +++ b/back/models/dms.js @@ -6,6 +6,7 @@ module.exports = Self => { require('../methods/dms/removeFile')(Self); require('../methods/dms/updateFile')(Self); require('../methods/dms/deleteTrashFiles')(Self); + require('../methods/dms/saveSign')(Self); Self.checkRole = async function(ctx, id) { const models = Self.app.models; diff --git a/db/changes/10502-november/00-ACL_saveSign.sql b/db/changes/10502-november/00-ACL_saveSign.sql new file mode 100644 index 000000000..549464512 --- /dev/null +++ b/db/changes/10502-november/00-ACL_saveSign.sql @@ -0,0 +1 @@ +INSERT INTO salix.ACL (model,property,accessType,permission,principalId) VALUES ('Dms','saveSign','*','ALLOW','employee'); diff --git a/db/changes/10502-november/01-add_data_to_hedera.config.sql b/db/changes/10502-november/01-add_data_to_hedera.config.sql new file mode 100644 index 000000000..73305264c --- /dev/null +++ b/db/changes/10502-november/01-add_data_to_hedera.config.sql @@ -0,0 +1,30 @@ +INSERT INTO + `hedera`.`config` ( + defaultLang, + https, + cookieLife, + jwtKey, + defaultForm, + restUri, + testRestUri, + guestUser, + testDomain, + productionDomain, + pdfsDir, + dmsDir + ) +VALUES + ( + 'es', + 0, + 15, + 'dfAr&s4t78h9F.Arw1C?dpR', + 'cms/home', + 'https://verdnatura.es/', + 'https://test.verdnatura.es/', + 'visitor', + NULL, + 'verdnatura.es', + '/mnt/storage/pdfs', + '/mnt/storage/dms' + ); \ No newline at end of file