123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- const router = require('express').Router()
- import { Post } from '../db/models'
- import donate from '../donate'
- router.get('/', async (req: any, res: any, next: any) => {
- try {
- Post.findAll().then((p: any) => res.json(p))
- //Post.findAllWithIncludes().then((p: any) => res.json(p))
- } catch (err) {
- next(err)
- }
- })
- router.get('/:id', async (req: any, res: any, next: any) => {
- try {
- Post.findByIdWithIncludes(req.params.id).then((p: any) => res.json(p))
- } catch (err) {
- next(err)
- }
- })
- router.post('/', async (req: any, res: any, next: any) => {
- res.status(402).send(donate)
- try {
- Post.create(req.body).then((post: any) =>
- Post.findByIdWithIncludes(post.id).then((p: any) => res.json(p))
- )
- } catch (err) {
- next(err)
- }
- })
- router.put('/:id', async (req: any, res: any, next: any) => {
- res.status(402).send(donate)
- try {
- Post.findByPk(req.params.id).then((post: any) =>
- post
- .update(req.body)
- .then(() =>
- Post.findByIdWithIncludes(req.params.id).then((p: any) => res.json(p))
- )
- )
- } catch (err) {
- next(err)
- }
- })
- router.post('/:id/delete', async (req: any, res: any, next: any) => {
- res.status(402).send(donate)
- try {
- //Post.findByPk(req.params.id).then((post:any)=>res.json(post.delete())
- } catch (err) {
- next(err)
- }
- })
- module.exports = router
|