-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathapi.js
More file actions
86 lines (75 loc) · 2.05 KB
/
api.js
File metadata and controls
86 lines (75 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Created by championswimmer on 15/05/17.
*/
const Router = require('express').Router
const auth = require('./../utils/auth')
const config = require('./../config')
const du = require('./../utils/datautils')
const { BOSS_END_DATE, BOSS_START_DATE } = require('./../utils/consts')
const route = new Router()
route.get('/claims', (req, res) => {
const options = {
status: req.query.status || 'claimed',
page: req.query.page || 1,
size: req.query.size || config.PAGINATION_SIZE
}
du.getClaims(options)
.then(data => {
res.send(data)
})
.catch(err => {
console.log(err)
res.status(500).send('Sorry! Could not get the claims right now.')
})
})
route.get('/claims/:id/delete', auth.adminOnly, (req, res) => {
du.delClaim(req.params.id)
.then(result => {
res.send({ result: result })
})
.catch(err => {
console.log(err)
res.status(500).send('Sorry! Could not delete the claim right now.')
})
})
route.get('/claims/:id/update', auth.adminOnly, (req, res) => {
//TODO: For authorised requests only
du.updateClaim(req.params.id, req.query)
.then(result => {
res.send({ result: result })
})
.catch(err => {
console.log(err)
res.status(500).send('Sorry! Could not update the claim right now.')
})
})
route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => {
if (process.env.BOSS_DEV === 'localhost') {
req.user = {
usergithub: {
username: 'Dhroov7'
}
}
}
if (Date.now() > BOSS_END_DATE.getTime()) {
return res.send("Sorry! Boss has ended. You can't add claim from now.")
}
if (Date.now() < BOSS_START_DATE.getTime()) {
return res.send("Sorry! BOSS has not yet started")
}
du.createClaim(
req.user.usergithub.username,
req.body.issue_url,
req.body.pull_url,
req.body.bounty,
config.CLAIM_STATUS.CLAIMED
)
.then(claim => {
res.send(claim)
})
.catch(err => {
console.log(err)
res.send('Sorry! Could not add the claim right now.')
})
})
module.exports = route