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