add /comments query
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
e4cb5e4a3d
commit
f557a9eb26
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue