#6276 createNewWarehouse methods migrated from silex to salix #1850

Merged
jorgep merged 158 commits from 6276-createNewWarehouse into dev 2024-03-06 11:32:11 +00:00
2 changed files with 56 additions and 0 deletions
Showing only changes of commit 7b81630b85 - Show all commits

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',
jgallego marked this conversation as resolved
Review

esto porque no se hace automatizado como el resto de modelos? ejemplo ticket

esto porque no se hace automatizado como el resto de modelos? ejemplo ticket
Review

@jgallego @alexm Perquè necessitaria dos cridaes, una per traure el id i un altra per fer el insert amb el id.

@jgallego @alexm Perquè necessitaria dos cridaes, una per traure el id i un altra per fer el insert amb el id.
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);
};