correct controller issues and add datapush
parent
6d36276c53
commit
852b44701d
|
@ -39,6 +39,7 @@ module.exports = {
|
|||
throw new HttpError(500, err.message)
|
||||
}
|
||||
await Book.update({ id: result.id }, { storage: uploaded[0].fd })
|
||||
sendUpdatesAsync(result.id)
|
||||
return res.json({
|
||||
...result
|
||||
})
|
||||
|
@ -70,3 +71,11 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function sendUpdatesAsync (id) {
|
||||
const book = await Book.find({ id })
|
||||
const targets = await TargetUri.find()
|
||||
for (const i in targets) {
|
||||
sails.log('sending ' + book.id + ' info to ' + targets[i].url)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,16 +22,22 @@ module.exports = {
|
|||
try {
|
||||
const id = req.param('id')
|
||||
const value = req.param('url')
|
||||
const url = await TargetUrl.update({ id, user: req.user.id }, { url: value }).fetch()
|
||||
return res.json(url)
|
||||
if (value.length) {
|
||||
const url = await TargetUrl.update({ id, user: req.user.id }, { url: value }).fetch()
|
||||
return res.json(url)
|
||||
} else {
|
||||
await TargetUrl.destroyOne({ id })
|
||||
return res.status(204).send()
|
||||
}
|
||||
} catch (e) {
|
||||
return (new HttpError(500, e.message)).send(res)
|
||||
}
|
||||
},
|
||||
delete: async function (req, res) {
|
||||
try {
|
||||
await TargetUrl.destroy({ id: req.param('id') })
|
||||
return res.status(204)
|
||||
const id = +req.param('id')
|
||||
await TargetUrl.destroyOne({ id })
|
||||
return res.status(204).send()
|
||||
} catch (e) {
|
||||
return (new HttpError(500, e.message)).send(res)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue