ingredient route
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Express, Router } from "express";
|
||||
import { GroceryListCtl } from "../controllers";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -18,6 +19,6 @@ export const groceryListRoute = (app: Express) => {
|
||||
})
|
||||
|
||||
router.put('/:id', async (req, res, next) => {
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { Express } from "express"
|
||||
import { userRoute } from "./users";
|
||||
import { recipeRoute } from "./recipe";
|
||||
import { collectionRoute } from "./collection";
|
||||
import { ingredientRoute } from "./ingredient";
|
||||
|
||||
export const routes = (app: Express, passport?: any) => {
|
||||
console.log('routes called');
|
||||
@@ -9,6 +10,7 @@ export const routes = (app: Express, passport?: any) => {
|
||||
userRoute(app);
|
||||
recipeRoute(app);
|
||||
collectionRoute(app);
|
||||
ingredientRoute(app);
|
||||
|
||||
app.get('/hello', (req, res) => {
|
||||
res.send({ message: "hello from the server!!" });
|
||||
|
||||
@@ -1,22 +1,52 @@
|
||||
import { Express, Router } from "express";
|
||||
import { IngredientCtl } from "../controllers";
|
||||
const IngredientInstance = new IngredientCtl();
|
||||
|
||||
const router = Router();
|
||||
|
||||
export const ingredientRoute = (app: Express) => {
|
||||
app.use('/ingredient', router);
|
||||
|
||||
router.get('/', async (req, res, next) => {
|
||||
|
||||
try {
|
||||
const result = await IngredientInstance.getAll();
|
||||
res.status(200).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/:id', async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
try {
|
||||
const result = await IngredientInstance.getOne(id);
|
||||
res.status(200).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
})
|
||||
|
||||
router.put('/:id', async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
const data = req.body;
|
||||
|
||||
try {
|
||||
const result = await IngredientInstance.put(id, data);
|
||||
res.status(200).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/', async (req, res, next) => {
|
||||
|
||||
const data = req.body;
|
||||
|
||||
try {
|
||||
const result = await IngredientInstance.post(data);
|
||||
res.status(201).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user