salix/back/methods/dms/saveSign.js

76 lines
2.0 KiB
JavaScript
Raw Normal View History

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;
}
};
};