project.js
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const Controller = require('egg').Controller;
class ProjectController extends Controller {
// 查询项目列表
async index() {
const { ctx } = this;
// // 定义查询接口的请求参数规则
// const searchRule = {
// pageSize: 'string',
// pageNum: 'string',
// };
// ctx.validate(searchRule, ctx.query);
await ctx.service.projectService.getList(ctx.query);
}
// 创建项目
async create() {
const { ctx } = this;
// 定义创建项目接口的请求参数规则
const createRule = {
name: 'string',
remark: 'string',
addr: 'string',
};
console.log(ctx.request.body);
ctx.validate(createRule, ctx.request.body);
await ctx.service.projectService.createProject(ctx.request.body);
}
// 编辑项目
async update() {
const { ctx } = this;
// 定义创建项目接口的请求参数规则
const createRule = {
name: 'string',
remark: 'string',
id: 'number',
addr: 'string',
};
ctx.validate(createRule, ctx.request.body);
await ctx.service.projectService.updateProject(ctx.request.body);
}
// 删除项目
async delete() {
const { ctx } = this;
// 定义创建项目接口的请求参数规则
const createRule = {
id: 'number',
};
ctx.validate(createRule, ctx.request.body);
await ctx.service.projectService.deleteProject(ctx.request.body);
}
}
module.exports = ProjectController;