rubberguppe/routes/inbox.js

34 lines
947 B
JavaScript
Raw Normal View History

const express = require('express')
const router = express.Router()
const utils = require('../utils')
2018-09-15 07:01:19 +00:00
router.post('/', utils.validators.activity, function (req, res) {
const db = req.app.get('db');
req.body._target = req.user
Promise.all([
db.collection('objects').insertOne(req.body.object),
db.collection('streams').insertOne(req.body)
]).then(() => res.status(200).send())
.catch(err => {
console.log(err)
res.status(500).send()
})
2018-09-15 07:01:19 +00:00
});
router.get('/', function (req, res) {
const db = req.app.get('db');
db.collection('streams')
.find({_target: req.user})
.sort({_id: -1})
2019-09-15 02:49:33 +00:00
.project({_id: 0, _target: 0, _meta: 0, '@context': 0, 'object._id': 0, 'object.@context': 0, 'objecct._meta': 0})
.toArray()
.then(stream => res.json(utils.arrayToCollection(stream, true)))
.catch(err => {
console.log(err)
return res.status(500).send()
})
;
})
2018-09-15 07:01:19 +00:00
module.exports = router;