added course route

This commit is contained in:
Mikayla Dobson
2022-12-08 14:11:16 -06:00
parent 174866e254
commit 836b10379d
5 changed files with 123 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
import { Express, Router } from 'express';
import { CourseCtl } from '../controllers';
const CourseInstance = new CourseCtl();
const router = Router();
export const courseRouter = (app: Express) => {
app.use('/course', router);
router.get('/', async (req, res, next) => {
try {
const result = await CourseInstance.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 CourseInstance.getOne(id);
res.status(200).send(result);
} catch(e) {
next(e);
}
})
router.post('/', async (req, res, next) => {
const data = req.body;
try {
const result = await CourseInstance.post(data);
res.status(201).send(result);
} catch(e) {
next(e);
}
})
}

View File

@@ -9,6 +9,7 @@ import { authRoute } from "./auth";
import { subscriptionRoute } from "./subscription";
import { friendRouter } from "./friend";
import { cuisineRouter } from "./cuisine";
import { courseRouter } from "./course";
export const routes = async (app: Express, passport: PassportStatic) => {
console.log('routes called');
@@ -17,6 +18,7 @@ export const routes = async (app: Express, passport: PassportStatic) => {
userRoute(app);
friendRouter(app);
cuisineRouter(app);
courseRouter(app);
recipeRoute(app);
collectionRoute(app);
subscriptionRoute(app);