-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
80 lines (62 loc) · 2.05 KB
/
main.js
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
var sortBy = require('sort-array')
var restify = require('restify')
var rsvp = require('rsvp')
var Board = require('./Board')
var JiraQuerry = require('./JiraQuerry')
var Sprint = require('./Sprint')
var SprintDataExtractor = require('./SprintDataExtractor')
var port = 3001
var server = restify.createServer()
server.use(restify.fullResponse())
server.use(restify.bodyParser({ mapParams: true }))
server.use(
function crossOrigin(req,res,next){
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "X-Requested-With")
return next()
}
)
server.get("/jiradata/sprinthistory", function(req, res, next) {
var boardId = 159;
res.setHeader('Access-Control-Allow-Origin', '*');
var board = new Board(boardId)
board.getSprints().then(function(result) {
handleSprints(boardId, result).then(function(sprintHistory) {
res.json(sprintHistory);
})
})
next();
});
server.listen(port, function (err) {
if (err) {
console.error(err)
return 1
} else {
return 0
}
})
function handleSprints(boardId, result) {
var order = [];
var sprintHistory = [];
var promise = new rsvp.Promise(function(resolve) {
for(var i = 0; i < result.length; i++) {
order.push(result[i]);
var sprint = new Sprint(boardId, result[i])
sprint.getSprint().then(function(sprint) {
sprintDataExtractor = new SprintDataExtractor()
sprintHistory.push(sprintDataExtractor.extractData(sprint))
if(sprintHistory.length == result.length) {
sortBy(sprintHistory, "id", { id: order })
jiraQuerry = new JiraQuerry()
var currentSprintname = sprintHistory[result.length-1].sprintName
jiraQuerry.getSprintGoals(currentSprintname).then( function(querryResult) {
var sprintGoals = sprintDataExtractor.extractSprintGoals(querryResult);
sprintHistory[result.length-1].sprintGoals = sprintGoals;
resolve(sprintHistory)
})
}
})
}
})
return promise
}