text: /**
   * Created by xbh 2019-06-12 文章类型API
   */
  var express = require('express');
  var router = express.Router();
  const result = require('../../util/result-util');
  const typeService = require('../../service/type-service');
  
  /**
   * @api {post} /admin/type/create 添加文章类型
   * @apiGroup type
   * @apiVersion 1.0.0
   * @apiName create
   * @apiParam {String} [name] 名称
   * @apiParam {Number} [categoryId] 文章类型ID
   * @apiSuccessExample {json} Success-Response:
   *  HTTP/1.1 200 OK
   * {
   *  "code": 200,
   *  "message": "操作成功",
   *  "data": 1
   * }
   * @apiErrorExample {json} Error-Response:
   *  HTTP/1.1 500 error
   * {
   *  "code": 500,
   *  "message": "操作失败",
   * }
   * @apiSampleRequest /admin/type/create
   */
  router.post('/create', function (req, res, next) {
      let type = req.body;
      typeService.add(type).then(data => {
          let {affectedRows} = data;
          if (affectedRows > 0) res.json(result.success(affectedRows));
          else res.json(result.failed);
      }).catch(e => res.json(result.exceptionFailed(e.message)));
  });
  
  /**
   * @api {delete} /admin/type/delete/{id} 删除文章类型
   * @apiGroup type
   * @apiVersion 1.0.0
   * @apiName delete
   * @apiParam {Number} [id] ID
   * @apiSuccessExample {json} Success-Response:
   *  HTTP/1.1 200 OK
   * {
   *  "code": 200,
   *  "message": "操作成功",
   *  "data": 1
   * }
   * @apiErrorExample {json} Error-Response:
   *  HTTP/1.1 500 error
   * {
   *  "code": 500,
   *  "message": "操作失败",
   * }
   * @apiSampleRequest /admin/type/delete/:id
   */
  router.delete('/delete/:id', function (req, res, next) {
      let {id} = req.params;
      typeService.del(id).then(data => {
          let {affectedRows} = data;
          if (affectedRows > 0) res.json(result.success(affectedRows));
          else res.json(result.failed);
      }).catch(e => res.json(result.exceptionFailed(e.message)));
  });
  
  /**
   * @api {put} /admin/type/update/{id} 修改文章类型
   * @apiGroup type
   * @apiVersion 1.0.0
   * @apiName update
   * @apiParam {Number} [id] ID
   * @apiParam {String} [name] 名称
   * @apiParam {Number} [contentNum] 文章数
   * @apiParam {Number} [categoryId] 分类ID
   * @apiSuccessExample {json} Success-Response:
   *  HTTP/1.1 200 OK
   * {
   *  "code": 200,
   *  "message": "操作成功",
   *  "data": 1
   * }
   * @apiErrorExample {json} Error-Response:
   *  HTTP/1.1 500 error
   * {
   *  "code": 500,
   *  "message": "操作失败",
   * }
   * @apiSampleRequest /admin/type/update/:id
   */
  router.put('/update/:id', function (req, res, next) {
      let {id} = req.params;
      let type = req.body;
      typeService.modify(id, type).then(data => {
          let {affectedRows} = data;
          if (affectedRows > 0) res.json(result.success(affectedRows));
          else res.json(result.failed);
      }).catch(e => res.json(result.exceptionFailed(e.message)));
  });
  
  /**
   * @api {put} /admin/type/addContentNum/{id} 添加文章数
   * @apiGroup type
   * @apiVersion 1.0.0
   * @apiName update
   * @apiParam {Number} [id] ID
   * @apiSuccessExample {json} Success-Response:
   *  HTTP/1.1 200 OK
   * {
   *  "code": 200,
   *  "message": "操作成功",
   *  "data": 1
   * }
   * @apiErrorExample {json} Error-Response:
   *  HTTP/1.1 500 error
   * {
   *  "code": 500,
   *  "message": "操作失败",
   * }
   * @apiSampleRequest /admin/type/addContentNum/:id
   */
  router.put('/addContentNum/:id', function (req, res, next) {
      let {id} = req.params;
      typeService.addContentNum(id).then(data => {
          let {affectedRows} = data;
          if (affectedRows > 0) res.json(result.success(affectedRows));
          else res.json(result.failed);
      }).catch(e => res.json(result.exceptionFailed(e.message)));
  });
  
  /**
   * @api {get} /admin/type/list 获取列表
   * @apiGroup type
   * @apiVersion 1.0.0
   * @apiName list
   * @apiSuccessExample {json} Success-Response:
   *  HTTP/1.1 200 OK
   * {
   *  "code": 200,
   *  "message": "操作成功",
   *  "data": 1
   * }
   * @apiErrorExample {json} Error-Response:
   *  HTTP/1.1 500 error
   * {
   *  "code": 500,
   *  "message": "操作失败",
   * }
   * @apiSampleRequest /admin/type/list
   */
  router.get('/list', function (req, res, next) {
      let {categoryId, pageNum, pageSize} = req.query;
      typeService.list(categoryId, pageNum, pageSize).then(data => {
          if (data) res.json(result.success(data));
          else res.json(result.failed);
      }).catch(e => res.json(result.exceptionFailed(e.message)));
  });
  
  
  /**
   * @api {get} /admin/type/categoryList 文章类型列表
   * @apiGroup type
   * @apiVersion 1.0.0
   * @apiName categoryList
   * @apiParam {Number} [categoryId] 分类ID
   * @apiSuccessExample {json} Success-Response:
   *  HTTP/1.1 200 OK
   * {
   *  "code": 200,
   *  "message": "操作成功",
   *  "data": 1
   * }
   * @apiErrorExample {json} Error-Response:
   *  HTTP/1.1 500 error
   * {
   *  "code": 500,
   *  "message": "操作失败",
   * }
   * @apiSampleRequest /admin/type/categoryList
   */
  router.get('/categoryList', function (req, res, next) {
      let {categoryId} = req.query;
      typeService.cateList(categoryId).then(data => {
          if (data) res.json(result.success(data));
          else res.json(result.failed);
      }).catch(e => res.json(result.exceptionFailed(e.message)));
  });
  
  module.exports = router;