diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-12-15 08:06:25 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-12-15 08:06:25 +0100 |
| commit | fe69052c4b6f180739b713d4c2ef495c3efc4bf2 (patch) | |
| tree | 55d552c827dd48d2baf425f7235099c408413b0b | |
| parent | e21b3dd61e917f4cd8ebd210f5776d33b4ea584a (diff) | |
fix
| -rw-r--r-- | bucky/app/federate.js | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/bucky/app/federate.js b/bucky/app/federate.js index 451908b..d4ce3e6 100644 --- a/bucky/app/federate.js +++ b/bucky/app/federate.js @@ -4,10 +4,10 @@ var db = require('../db') module.exports = { route: (app) => { - app.put('/raw/import/thread/', importRaw('thread', 'Thread'), (req, res) => res.send({ status: 'ok' })) - app.put('/raw/import/keyword/', importRaw('keyword', 'Keyword'), (req, res) => res.send({ status: 'ok' })) - app.put('/raw/import/file/', importRaw('file', 'File'), (req, res) => res.send({ status: 'ok' })) - app.put('/raw/import/comment/', importRaw('comment', 'Comment'), (req, res) => res.send({ status: 'ok' })) + app.put('/raw/import/thread/', importRaw('thread', 'Thread'), (req, res) => res.send({ status: 'ok', el: res.el })) + app.put('/raw/import/keyword/', importRaw('keyword', 'Keyword'), (req, res) => res.send({ status: 'ok', el: res.el })) + app.put('/raw/import/file/', importRaw('file', 'File'), (req, res) => res.send({ status: 'ok', el: res.el })) + app.put('/raw/import/comment/', importRaw('comment', 'Comment'), (req, res) => res.send({ status: 'ok', el: res.el })) app.get('/raw/export/thread/:id', exportThread, (req, res) => res.send({ status: 'ok' })) app.get('/raw/export/keyword/:keyword', exportKeyword, (req, res) => res.send({ status: 'ok' })) @@ -15,6 +15,7 @@ module.exports = { function importRaw (type, model) { return (req, res, next) => { console.log('importing', type, req.body.id) + delete req.body.id db[model].forge(req.body).save().then((el) => { res.el = el; next() @@ -39,16 +40,26 @@ module.exports = { }) } function exportThread (req, res, next) { + var thread_id return db.getThread(req.params.id).then(thread => { - send("thread", thread) + return send("thread", thread) + }).then(json => { + thread_id = json.id + console.log('got thread id', thread_id) return db.getCommentsForThread(req.params.id) }).then(comments => { - var promises = comments.map(comment => send("comment", comment)) + var promises = comments.map(comment => { + comment.set('thread', thread_id) + send("comment", comment) + }) return Promise.all(promises) }).then( () => { return db.getFilesForThread(req.params.id) }).then(files => { - var promises = files.map(comment => send("comment", comment)) + var promises = files.map(file => { + file.set('thread', thread_id) + send("file", file) + }) return promises }).then( () => { next() @@ -68,7 +79,6 @@ module.exports = { 'Accept': 'application/json', }, }).then((res) => {return res.json()}) - .then((json) => console.log(json)) } } |
