SHARE
TWEET

Untitled

Ahlushko Jun 25th, 2020 1,511 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Lab = require('./lab')
  2. const express = require('express')
  3. const router = express.Router()
  4.  
  5. router.get('/get', (req, res) => {
  6.     Lab.find({}, (err, doc)=> {
  7.         if(err) throw err
  8.         res.json(doc)
  9.     })
  10. })
  11. router.post('/create', (req,res)=> {
  12.     Lab.create({
  13.         surname: req.body.surname,
  14.         initials: req.body.initials,
  15.         title: req.body.title,
  16.         year: req.body.year
  17.     }, (err, doc)=> {
  18.         if(err) throw err
  19.         res.json(doc)
  20.     })
  21. })
  22. router.post('/delete', (req,res)=> {
  23.     if(JSON.stringify(req.body) == "{}"){
  24.         Lab.remove({}, (err,doc) => {
  25.             if(err) throw err
  26.             res.json({
  27.                 success: true,
  28.             })
  29.         })
  30.     } else {
  31.         Lab.remove(req.body, (err,doc)=>{
  32.             if(err) throw err
  33.             res.json({
  34.                 success: true,
  35.             })
  36.         })
  37.     }
  38. })
  39. router.post('/update', (req,res)=> {
  40.     Lab.updateOne({_id: req.body._id}, req.body, (err,doc)=> {
  41.         if(err) throw err
  42.         res.json()
  43.     })
  44. })
  45. module.exports = router
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top