recipe route
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { Express } from "express"
|
||||
import { userRoute } from "./users";
|
||||
import { recipeRoute } from "./recipe";
|
||||
|
||||
export const routes = (app: Express, passport?: any) => {
|
||||
console.log('routes called');
|
||||
|
||||
userRoute(app);
|
||||
recipeRoute(app);
|
||||
|
||||
app.get('/hello', (req, res) => {
|
||||
res.send({ message: "hello from the server!!" });
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Express, Router } from "express"
|
||||
import RecipeCtl from "../controllers/RecipeCtl";
|
||||
const recipectl = new RecipeCtl();
|
||||
|
||||
const router = Router();
|
||||
|
||||
export const recipeRoute = (app: Express) => {
|
||||
app.use('/recipe', router);
|
||||
|
||||
router.get('/:id', async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
console.log('/recipe/' + id + ' called');
|
||||
|
||||
try {
|
||||
const result = await recipectl.getOne(id);
|
||||
res.status(200).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
})
|
||||
|
||||
router.put('/:id', async (req, res, next) => {
|
||||
const data = req.body;
|
||||
const { id } = req.params;
|
||||
|
||||
try {
|
||||
const result = await recipectl.updateOne(id, data);
|
||||
res.status(200).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/', async (req, res, next) => {
|
||||
const data = req.body;
|
||||
console.log(data);
|
||||
|
||||
try {
|
||||
const result = await recipectl.post(data);
|
||||
res.status(201).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import pool from '../db';
|
||||
import { Express, Router } from 'express';
|
||||
import UserCtl from '../controllers/UserCtl';
|
||||
const router = Router();
|
||||
|
||||
Reference in New Issue
Block a user