fix: refs #6776 back
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-02-20 09:27:37 +01:00
parent 072280cc9c
commit 55b490160b
1 changed files with 4 additions and 1 deletions

View File

@ -1,3 +1,4 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('addSaleByCode', { Self.remoteMethodCtx('addSaleByCode', {
description: 'Add a collection', description: 'Add a collection',
@ -42,7 +43,9 @@ module.exports = Self => {
try { try {
const [[item]] = await Self.rawSql('CALL vn.item_getInfo(?,?)', [barcode, warehouseFk], myOptions); const [[item]] = await Self.rawSql('CALL vn.item_getInfo(?,?)', [barcode, warehouseFk], myOptions);
await Self.addSale(ctx, ticketFk, item.id, quantity, myOptions); if (!item?.available) throw new UserError('We do not have availability for the selected item');
await Self.rawSql('CALL vn.collection_addItem(?, ?, ?)', [item.id, quantity, ticketFk], myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();
} catch (e) { } catch (e) {