index.js 1.01 KB
var express = require('express');
var createError = require('http-errors');
var router = express.Router();
const post = require('../../../model/video')

router.get('/list', (req, res, next) => {
  let { tag, skip } = req.query
  let joinedTag = tag.join("|")
  let regexsearch = { tag: { $regex: joinedTag, $options: 'si' }  }
  skip = parseInt(skip)
  post.find()
  .sort({'_id': -1})
  .limit(12)
  .skip(skip)
  .then(rs => {
    console.log(rs)
    res.send({ success: true, d: rs, })
  })
  .catch(e => {
    console.log(e)
    res.send({ success: false, msg: e.message })
  })
})

router.delete('/:_id', (req, res, next) => {
  const _id = req.params._id
  post.findOne({ _id })
    .then(r => {
      console.log(r)
      return post.deleteOne({ _id })
    })
    .then(r => {
      res.send({ success: true, d: r})
    })
    .catch(e => {
      console.log(e)
      res.send({ success: false, msg: e.message })
    })
})

router.all('*', function (req, res, next) {
  next(new Error ('Wrong Url!'));
});

module.exports = router;