const router = require('express').Router() import { Proposal } from '../db/models' import donate from '../donate' router.get('/', async (req: any, res: any, next: any) => { try { Proposal.findAllWithIncludes().then((p: any) => res.json(p)) } catch (err) { next(err) } }) router.get('/:id', async (req: any, res: any, next: any) => { try { Proposal.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 { Proposal.create(req.body).then((proposal: any) => Proposal.findByIdWithIncludes(proposal.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 { Proposal.findByPk(req.params.id).then((proposal: any) => proposal .update(req.body) .then(() => Proposal.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 { //Proposal.findByPk(req.params.id).then((proposal:any)=>res.json(proposal.delete()) } catch (err) { next(err) } }) module.exports = router