2023-02-16 18:19:42 +01:00
|
|
|
console.log("router/share INIT");
|
|
|
|
var express = require("express");
|
|
|
|
var router = new express.Router();
|
|
|
|
const database = require("../services/database");
|
|
|
|
|
2023-02-17 10:21:58 +01:00
|
|
|
const server = require("../server");
|
|
|
|
var passport = server.passport;
|
|
|
|
|
|
|
|
router.route("/")
|
|
|
|
.get(passport.authenticate("jwt", { session: false }), (req, res) => {
|
2023-02-17 22:20:09 +01:00
|
|
|
if (req.user.roles.includes("admin")) {
|
|
|
|
database.share.collection(result => {
|
|
|
|
res.json(result).status(200).end();
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
res.status(403).end();
|
|
|
|
}
|
2023-02-17 10:23:34 +01:00
|
|
|
});
|
2023-02-17 10:21:58 +01:00
|
|
|
router.route("/:id")
|
|
|
|
.get((req, res) => {
|
|
|
|
database.share.byId(req.params.id, result => {
|
|
|
|
res.json(result).status(200).end();
|
2023-02-16 18:19:42 +01:00
|
|
|
});
|
2023-02-17 10:21:58 +01:00
|
|
|
});
|
2023-02-16 18:19:42 +01:00
|
|
|
|
|
|
|
module.exports = router;
|