feat(save-sign implemented in salix back, refs 3681 @2h
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
8e7e7901af
commit
0f0c4c0554
|
@ -1,4 +1,6 @@
|
|||
const md5 = require('md5');
|
||||
const fs = require('fs-extra');
|
||||
const {file} = require('jszip');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('saveSign', {
|
||||
|
@ -38,7 +40,7 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
async function createGestDoc(ticketId, userFk) {
|
||||
if (!gestDocExists(ticketId)) {
|
||||
if (! await gestDocExists(ticketId)) {
|
||||
const query = `SELECT t.warehouseFk,
|
||||
t.companyFk,
|
||||
c.name,
|
||||
|
@ -76,26 +78,26 @@ module.exports = Self => {
|
|||
|
||||
return resultDms.insertId;
|
||||
}
|
||||
return null;
|
||||
|
||||
return 'null';
|
||||
}
|
||||
|
||||
async function gestDocExists(ticket) {
|
||||
const dMSQuery = `SELECT dmsFk as id FROM vn.ticketDms WHERE ticketFk = ?`;
|
||||
|
||||
const result = await Self.rawSql(dMSQuery, [ticket]);
|
||||
result = await Self.rawSql(dMSQuery, [ticket]);
|
||||
|
||||
if (result.length > 0) {
|
||||
const isSigned = await Self.rawSql(
|
||||
`SELECT isSigned FROM vn.ticket WHERE id = ?`, [ticket]
|
||||
);
|
||||
if (result.length < 0)
|
||||
return false;
|
||||
|
||||
if (isSigned[0].isSigned)
|
||||
return true;
|
||||
else
|
||||
deleteFromGestDoc(ticket);
|
||||
}
|
||||
const isSigned = await Self.rawSql(
|
||||
`SELECT isSigned FROM vn.ticket WHERE id = ?`, [ticket]
|
||||
);
|
||||
|
||||
return false;
|
||||
if (isSigned[0].isSigned)
|
||||
return true;
|
||||
else
|
||||
deleteFromGestDoc(ticket);
|
||||
}
|
||||
|
||||
async function deleteFromGestDoc(ticket) {
|
||||
|
@ -104,43 +106,96 @@ module.exports = Self => {
|
|||
);
|
||||
}
|
||||
|
||||
async function dmsRecover(ticket, signContent) {
|
||||
const query = `INSERT INTO vn.dmsRecover (ticketFk, sign) VALUES (?, ?)`;
|
||||
|
||||
await Self.rawSql(query, [ticket, signContent]);
|
||||
}
|
||||
|
||||
async function ticketGestdoc(ticket, dmsFk) {
|
||||
const query = `REPLACE INTO vn.ticketDms(ticketFk, dmsFk)
|
||||
VALUES (?, ?)`;
|
||||
|
||||
await Self.rawSql(query, [ticket, dmsFk]);
|
||||
|
||||
const queryVnTicketSetState = `CALL vn.ticket_setState(?, ?)`;
|
||||
|
||||
await Self.rawSql(queryVnTicketSetState, [ticket, 'DELIVERED']);
|
||||
}
|
||||
|
||||
async function updateGestdoc(file, ticket) {
|
||||
const query = `UPDATE vn.dms SET file=?, contentType = 'image/png' WHERE id=?`;
|
||||
|
||||
await Self.rawSql(query, [file, ticket]);
|
||||
}
|
||||
|
||||
Self.saveSign = async(ctx, signContent, tickets, signedTime, addressFk) => {
|
||||
let tx = await Self.beginTransaction({});
|
||||
try {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const dmsDir = `storage/dms`;
|
||||
|
||||
const dmsDir = await Self.rawSql(`SELECT dmsDir FROM hedera.config`);
|
||||
let image = null;
|
||||
|
||||
for (let i = 0; i < tickets.length; i++) {
|
||||
const call = `SELECT alertLevel FROM vn.ticketState WHERE ticketFk = ${tickets[i]}`;
|
||||
const result = await Self.rawSql(call);
|
||||
for (let i = 0; i < tickets.length; i++) {
|
||||
const call = `SELECT alertLevel FROM vn.ticketState WHERE ticketFk = ${tickets[i]}`;
|
||||
const result = await Self.rawSql(call);
|
||||
|
||||
alertLevel = result[0].alertLevel;
|
||||
alertLevel = result[0].alertLevel;
|
||||
|
||||
signedTime ? signedTime != undefined : signedTime = new Date();
|
||||
signedTime ? signedTime != undefined : signedTime = new Date();
|
||||
|
||||
if (alertLevel >= 2) {
|
||||
if (!await gestDocExists(tickets[i])) {
|
||||
const id = createGestDoc(tickets[i], userId);
|
||||
const hashDir = md5(id).substring(0, 3);
|
||||
const dir = `${dmsDir[0].dmsDir}/${hashDir}`;
|
||||
if (alertLevel >= 2) {
|
||||
let dir;
|
||||
let id = null;
|
||||
let fileName = null;
|
||||
|
||||
if (!fs.existsSync(dir))
|
||||
fs.mkdirSync(dir);
|
||||
if (!await gestDocExists(tickets[i])) {
|
||||
id = await createGestDoc(tickets[i], userId);
|
||||
|
||||
const hashDir = md5(id).substring(0, 3);
|
||||
dir = `${dmsDir}/${hashDir}`;
|
||||
|
||||
if (!fs.existsSync(dir))
|
||||
fs.mkdirSync(dir);
|
||||
|
||||
fileName = `${id}.png`;
|
||||
image = `${dir}/${fileName}`;
|
||||
}
|
||||
|
||||
if (image != null) {
|
||||
// if the dir does not exist
|
||||
if (!fs.existsSync(dir))
|
||||
dmsRecover(tickets[i], signContent);
|
||||
else {
|
||||
// Create the file with the image,
|
||||
// the name is the variable image,
|
||||
// the content is the signContent and is in base64
|
||||
console.log('image', image);
|
||||
fs.writeFile(image, signContent, 'base64', async function(err) {
|
||||
if (err) {
|
||||
await tx.rollback();
|
||||
return 'ERROR';
|
||||
}
|
||||
});
|
||||
}
|
||||
} else
|
||||
dmsRecover(tickets[i], signContent);
|
||||
|
||||
if (id != null && fileName.length > 0) {
|
||||
ticketGestdoc(tickets[i], id);
|
||||
updateGestdoc(id, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Sign saved'
|
||||
};
|
||||
return 'OK';
|
||||
} catch (err) {
|
||||
await tx.rollback();
|
||||
throw err;
|
||||
return 'ERROR';
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1 +1 @@
|
|||
INSERT INTO salix.ACL (model,property,accessType,permission,principalId) VALUES ('Dms','saveSign','*','ALLOW','employee');
|
||||
INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) VALUES ('Dms','saveSign','*','ALLOW','employee');
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
INSERT INTO
|
||||
`hedera`.`config` (
|
||||
defaultLang,
|
||||
https,
|
||||
cookieLife,
|
||||
jwtKey,
|
||||
defaultForm,
|
||||
restUri,
|
||||
testRestUri,
|
||||
guestUser,
|
||||
testDomain,
|
||||
productionDomain,
|
||||
pdfsDir,
|
||||
dmsDir
|
||||
`defaultLang`,
|
||||
`https`,
|
||||
`cookieLife`,
|
||||
`jwtKey`,
|
||||
`defaultForm`,
|
||||
`restUri`,
|
||||
`testRestUri`,
|
||||
`guestUser`,
|
||||
`testDomain`,
|
||||
`productionDomain`,
|
||||
`pdfsDir`,
|
||||
`dmsDir`
|
||||
)
|
||||
VALUES
|
||||
(
|
|
@ -236,6 +236,7 @@
|
|||
"Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador",
|
||||
"Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador",
|
||||
"Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente",
|
||||
"You don't have grant privilege": "No tienes privilegios para dar privilegios",
|
||||
"You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario"
|
||||
}
|
||||
"You don't have grant privilege": "No tienes privilegios para dar privilegios",
|
||||
"You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario",
|
||||
"this warehouse has not dms": "this warehouse has not dms"
|
||||
}
|
Loading…
Reference in New Issue