#6276 createNewWarehouse methods migrated from silex to salix #1850
|
@ -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',
|
||||||
jgallego marked this conversation as resolved
|
|||||||
|
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 => {
|
module.exports = Self => {
|
||||||
require('../methods/shelving/getSummary')(Self);
|
require('../methods/shelving/getSummary')(Self);
|
||||||
|
require('../methods/shelving/addLog')(Self);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
esto porque no se hace automatizado como el resto de modelos? ejemplo ticket
@jgallego @alexm Perquè necessitaria dos cridaes, una per traure el id i un altra per fer el insert amb el id.