feat: refs #6822
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Robert Ferrús 2024-07-03 12:03:28 +02:00
parent eb17d66986
commit 04f6059d6f
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,38 @@
module.exports = Self => {
Self.remoteMethodCtx('transfer', {
description: 'Trasladar la mercancia de una entrada al dia siguiente',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
http: {source: 'path'}
}
],
http: {
path: '/:id/transfer',
verb: 'POST'
}
});
Self.transfer = async(ctx, id, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
await Self.rawSql('CALL vn.entryTransfer(?)', [id], myOptions);
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -10,6 +10,7 @@ module.exports = Self => {
require('../methods/entry/addFromPackaging')(Self); require('../methods/entry/addFromPackaging')(Self);
require('../methods/entry/addFromBuy')(Self); require('../methods/entry/addFromBuy')(Self);
require('../methods/entry/buyLabel')(Self); require('../methods/entry/buyLabel')(Self);
require('../methods/entry/transfer')(Self);
Self.observe('before save', async function(ctx, options) { Self.observe('before save', async function(ctx, options) {
if (ctx.isNewInstance) return; if (ctx.isNewInstance) return;