diff --git a/routes/root.js b/routes/root.js index a4b548d..40cbbd0 100644 --- a/routes/root.js +++ b/routes/root.js @@ -227,15 +227,17 @@ route.get('/claims/add', auth.ensureLoggedInGithub, (req, res) => { }) }) -route.get('/claims/:id', auth.adminOnly, (req, res) => { - du.getClaimById(req.params.id) - .then(claim => { - if (!claim) throw new Error('No claim found') - res.render('pages/claims/id', { claim }) - }) - .catch(err => { - res.send('Error fetching claim id = ' + escapeHtml(req.params.id)) - }) +route.get('/claims/:id', auth.adminOnly,async (req, res) => { + try{ + const claim = await du.getClaimById(req.params.id) + if (!claim) throw new Error('No claim found') + + // get all conflicts + const conflicts = await du.getConflictsReport(claim) + res.render('pages/claims/id', {claim, conflicts}) + }catch(e){ + res.send('Error fetching claim id = ' + escapeHtml(req.params.id)) + } }) route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => { diff --git a/utils/datautils.js b/utils/datautils.js index 0efa24c..15bb9fd 100644 --- a/utils/datautils.js +++ b/utils/datautils.js @@ -59,6 +59,62 @@ function delClaim(claimId) { }) } +async function getConflictsReport(claim){ + try{ + const issues = await db.Database.query(` + SELECT * + FROM "claims" + WHERE ( "issueUrl"='${claim.issueUrl}' OR + "pullUrl"='${claim.issueUrl}' ) + AND "id" != ${claim.id} + `) + + const pulls = await db.Database.query(` + SELECT * + FROM "claims" + WHERE ("issueUrl"='${claim.pullUrl}') + AND "id" != ${claim.id} + `) + + const both = await db.Database.query(` + SELECT * + FROM "claims" + WHERE (( "issueUrl"='${claim.issueUrl}' AND + "pullUrl"='${claim.pullUrl}' ) + OR ( "issueUrl"='${claim.pullUrl}' AND + "pullUrl"='${claim.issueUrl}' )) + AND "id" != ${claim.id} + `) + + // if both urls same + const object = { + both: both[0] + } + if(claim.issueUrl === claim.pullUrl){ + // if url is of an issue + if(claim.issueUrl.includes("/issues/")){ + object.issue = issues[0] + object.pulls = [] + }else{ + object.issue = [] + object.pulls = pulls[0] + } + } + else{ + object.issue = issues[0] + object.pulls = pulls[0] + } + return object + }catch(e){ + console.log(e.message); + return { + issue: [], + pulls: [], + both: [] + } + } +} + function updateClaim(claimId, { status, reason, bounty }) { const claim = { action: 'update', @@ -180,5 +236,6 @@ module.exports = { getLoggedInUserStats, getClaimById, updateClaim, - getCounts + getCounts, + getConflictsReport } diff --git a/views/pages/claims/id.hbs b/views/pages/claims/id.hbs index b926288..d3f8733 100644 --- a/views/pages/claims/id.hbs +++ b/views/pages/claims/id.hbs @@ -1,7 +1,7 @@
+ {{#if claim.reason}}
+ Reason: {{claim.reason}}
+ {{/if}}
+
+ Project : {{claim.repo}}
+
+
+ Issue: {{claim.issueUrl}}
+
+
+ Pull Request: {{claim.pullUrl}}
+
+
+ {{#if claim.reason}}
+ Reason: {{claim.reason}}
+ {{/if}}
+
+ Project : {{claim.repo}}
+
+
+ Issue: {{claim.issueUrl}}
+
+
+ Pull Request: {{claim.pullUrl}}
+
+
+ {{#if claim.reason}}
+ Reason: {{claim.reason}}
+ {{/if}}
+
+ Project : {{claim.repo}}
+
+
+ Issue: {{claim.issueUrl}}
+
+
+ Pull Request: {{claim.pullUrl}}
+
+