refs #6276 shelvingLog_add
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2023-12-12 14:56:58 +01:00
parent f5ee3aff7a
commit 7b81630b85
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,55 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('addLog', {
description: 'Add a new log',
accessType: 'WRITE',
accepts: {
arg: 'code',
type: 'string',
required: true,
},
http: {
path: '/addLog',
verb: 'POST'
}
});
Self.addLog = async(ctx, code, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const shelving = await Self.findOne({
where: {
code
}
}, myOptions);
if (!shelving) throw new UserError('Shelving not valid');
await models.ShelvingLog.create({
changedModel: 'Shelving',
originFk: shelving.id,
changedModelId: shelving.id,
action: 'select',
userFk: userId
}, myOptions);
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -1,3 +1,4 @@
module.exports = Self => {
require('../methods/shelving/getSummary')(Self);
require('../methods/shelving/addLog')(Self);
};