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