const router = require('express').Router() import { Block } from '../db/models' import donate from '../donate' const limit = 50000 const order = [['id', 'DESC']] router.get('/', async (req: any, res: any, next: any) => { try { Block.findAll({ limit, order }).then((a: any) => res.json(a)) //Block.findAllWithIncludes().then((a: any) => res.json(a)) } catch (err) { next(err) } }) router.get('/offset/:offset', async (req: any, res: any, next: any) => { try { const { offset } = req.params Block.findAll({ limit, offset: offset, order }).then((a: any) => res.json(a) ) } catch (err) { next(err) } }) router.get('/page/:page', async (req: any, res: any, next: any) => { try { const { page } = req.params const offset = limit * page Block.findAll({ limit, offset, order }).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) => { res.status(402).send(donate) 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) => { res.status(402).send(donate) 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) => { res.status(402).send(donate) try { //Block.findByPk(req.params.id).then((account:any)=>res.json(account.delete()) } catch (err) { next(err) } }) module.exports = router