refs #6276 shelvingLog_add
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
f5ee3aff7a
commit
7b81630b85
|
@ -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;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/shelving/getSummary')(Self);
|
||||
require('../methods/shelving/addLog')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue