Skip to content

Commit

Permalink
Merge pull request #6 from ederwms/bugfix/incidents-list
Browse files Browse the repository at this point in the history
fix incidents list not show incidents with files
  • Loading branch information
ederwms authored Jul 26, 2020
2 parents d9a534e + 0084360 commit 4b1b23f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/services/db_bethehero/incident.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,31 @@ const fileService = require('./file.service')

const index = async (idong) => {
const incidents = await db.query(
`SELECT * FROM incidents AS i INNER JOIN files AS f ON i.idfile = f.idfile WHERE idong = '${idong}';`
`SELECT * FROM incidents AS i LEFT JOIN files AS f ON i.idfile = f.idfile WHERE idong = '${idong}';`
)

return incidents
var results = []

for (let i = 0; i < incidents.length; i++) {
const incidentFile = {
idfile: incidents[i].idfile,
filename: incidents[i].filename,
filesize: incidents[i].filesize,
filekey: incidents[i].filekey,
fileurl: incidents[i].fileurl
}

results.push({
idincident: incidents[i].idincident,
title: incidents[i].title,
description: incidents[i].description,
value: incidents[i].value,
idong: incidents[i].idong,
file: incidents[i].idfile !== null ? incidentFile : null
})
}

return results
}

const create = async ({ title, description, value, idong, idfile }) => {
Expand Down

0 comments on commit 4b1b23f

Please sign in to comment.