Compare commits

...

4 Commits

Author SHA1 Message Date
ab90aba67b Merge pull request 'Share: Provide API-endpoint for items collection' (#3) from dev into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #3
2023-02-17 10:27:31 +01:00
Artem Anufrij
1c8163c835 config for production
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing
2023-02-17 10:24:41 +01:00
Artem Anufrij
481966768d code style fix #2
All checks were successful
continuous-integration/drone/push Build is passing
2023-02-17 10:23:34 +01:00
Artem Anufrij
5f9d438420 share: provide collection api fix#2
All checks were successful
continuous-integration/drone/push Build is passing
2023-02-17 10:21:58 +01:00
2 changed files with 23 additions and 4 deletions

View File

@ -3,10 +3,20 @@ var express = require("express");
var router = new express.Router();
const database = require("../services/database");
router.route("/:id").get((req, res) => {
database.share.byId(req.params.id, (result) => {
res.json(result).status(200).end();
const server = require("../server");
var passport = server.passport;
router.route("/")
.get(passport.authenticate("jwt", { session: false }), (req, res) => {
database.share.collection(result => {
res.json(result).status(200).end();
})
});
router.route("/:id")
.get((req, res) => {
database.share.byId(req.params.id, result => {
res.json(result).status(200).end();
});
});
});
module.exports = router;

View File

@ -42,6 +42,15 @@ exports.byId = function (id, callback) {
});
}
exports.collection = function (callback) {
dbo.collection("shares")
.find({})
.toArray((err, result) => {
if (err) throw err;
cb(callback, result);
});
}
exports.exists = function (object_id, callback) {
dbo.collection("shares")
.findOne({ object_id: ObjectId(object_id) })