123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- const Personnel = require('../module/Personnel');
- const Router = require('koa-router');
- const permission = require('../intercept/permission');
- const router = new Router();
- /**
- * 获取案例数据
- */
- router.get('/', async ctx => {
- let personnel = new Personnel();
- personnel.hide = 0;
- for (let key in ctx.request.query) {
- personnel[key] = ctx.request.query[key]
- }
- let result = await personnel.query()
- ctx.body = {
- msg: '成功获取数据',
- content: result
- }
- });
- /**
- * 添加案例
- */
- router.post('/', permission, async ctx => {
- let body = ctx.request.body;
- let personnel = new Personnel();
- personnel.type = body.type;
- personnel.address = body.address;
- personnel.count = body.count;
- personnel.time = Date.now().toString();
- personnel.describe = body.describe;
- personnel.requirement = body.requirement;
- personnel.bonus = body.bonus;
- personnel.title = body.title;
- personnel.language = body.language;
- let { insertId } = await personnel.insert()
- ctx.body = {
- msg: '成功添加!',
- insertId
- };
- });
- /**
- * 修改案例
- */
- router.put('/', permission, async ctx => {
- let body = ctx.request.body;
- let personnel = new Personnel();
- personnel.id = body.id;
- if (!await personnel.exists()) {
- ctx.error('该招聘不存在!')
- }
- personnel.type = body.type;
- personnel.address = body.address;
- personnel.count = body.count;
- personnel.describe = body.describe;
- personnel.requirement = body.requirement;
- personnel.bonus = body.bonus;
- personnel.title = body.title;
- personnel.language = body.language;
- await personnel.update()
- ctx.body = {
- msg: '成功修改!'
- };
- });
- /**
- * 删除案例
- */
- router.delete('/:id', permission, async ctx => {
- let id = ctx.params.id;
- (!id || !Number.isFinite(Number(id))) &&
- ctx.error('该案例不存在,请刷新后重试!');
- let personnel = new Personnel();
- personnel.id = id;
- personnel.hide = 0;
- (await personnel.exists()) ||
- ctx.error('该案例不存在,请刷新后重试!');
- personnel.hide = 1;
- await personnel.update();
- ctx.body = { msg: '成功删除!' };
- });
- module.exports = exports = { path: '/personnel', router };
|