-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdebounced.coffee
42 lines (34 loc) · 1 KB
/
debounced.coffee
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
express = require 'express'
bodyParser = require 'body-parser'
{trello, db,
queueApplyMirror} = require './setup'
app = express()
app.use bodyParser.json()
app.post '/refetch-checklists', (request, response) ->
options = request.body.merge.options
delete request.body.merge.options
for id of request.body.merge
(->
cardId = id
if options and options[cardId]
applyMirror = options[cardId].applyMirror
else
applyMirror = false
console.log '-> refetching checklists for', cardId
trello.get "/1/cards/#{cardId}", {
fields: 'id'
checkItemStates: 'true'
checkItemState_fields: 'idCheckItem,state'
checklists: 'all'
checklist_fields: 'name,pos'
}, (err, data) ->
db.cards.update(
{ _id: cardId }
{ $set: { checklists: data.checklists } }
).then(->
if applyMirror
queueApplyMirror 'checklists', cardId
)
)()
response.send 'ok'
module.exports = app