Fix db relations, add sample data, show categories in frontend menu
This commit is contained in:
22
software/backend/routes/category.routes.ts
Normal file
22
software/backend/routes/category.routes.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Router, Request, Response, NextFunction } from "express";
|
||||
import { Category } from "../models/category.model";
|
||||
|
||||
export const category = Router()
|
||||
|
||||
category.get("/", (req: Request, res: Response, next: NextFunction) => {
|
||||
Category.findAll()
|
||||
.then(categories => {
|
||||
res.json(categories)
|
||||
})
|
||||
.catch(next)
|
||||
})
|
||||
|
||||
category.post("/", (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
console.log(req.body)
|
||||
const category = Category.create(req.body)
|
||||
res.status(201).json(category)
|
||||
} catch (e) {
|
||||
next(e)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user