From ac2809082d74b4759836408563749f3dcdd6384b Mon Sep 17 00:00:00 2001 From: Paul Girard Date: Thu, 7 Sep 2017 12:10:47 +0200 Subject: [PATCH] resilient to bad WhoID in db --- server/routes/editLog.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/routes/editLog.js b/server/routes/editLog.js index 95e2ce07..33922271 100644 --- a/server/routes/editLog.js +++ b/server/routes/editLog.js @@ -213,9 +213,11 @@ function formatEdits(data, model){ data.forEach(d => { const edit = {} edit.who = { - id: d.whoID, - name: (d.creator[0].firstName ? d.creator[0].firstName+' ': '')+ d.creator[0].name, - roles: d.creator[0].isariAuthorizedCenters ? + id: d.whoID + } + if (d.creator.length){ + edit.who.name = (d.creator[0].firstName ? d.creator[0].firstName+' ': '')+ d.creator[0].name + edit.who.roles = d.creator[0].isariAuthorizedCenters ? d.creator[0].isariAuthorizedCenters.map(iac =>({lab:iac.organization,role:iac.isariRole})): [] }