commons.js
1.17 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
/*
* @Author: huyue
* @Date: 2021-09-02 14:15:48
* @Last Modified by: huyue
* @Last Modified time: 2021-09-02 14:43:02
*/
// app/service/Commons.js
const Service = require("egg").Service;
class CommonsService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const { CommonsInfo } = this.app.model;
this.DI = CommonsInfo;
}
/** 搜索列表 */
async findAll({ project_id }) {
return await this.DI.findAll({
where: { project_id: project_id },
attributes: [
"id",
"user_id",
"project_id",
"content",
"created_at",
"updated_at",
],
});
}
/** 新增评论 */
async create(params) {
const now = Date.now();
const p = await this.DI.create({
//目前还没有用户,所以都是默认值 ’1‘
// user_id:'',
project_id: params.project_id,
content: params.content,
created_at: now,
updated_at: now,
});
// console.log(p);
return {
id: p.id,
};
}
}
module.exports = CommonsService;