support on collection route
This commit is contained in:
@@ -1,14 +1,36 @@
|
||||
import { Express, Router } from "express";
|
||||
import CollectionCtl from "../controllers/CollectionCtl";
|
||||
const CollectionInstance = new CollectionCtl();
|
||||
|
||||
const router = Router();
|
||||
|
||||
const collectionRoute = (app: Express) => {
|
||||
export const collectionRoute = (app: Express) => {
|
||||
app.use('/collection', router);
|
||||
|
||||
router.get('/:id', async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
try {
|
||||
|
||||
const result = await CollectionInstance.getOne(id);
|
||||
res.status(200).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/', async (req, res, next) => {
|
||||
try {
|
||||
const result = await CollectionInstance.getAll();
|
||||
res.status(200).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/', async (req, res, next) => {
|
||||
const data = req.body;
|
||||
try {
|
||||
const result = await CollectionInstance.post(data);
|
||||
res.status(201).send(result);
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { Express } from "express"
|
||||
import { userRoute } from "./users";
|
||||
import { recipeRoute } from "./recipe";
|
||||
import { collectionRoute } from "./collection";
|
||||
|
||||
export const routes = (app: Express, passport?: any) => {
|
||||
console.log('routes called');
|
||||
|
||||
userRoute(app);
|
||||
recipeRoute(app);
|
||||
collectionRoute(app);
|
||||
|
||||
app.get('/hello', (req, res) => {
|
||||
res.send({ message: "hello from the server!!" });
|
||||
|
||||
@@ -9,7 +9,6 @@ export const recipeRoute = (app: Express) => {
|
||||
|
||||
router.get('/:id', async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
console.log('/recipe/' + id + ' called');
|
||||
|
||||
try {
|
||||
const result = await recipectl.getOne(id);
|
||||
|
||||
Reference in New Issue
Block a user