From b0abe829b1adef052ff723c5e316be34eac29b2a Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 6 Sep 2024 10:10:41 +0200 Subject: [PATCH] fix: refs ##7905 Handle error --- loopback/locale/es.json | 5 +++-- modules/entry/back/methods/entry/getBuysCsv.js | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 8c11b3f1c..8b443d96b 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -371,5 +371,6 @@ "The sale not exists in the item shelving": "La venta no existe en la estantería del artículo", "The entry not have stickers": "La entrada no tiene etiquetas", "Too many records": "Demasiados registros", - "Original invoice not found": "Factura original no encontrada" -} + "Original invoice not found": "Factura original no encontrada", + "The entry has no lines or does not exist": "La entrada no tiene lineas o no existe" +} \ No newline at end of file diff --git a/modules/entry/back/methods/entry/getBuysCsv.js b/modules/entry/back/methods/entry/getBuysCsv.js index a46f09c66..4bd246fa0 100644 --- a/modules/entry/back/methods/entry/getBuysCsv.js +++ b/modules/entry/back/methods/entry/getBuysCsv.js @@ -1,5 +1,6 @@ const {toCSV} = require('vn-loopback/util/csv'); const {flatten} = require('vn-loopback/util/flatten'); +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('getBuysCsv', { @@ -36,6 +37,7 @@ module.exports = Self => { Self.getBuysCsv = async(ctx, id, options) => { const data = await Self.getBuys(ctx, id, null, options); + if (!data.length) throw new UserError('The entry has no lines or does not exist'); const dataFlatted = flatten(data); return [toCSV(dataFlatted), 'text/csv', `inline; filename="buys-${id}.csv"`]; };