12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- const router = require('express').Router()
- import { Account } from '../db/models'
- router.get('/', async (req: any, res: any, next: any) => {
- try {
- //Account.findAllWithIncludes().then((a: any) => res.json(a))
- Account.findAll().then((a: any) => res.json(a))
- } catch (err) {
- next(err)
- }
- })
- router.get('/:id', async (req: any, res: any, next: any) => {
- try {
- Account.findByIdWithIncludes(req.params.id).then((a: any) => res.json(a))
- } catch (err) {
- next(err)
- }
- })
- router.post('/', async (req: any, res: any, next: any) => {
- try {
- Account.create(req.body).then((account: any) =>
- Account.findByIdWithIncludes(account.id).then((a: any) => res.json(a))
- )
- } catch (err) {
- next(err)
- }
- })
- router.put('/:id', async (req: any, res: any, next: any) => {
- try {
- Account.findByPk(req.params.id).then((account: any) =>
- account
- .update(req.body)
- .then(() =>
- Account.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 {
- //Account.findByPk(req.params.id).then((account:any)=>res.json(account.delete())
- } catch (err) {
- next(err)
- }
- })
- module.exports = router
|