/
lists.js
executable file
·43 lines (36 loc) · 1.16 KB
/
lists.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
#!/usr/bin/env node
var util = require('util');
var Lists = module.exports = function (trello, boardPromise) {
this.trello = trello;
this.current = boardPromise.then(function (board) {
return trello.get(util.format('/1/boards/%s/lists', board.id)).then(function (lists) {
var map = {};
lists.forEach(function(list){
if (!map[list.name]) {
map[list.name] = [];
}
map[list.name].push(list);
});
for (key in map) {
if (map.hasOwnProperty(key)) {
map[key] = Promise.resolve(map[key]);
}
}
return {board: board, map: map};
});
});
};
Lists.prototype.getList = function(name) {
var self = this;
return self.current.then(function(current) {
if (!current.map[name]) {
current.map[name] = self.trello.post('/1/lists', {
name: name,
idBoard: current.board.id
}).then(function (list) {
return [list];
});
}
return current.map[name];
});
};