1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- const router = require('express').Router()
- import { Council } from '../db/models'
- router.get('/', async (req: any, res: any, next: any) => {
- try {
- 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) => {
- 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) => {
- 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) => {
- try {
- //Council.findByPk(req.params.id).then((member:any)=>res.json(member.delete())
- } catch (err) {
- next(err)
- }
- })
- module.exports = router
|