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