|
@@ -0,0 +1,103 @@
|
|
|
|
+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 };
|