add /comments query

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2018-12-13 12:47:39 +01:00
parent e4cb5e4a3d
commit f557a9eb26
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
2 changed files with 14 additions and 2 deletions

View File

@ -29,7 +29,6 @@ const App = (ghc) => {
body: ghc.db.schema,
},
handler: async (ctx) => {
/* TODO add validation of received JSON body */
await ghc.db.addBuild(ctx.params.pr, ctx.request.body)
await ghc.update(ctx.params.pr)
ctx.status = 201
@ -45,11 +44,15 @@ const App = (ghc) => {
})
router.get('/builds/:pr', async (ctx) => {
/* TODO add validation of id parameter */
const builds = await ghc.db.getBuilds(ctx.params.pr)
ctx.body = {count: builds.length, builds}
})
router.get('/comments', async (ctx) => {
const comments = await ghc.db.getComments()
ctx.body = {count: comments.length, comments}
})
return app
}

View File

@ -72,6 +72,15 @@ class Builds {
const rval = await this.comments.findOne({pr: pr})
return rval ? rval.comment_id : null
}
async getComments (pr) {
const comments = await this.comments.chain().simplesort('pr').data();
/* strip the loki attributes */
return comments.map((c) => {
const {$loki, meta, ...comment} = c
return comment
})
}
}
module.exports = Builds