eras.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const router = require('express').Router()
  2. import { Era } from '../db/models'
  3. import donate from '../donate'
  4. router.get('/', async (req: any, res: any, next: any) => {
  5. try {
  6. //Era.findAllWithIncludes().then((a: any) => res.json(a))
  7. Era.findAll().then((a: any) => res.json(a))
  8. } catch (err) {
  9. next(err)
  10. }
  11. })
  12. router.get('/:id', async (req: any, res: any, next: any) => {
  13. try {
  14. Era.findByIdWithIncludes(req.params.id).then((a: any) => res.json(a))
  15. } catch (err) {
  16. next(err)
  17. }
  18. })
  19. router.post('/', async (req: any, res: any, next: any) => {
  20. res.status(402).send(donate)
  21. try {
  22. Era.create(req.body).then((account: any) =>
  23. Era.findByIdWithIncludes(account.id).then((a: any) => res.json(a))
  24. )
  25. } catch (err) {
  26. next(err)
  27. }
  28. })
  29. router.put('/:id', async (req: any, res: any, next: any) => {
  30. res.status(402).send(donate)
  31. try {
  32. Era.findByPk(req.params.id).then((account: any) =>
  33. account
  34. .update(req.body)
  35. .then(() =>
  36. Era.findByIdWithIncludes(req.params.id).then((a: any) => res.json(a))
  37. )
  38. )
  39. } catch (err) {
  40. next(err)
  41. }
  42. })
  43. router.post('/:id/delete', async (req: any, res: any, next: any) => {
  44. res.status(402).send(donate)
  45. try {
  46. //Era.findByPk(req.params.id).then((account:any)=>res.json(account.delete())
  47. } catch (err) {
  48. next(err)
  49. }
  50. })
  51. module.exports = router