Skip to content

Commit 8a8dba5

Browse files
authored
Merge pull request #19 from atian25/egg-fix
feat: egg style && upgrade to 2
2 parents c6ed9a1 + a79eea0 commit 8a8dba5

File tree

20 files changed

+107
-91
lines changed

20 files changed

+107
-91
lines changed

server/.autod.conf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module.exports = {
44
write: true,
55
prefix: '^',
6+
plugin: 'autod-egg',
67
test: [
78
'test',
89
'benchmark',
@@ -14,8 +15,8 @@ module.exports = {
1415
'egg-bin',
1516
'autod',
1617
'eslint',
17-
'eslint-config-egg',
1818
'supertest',
19+
'autod-egg',
1920
'webstorm-disable-index',
2021
],
2122
exclude: [

server/app/controller/api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = app => {
4343
}
4444
}
4545
const resources = yield this.service.api.getRichList(condition, page, limit, order)
46-
const count = yield app.model.api.find(condition).count().exec()
46+
const count = yield app.model.Api.find(condition).count().exec()
4747
this.ctx.body = { resources, pages: { limit, page, count } }
4848
this.ctx.status = 200
4949
}
@@ -114,7 +114,7 @@ module.exports = app => {
114114
assert(mongoose.Types.ObjectId.isValid(groupId), 403, 'invalid groupId')
115115
assert(mongoose.Types.ObjectId.isValid(apiId), 403, 'invalid apiId')
116116

117-
const resources = (yield app.model.api.findOne({ _id: apiId, isDeleted: false })).toObject()
117+
const resources = (yield app.model.Api.findOne({ _id: apiId, isDeleted: false })).toObject()
118118
resources.history = yield this.service.apiHistory.get(resources)
119119

120120
this.ctx.body = { resources }
@@ -194,7 +194,7 @@ module.exports = app => {
194194
msg: '无权删除'
195195
})
196196
}
197-
yield app.model.group.update({ _id: groupId }, { modifiedTime: Date.now() }, { new: true }).exec()
197+
yield app.model.Group.update({ _id: groupId }, { modifiedTime: Date.now() }, { new: true }).exec()
198198
this.ctx.logger.info('deleteApi')
199199
this.ctx.status = 204
200200
}

server/app/controller/authority.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = app => {
1919
}
2020
* getApi () {
2121
const { apiId } = this.ctx.params
22-
const authority = (yield this.service.apiAuthority.get(apiId)) || app.model.apiAuthority()
22+
const authority = (yield this.service.apiAuthority.get(apiId)) || app.model.ApiAuthority()
2323
authority.apiId = apiId
2424
this.success(authority)
2525
}

server/app/controller/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ module.exports = app => {
1010
if (id.length < 5) {
1111
// hack方法,兼容老的存下url信息的api
1212
const url = `/client/${id}`
13-
return yield app.model.api.findOne({ url, 'options.method': method }).exec()
13+
return yield app.model.Api.findOne({ url, 'options.method': method }).exec()
1414
}
15-
return yield app.model.api.findOne({ _id: id, 'options.method': method }).exec()
15+
return yield app.model.Api.findOne({ _id: id, 'options.method': method }).exec()
1616
}
1717
* real () {
1818
const { _apiRealUrl, _apiMethod } = this.ctx.request.body

server/app/controller/group.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ module.exports = app => {
2727
isDeleted: false,
2828
name: reg
2929
}
30-
const resources = yield app.model.group
31-
.find(cond)
32-
.sort({ modifiedTime: -1, createTime: -1 })
33-
.skip((page - 1) * limit)
34-
.limit(limit)
35-
.exec()
36-
const count = yield app.model.group.find(cond).count().exec()
30+
const resources = yield app.model.Group
31+
.find(cond)
32+
.sort({ modifiedTime: -1, createTime: -1 })
33+
.skip((page - 1) * limit)
34+
.limit(limit)
35+
.exec()
36+
const count = yield app.model.Group.find(cond).count().exec()
3737
this.ctx.body = { resources, pages: { limit, page, count } }
3838
this.ctx.status = 200
3939
}

server/app/model/api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
module.exports = mongoose => {
1+
module.exports = app => {
2+
const mongoose = app.mongoose
23
const { ObjectId } = mongoose.Schema.Types
34
const ApiSchema = mongoose.Schema({
45
group: {

server/app/model/api_authority.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
module.exports = mongoose => {
1+
module.exports = app => {
2+
const mongoose = app.mongoose
23
const { ObjectId } = mongoose.Schema.Types
34
const ApiAuthoritySchema = mongoose.Schema({
45
apiId: {
@@ -9,7 +10,7 @@ module.exports = mongoose => {
910
operation: { // 编辑权限
1011
mode: {
1112
type: Number,
12-
default: 0 // 0 - 所有人, 1 - 组内人员 2 - 指定人员
13+
default: 0 // 0 - 所有人, 1 - 组内人员 2 - 指定人员
1314
},
1415
operator: {
1516
type: [ ObjectId ],

server/app/model/api_history.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
module.exports = mongoose => {
1+
module.exports = app => {
2+
const mongoose = app.mongoose
23
const { ObjectId } = mongoose.Schema.Types
34
const ApiHistorySchema = mongoose.Schema({
45
apiId: {

server/app/model/api_stat.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const moment = require('moment')
2-
module.exports = mongoose => {
2+
module.exports = app => {
3+
const mongoose = app.mongoose
34
const { ObjectId } = mongoose.Schema.Types
45
const ApiStatSchema = mongoose.Schema({
56
apiId: {

server/app/model/group.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
module.exports = mongoose => {
1+
module.exports = app => {
2+
const mongoose = app.mongoose
23
const { ObjectId } = mongoose.Schema.Types
34
const GroupSchema = new mongoose.Schema({
45
teamId: {

0 commit comments

Comments
 (0)