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; } };