From d19ebe0c8c7d259cc44268b9f01ec87104cb406b Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Tue, 14 Nov 2017 11:20:12 +0100 Subject: [PATCH] bug fixed list producction --- .../common/methods/fake-production/list.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/services/production/common/methods/fake-production/list.js b/services/production/common/methods/fake-production/list.js index 0ad582160..a52f29f96 100644 --- a/services/production/common/methods/fake-production/list.js +++ b/services/production/common/methods/fake-production/list.js @@ -68,16 +68,17 @@ module.exports = function(Self) { } function sum(tickets) { - var obj = {lines: 0, m3: 0}; - tickets.forEach(function(t, i) { - obj.lines += t.lines; - obj.m3 += t.m3; - if (tickets[i].problem) - tickets[i].problem = tickets[i].problem.trim(); - }, this); + let obj = {lines: 0, m3: 0}; + if (tickets && tickets.length) + tickets.forEach(function(t, i) { + obj.lines += t.lines; + obj.m3 += t.m3; + if (tickets[i].problem) + tickets[i].problem = tickets[i].problem.trim(); + }, this); obj.m3 = obj.m3.toFixed(2); - obj.total = tickets.length; - obj.tickets = tickets; + obj.total = tickets ? tickets.length : 0; + obj.tickets = tickets || []; return obj; } };