const router = require('express').Router() import { Category } from '../db/models' import donate from '../donate' router.get('/', async (req: any, res: any, next: any) => { try { Category.findAll().then((p: any) => res.json(p)) //Category.findAllWithIncludes().then((p: any) => res.json(p)) } catch (err) { next(err) } }) router.get('/:id', async (req: any, res: any, next: any) => { try { Category.findByIdWithIncludes(req.params.id).then((p: any) => res.json(p)) } catch (err) { next(err) } }) router.post('/', async (req: any, res: any, next: any) => { res.status(402).send(donate) try { Category.create(req.body).then((category: any) => Category.findByIdWithIncludes(category.id).then((p: any) => res.json(p)) ) } catch (err) { next(err) } }) router.put('/:id', async (req: any, res: any, next: any) => { res.status(402).send(donate) try { Category.findByPk(req.params.id).then((category: any) => category .update(req.body) .then(() => Category.findByIdWithIncludes(req.params.id).then((p: any) => res.json(p) ) ) ) } catch (err) { next(err) } }) router.post('/:id/delete', async (req: any, res: any, next: any) => { res.status(402).send(donate) try { //Category.findByPk(req.params.id).then((category:any)=>res.json(category.delete()) } catch (err) { next(err) } }) module.exports = router