1
0

accounts.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const router = require('express').Router()
  2. import { Account } from '../db/models'
  3. import donate from '../donate'
  4. router.get('/', async (req: any, res: any, next: any) => {
  5. try {
  6. //Account.findAllWithIncludes().then((a: any) => res.json(a))
  7. Account.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. Account.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. Account.create(req.body).then((account: any) =>
  23. Account.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. Account.findByPk(req.params.id).then((account: any) =>
  33. account
  34. .update(req.body)
  35. .then(() =>
  36. Account.findByIdWithIncludes(req.params.id).then((a: any) =>
  37. res.json(a)
  38. )
  39. )
  40. )
  41. } catch (err) {
  42. next(err)
  43. }
  44. })
  45. router.post('/:id/delete', async (req: any, res: any, next: any) => {
  46. res.status(402).send(donate)
  47. try {
  48. //Account.findByPk(req.params.id).then((account:any)=>res.json(account.delete())
  49. } catch (err) {
  50. next(err)
  51. }
  52. })
  53. module.exports = router