attempted to refactor db seed, still needs more updating
This commit is contained in:
6
server/routes/comment.ts
Normal file
6
server/routes/comment.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Express, Router } from "express"
|
||||
const router = Router();
|
||||
|
||||
export const commentRoute = (app: Express) => {
|
||||
app.use('/comment', router);
|
||||
}
|
||||
@@ -49,9 +49,10 @@ export const friendRouter = (app: Express) => {
|
||||
router.put('/:id', async (req, res, next) => {
|
||||
const data = req.body;
|
||||
const { id } = req.params;
|
||||
const { user }: any = req.user;
|
||||
|
||||
try {
|
||||
const result = await UserInstance.updateFriendship(id, data);
|
||||
const result = await UserInstance.updateFriendship(id, user.id, data);
|
||||
res.status(200).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Express, Router } from "express"
|
||||
import { restrictAccess } from "../auth/middlewares";
|
||||
import RecipeCtl from "../controllers/RecipeCtl";
|
||||
const recipectl = new RecipeCtl();
|
||||
|
||||
@@ -18,6 +19,27 @@ export const recipeRoute = (app: Express) => {
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/', async (req, res, next) => {
|
||||
const { user }: any = req.user;
|
||||
const { filterby } = req.query;
|
||||
|
||||
try {
|
||||
let result;
|
||||
switch (filterby) {
|
||||
case "allaccessible":
|
||||
result = await recipectl.getAllAccessible(user.id);
|
||||
break;
|
||||
default:
|
||||
result = await recipectl.getAllAuthored(user.id);
|
||||
break;
|
||||
}
|
||||
|
||||
res.status(200).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
})
|
||||
|
||||
router.put('/:id', async (req, res, next) => {
|
||||
const data = req.body;
|
||||
const { id } = req.params;
|
||||
@@ -30,12 +52,12 @@ export const recipeRoute = (app: Express) => {
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/', async (req, res, next) => {
|
||||
router.post('/', restrictAccess, async (req, res, next) => {
|
||||
const { user }: any = req.user;
|
||||
const data = req.body;
|
||||
console.log(data);
|
||||
|
||||
try {
|
||||
const result = await recipectl.post(data);
|
||||
const result = await recipectl.post(user.id, data);
|
||||
res.status(201).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
|
||||
Reference in New Issue
Block a user