-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathenvManagement.js
More file actions
85 lines (83 loc) · 2.54 KB
/
envManagement.js
File metadata and controls
85 lines (83 loc) · 2.54 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const _ = require('lodash');
const Service = require('egg').Service;
class EnvManagementService extends Service {
async queryEnvs(params) {
const { ctx } = this;
const { tags = '', search = '' } = params;
const envResult = await ctx.model.EnvManagement.findAll({
attributes: [
'id',
'envName',
'hostIp',
'uicUsername',
'uicPasswd',
'url',
'remark',
'tags',
],
where: {
status: 1,
$or: [
{
envName: { $like: `%${search}%` },
},
{
hostIp: { $like: `%${search}%` },
},
],
},
});
const tagsResult = await ctx.model.TagManagement.findAll();
const result = [];
envResult.forEach((item) => {
const tagids = item.get('tags').split(',');
const tagArrs = tagsResult.filter((ele) => {
return tagids.includes(`${ele.get('id')}`);
});
item.set('tags', tagArrs);
if (tags) {
if (tags.split(',').some((ele) => tagids.includes(`${ele}`))) {
result.push(item);
}
} else {
result.push(item);
}
});
return result;
}
addEnv(env) {
const { ctx } = this;
return ctx.model.EnvManagement.create(env);
}
editEnv(env) {
const { ctx } = this;
const { id, envName, hostIp, uicUsername, uicPasswd, url, remark, tags } = env;
const newEnv = {};
if (!_.isNil(envName)) newEnv.envName = envName;
if (!_.isNil(hostIp)) newEnv.hostIp = hostIp;
if (!_.isNil(uicUsername)) newEnv.uicUsername = uicUsername;
if (!_.isNil(uicPasswd)) newEnv.uicPasswd = uicPasswd;
if (!_.isNil(url)) newEnv.url = url;
if (!_.isNil(remark)) newEnv.remark = remark;
if (!_.isNil(tags)) newEnv.tags = tags;
return ctx.model.EnvManagement.update(newEnv, {
where: {
id,
},
});
}
deleteEnv(id) {
const { ctx } = this;
return ctx.model.EnvManagement.update(
{
status: 0,
},
{
where: {
id,
},
}
);
}
}
module.exports = EnvManagementService;