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