added functionality for user subscriptions

This commit is contained in:
Mikayla Dobson
2022-11-26 12:52:59 -06:00
parent 99c48d2a6e
commit 03ec2bf38c
18 changed files with 279 additions and 40 deletions

View File

@@ -1,4 +1,5 @@
import { Express, Router } from "express";
import { restrictAccess } from "../auth/middlewares";
import CollectionCtl from "../controllers/CollectionCtl";
const CollectionInstance = new CollectionCtl();
@@ -7,7 +8,7 @@ const router = Router();
export const collectionRoute = (app: Express) => {
app.use('/collection', router);
router.get('/:id', async (req, res, next) => {
router.get('/:id', restrictAccess, async (req, res, next) => {
const { id } = req.params;
try {
const result = await CollectionInstance.getOne(id);
@@ -17,7 +18,8 @@ export const collectionRoute = (app: Express) => {
}
})
router.get('/', async (req, res, next) => {
// implement is admin on this route
router.get('/', restrictAccess, async (req, res, next) => {
try {
const result = await CollectionInstance.getAll();
res.status(200).send(result);
@@ -26,7 +28,7 @@ export const collectionRoute = (app: Express) => {
}
})
router.post('/', async (req, res, next) => {
router.post('/', restrictAccess, async (req, res, next) => {
const data = req.body;
try {
const result = await CollectionInstance.post(data);
@@ -35,4 +37,31 @@ export const collectionRoute = (app: Express) => {
next(e);
}
})
// router.get('/subscriptions', restrictAccess, async (req, res, next) => {
// res.send('sanity check');
// // // @ts-ignore
// // const { user } = req.user;
// // if (!user) return;
// // try {
// // const result = await CollectionInstance.getSubscriptions("9");
// // res.status(200).send(result);
// // } catch(e) {
// // next(e);
// // }
// })
// router.post('/subscribe', restrictAccess, async (req, res, next) => {
// // @ts-ignore
// const { user } = req.user;
// const { collection } = req.query;
// try {
// const result = await CollectionInstance.postSubscription(collection as string, user.id as string);
// res.status(201).send(result);
// } catch(e) {
// next(e);
// }
// })
}