|
| 1 | +const express = require('express'); |
| 2 | +const bodyParser = require('body-parser'); |
| 3 | + |
| 4 | +const promoRouter = express.Router(); |
| 5 | + |
| 6 | +promoRouter.use(bodyParser.json()); |
| 7 | + |
| 8 | +promoRouter.route('/') |
| 9 | +.all((req, res, next) => { |
| 10 | + res.statusCode = 200; |
| 11 | + res.setHeader('Content-Type', 'text/plain'); |
| 12 | + next(); |
| 13 | +}) |
| 14 | +.get((req, res, next) => { |
| 15 | + res.end('Will send all the promotions to you!'); |
| 16 | +}) |
| 17 | +.post((req, res, next) => { |
| 18 | + res.end('Will add the promotions: ' + req.body.name + ' with details: ' + req.body.description); |
| 19 | +}) |
| 20 | +.put((req, res, next) => { |
| 21 | + res.statusCode = 403; |
| 22 | + res.end('PUT operation not supported on /promotions'); |
| 23 | +}) |
| 24 | +.delete((req, res, next) => { |
| 25 | + res.end('Deleting all promotions'); |
| 26 | +}); |
| 27 | + |
| 28 | + |
| 29 | +//promo Id |
| 30 | +promoRouter.route('/:promoId') |
| 31 | +.all((req,res,next) => { |
| 32 | + res.statusCode = 200; |
| 33 | + res.setHeader('Content-Type', 'text/plain'); |
| 34 | + next(); |
| 35 | +}) |
| 36 | +.get((req,res,next) => { |
| 37 | + res.end(`Will send all the promotion ${req.params.promoId} to you!`); |
| 38 | +}) |
| 39 | +.post((req, res, next) => { |
| 40 | + res.end(`Updating the promotion ${req.params.promoId} \n Will add the promotion ${req.params.promoId} : ${req.body.name} with details: ${req.body.description}`); |
| 41 | +}) |
| 42 | +.put((req, res, next) => { |
| 43 | + res.statusCode = 403; |
| 44 | + res.end(`PUT operation not supported on /promotion ${req.params.promoId}`); |
| 45 | +}) |
| 46 | +.delete((req, res, next) => { |
| 47 | + res.end(`Deleting promotion ${req.params.promoId}`); |
| 48 | +}); |
| 49 | + |
| 50 | +module.exports = promoRouter; |
0 commit comments