const router = require('express').Router() import { Block } from '../db/models' router.get('/', async (req: any, res: any, next: any) => { try { Block.findAll({ limit: 10000, order: [['id', 'DESC']] }).then((a: any) => res.json(a) ) //Block.findAllWithIncludes().then((a: any) => res.json(a)) } catch (err) { next(err) } }) router.get('/:id', async (req: any, res: any, next: any) => { try { Block.findByIdWithIncludes(req.params.id).then((a: any) => res.json(a)) } catch (err) { next(err) } }) router.post('/', async (req: any, res: any, next: any) => { try { Block.create(req.body).then((account: any) => Block.findByIdWithIncludes(account.id).then((a: any) => res.json(a)) ) } catch (err) { next(err) } }) router.put('/:id', async (req: any, res: any, next: any) => { try { Block.findByPk(req.params.id).then((account: any) => account .update(req.body) .then(() => Block.findByIdWithIncludes(req.params.id).then((a: any) => res.json(a) ) ) ) } catch (err) { next(err) } }) router.post('/:id/delete', async (req: any, res: any, next: any) => { try { //Block.findByPk(req.params.id).then((account:any)=>res.json(account.delete()) } catch (err) { next(err) } }) module.exports = router