diff --git a/doc/build/api.html b/doc/build/api.html
index 1e955c31..ae1ef0ed 100644
--- a/doc/build/api.html
+++ b/doc/build/api.html
@@ -71,6 +71,10 @@
/group/add
+
+
+ /group/list
+
@@ -148,16 +152,35 @@
返回示例:
- {
- "errcode": 0,
- "errmsg": 'success',
- "data":{
- "_id": 3,
- "group_name": "大数据4",
- "group_desc": "大数据4",
- "uid": "0"
- }
- }
+ {
+ "errcode": 0,
+ "errmsg": "success",
+ "data": {
+ "_id": 4,
+ "group_name": "大数据5",
+ "group_desc": "大数据5"
+ }
+}
+
+
+
+
+
+
+
+
+
+ 描述:
+ 添加项目分组
+
+
diff --git a/doc/build/static/server/controllers/group.js.html b/doc/build/static/server/controllers/group.js.html
index 86897ab5..cd968ede 100644
--- a/doc/build/static/server/controllers/group.js.html
+++ b/doc/build/static/server/controllers/group.js.html
@@ -29,7 +29,7 @@
import yapi from '../yapi.js'
import baseController from './base.js'
-
+//
class groupController extends baseController{
constructor(ctx){
super(ctx)
@@ -46,18 +46,7 @@ class groupController extends baseController{
* @param {String} group_name 项目分组名称,不能为空
* @param {String} [group_desc] 项目分组描述
* @returns {Object}
- * @example
- * {
- * "errcode": 0,
- * "errmsg": 'success',
- * "data":{
- * "_id": 3,
- * "group_name": "大数据4",
- * "group_desc": "大数据4",
- * "uid": "0"
- * }
- * }
- *
+ * @example ./api/group/add.json
*/
async add(ctx) {
let params = ctx.request.body;
@@ -87,6 +76,16 @@ class groupController extends baseController{
}
+ /**
+ * 添加项目分组
+ * @interface /group/list
+ * @method get
+ * @category group
+ * @foldnumber 10
+ * @returns {Object}
+ * @example
+ */
+
async list(ctx) {
try{
var groupInst = yapi.getInst(groupModel);
diff --git a/doc/build/static/server/controllers/project.js.html b/doc/build/static/server/controllers/project.js.html
index 99b9cbe1..d28d339d 100644
--- a/doc/build/static/server/controllers/project.js.html
+++ b/doc/build/static/server/controllers/project.js.html
@@ -162,11 +162,12 @@ class projectController extends baseController {
}
async list(ctx) {
- if(!ctx.request.query.group_id){
+ let group_id = ctx.request.query.group_id;
+ if(!group_id){
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
}
try{
- let result = await this.Model.list();
+ let result = await this.Model.list(group_id);
ctx.body = yapi.commons.resReturn(result)
}catch(err){
ctx.body = yapi.commons.resReturn(null, 402, e.message)
@@ -189,14 +190,43 @@ class projectController extends baseController {
async up(ctx){
try{
let id = ctx.request.body.id;
+ let params = ctx.request.body;
+
if(this.jungeMemberAuth(id, this.getUid()) !== true){
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
- let data = {};
- ctx.request.body.project_name && (data.project_name = ctx.request.body.project_name)
- ctx.request.body.project_desc && (data.project_desc = ctx.request.body.project_desc)
- if(Object.keys(data).length ===0){
- ctx.body = yapi.commons.resReturn(null, 404, '分组名和分组描述都为空');
+
+ if(!params.name){
+ return ctx.body = yapi.commons.resReturn(null, 400, '项目名不能为空');
+ }
+
+ let checkRepeat = await this.Model.checkNameRepeat(params.name);
+ if(checkRepeat > 0){
+ return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
+ }
+
+ if(!params.basepath){
+ return ctx.body = yapi.commons.resReturn(null, 400, '项目basepath不能为空');
+ }
+ if(!params.prd_host){
+ return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
+ }
+
+ let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
+ if(checkRepeatDomain > 0){
+ return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
+ }
+
+
+
+ let data= {
+ name: params.name,
+ desc: params.desc,
+ prd_host: params.prd_host,
+ basepath: params.basepath,
+ uid: this.getUid(),
+ up_time: yapi.commons.time(),
+ env: params.env
}
let result = await this.Model.up(id, data);
ctx.body = yapi.commons.resReturn(result)
diff --git a/exampleCode/api/group/add.json b/exampleCode/api/group/add.json
new file mode 100644
index 00000000..f74fec92
--- /dev/null
+++ b/exampleCode/api/group/add.json
@@ -0,0 +1,9 @@
+{
+ "errcode": 0,
+ "errmsg": "success",
+ "data": {
+ "_id": 4,
+ "group_name": "大数据5",
+ "group_desc": "大数据5"
+ }
+}
\ No newline at end of file
diff --git a/server/controllers/group.js b/server/controllers/group.js
index 19be25f8..76a68d5e 100644
--- a/server/controllers/group.js
+++ b/server/controllers/group.js
@@ -2,7 +2,7 @@ import groupModel from '../models/group.js'
import yapi from '../yapi.js'
import baseController from './base.js'
-
+//
class groupController extends baseController{
constructor(ctx){
super(ctx)
@@ -19,18 +19,7 @@ class groupController extends baseController{
* @param {String} group_name 项目分组名称,不能为空
* @param {String} [group_desc] 项目分组描述
* @returns {Object}
- * @example
- * {
- * "errcode": 0,
- * "errmsg": 'success',
- * "data":{
- * "_id": 3,
- * "group_name": "大数据4",
- * "group_desc": "大数据4",
- * "uid": "0"
- * }
- * }
- *
+ * @example ./api/group/add.json
*/
async add(ctx) {
let params = ctx.request.body;
@@ -60,6 +49,16 @@ class groupController extends baseController{
}
+ /**
+ * 添加项目分组
+ * @interface /group/list
+ * @method get
+ * @category group
+ * @foldnumber 10
+ * @returns {Object}
+ * @example
+ */
+
async list(ctx) {
try{
var groupInst = yapi.getInst(groupModel);
diff --git a/server/controllers/project.js b/server/controllers/project.js
index f477fae5..3284282a 100644
--- a/server/controllers/project.js
+++ b/server/controllers/project.js
@@ -135,11 +135,12 @@ class projectController extends baseController {
}
async list(ctx) {
- if(!ctx.request.query.group_id){
+ let group_id = ctx.request.query.group_id;
+ if(!group_id){
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
}
try{
- let result = await this.Model.list();
+ let result = await this.Model.list(group_id);
ctx.body = yapi.commons.resReturn(result)
}catch(err){
ctx.body = yapi.commons.resReturn(null, 402, e.message)
@@ -162,14 +163,43 @@ class projectController extends baseController {
async up(ctx){
try{
let id = ctx.request.body.id;
+ let params = ctx.request.body;
+
if(this.jungeMemberAuth(id, this.getUid()) !== true){
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
- let data = {};
- ctx.request.body.project_name && (data.project_name = ctx.request.body.project_name)
- ctx.request.body.project_desc && (data.project_desc = ctx.request.body.project_desc)
- if(Object.keys(data).length ===0){
- ctx.body = yapi.commons.resReturn(null, 404, '分组名和分组描述都为空');
+
+ if(!params.name){
+ return ctx.body = yapi.commons.resReturn(null, 400, '项目名不能为空');
+ }
+
+ let checkRepeat = await this.Model.checkNameRepeat(params.name);
+ if(checkRepeat > 0){
+ return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
+ }
+
+ if(!params.basepath){
+ return ctx.body = yapi.commons.resReturn(null, 400, '项目basepath不能为空');
+ }
+ if(!params.prd_host){
+ return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
+ }
+
+ let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
+ if(checkRepeatDomain > 0){
+ return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
+ }
+
+
+
+ let data= {
+ name: params.name,
+ desc: params.desc,
+ prd_host: params.prd_host,
+ basepath: params.basepath,
+ uid: this.getUid(),
+ up_time: yapi.commons.time(),
+ env: params.env
}
let result = await this.Model.up(id, data);
ctx.body = yapi.commons.resReturn(result)
diff --git a/server/models/project.js b/server/models/project.js
index 847fe7eb..4bcc612d 100644
--- a/server/models/project.js
+++ b/server/models/project.js
@@ -15,7 +15,7 @@ class projectModel extends baseModel{
group_id: {type: Number, required: true},
members: Array,
prd_host: {type: String, required: true},
- env: Array,
+ env: Object,
add_time: Number,
up_time: Number
}
@@ -62,7 +62,7 @@ class projectModel extends baseModel{
data.up_time = yapi.commons.time();
return this.model.update({
_id: id,
- }, data)
+ }, data, { runValidators: true })
}
addMember(id, uid){
diff --git a/server_dist/controllers/group.js b/server_dist/controllers/group.js
index a3549bad..d5cf7c8d 100644
--- a/server_dist/controllers/group.js
+++ b/server_dist/controllers/group.js
@@ -46,6 +46,7 @@ var _base2 = _interopRequireDefault(_base);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+//
var groupController = function (_baseController) {
(0, _inherits3.default)(groupController, _baseController);
@@ -67,18 +68,7 @@ var groupController = function (_baseController) {
* @param {String} group_name 项目分组名称,不能为空
* @param {String} [group_desc] 项目分组描述
* @returns {Object}
- * @example
- * {
- * "errcode": 0,
- * "errmsg": 'success',
- * "data":{
- * "_id": 3,
- * "group_name": "大数据4",
- * "group_desc": "大数据4",
- * "uid": "0"
- * }
- * }
- *
+ * @example ./api/group/add.json
*/
@@ -155,6 +145,17 @@ var groupController = function (_baseController) {
return add;
}()
+
+ /**
+ * 添加项目分组
+ * @interface /group/list
+ * @method get
+ * @category group
+ * @foldnumber 10
+ * @returns {Object}
+ * @example
+ */
+
}, {
key: 'list',
value: function () {
diff --git a/server_dist/controllers/project.js b/server_dist/controllers/project.js
index c3efaf78..7d53ca8d 100644
--- a/server_dist/controllers/project.js
+++ b/server_dist/controllers/project.js
@@ -1,9 +1,5 @@
'use strict';
-var _keys = require('babel-runtime/core-js/object/keys');
-
-var _keys2 = _interopRequireDefault(_keys);
-
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
@@ -479,42 +475,44 @@ var projectController = function (_baseController) {
key: 'list',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
- var result;
+ var group_id, result;
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
- if (ctx.request.query.group_id) {
- _context7.next = 2;
+ group_id = ctx.request.query.group_id;
+
+ if (group_id) {
+ _context7.next = 3;
break;
}
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
- case 2:
- _context7.prev = 2;
- _context7.next = 5;
- return this.Model.list();
+ case 3:
+ _context7.prev = 3;
+ _context7.next = 6;
+ return this.Model.list(group_id);
- case 5:
+ case 6:
result = _context7.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
- _context7.next = 12;
+ _context7.next = 13;
break;
- case 9:
- _context7.prev = 9;
- _context7.t0 = _context7['catch'](2);
+ case 10:
+ _context7.prev = 10;
+ _context7.t0 = _context7['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
- case 12:
+ case 13:
case 'end':
return _context7.stop();
}
}
- }, _callee7, this, [[2, 9]]);
+ }, _callee7, this, [[3, 10]]);
}));
function list(_x8) {
@@ -577,51 +575,107 @@ var projectController = function (_baseController) {
key: 'up',
value: function () {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
- var id, data, result;
+ var id, _params, checkRepeat, checkRepeatDomain, data, result;
+
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
_context9.prev = 0;
id = ctx.request.body.id;
+ _params = ctx.request.body;
if (!(this.jungeMemberAuth(id, this.getUid()) !== true)) {
- _context9.next = 4;
+ _context9.next = 5;
break;
}
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
- case 4:
- data = {};
-
- ctx.request.body.project_name && (data.project_name = ctx.request.body.project_name);
- ctx.request.body.project_desc && (data.project_desc = ctx.request.body.project_desc);
- if ((0, _keys2.default)(data).length === 0) {
- ctx.body = _yapi2.default.commons.resReturn(null, 404, '分组名和分组描述都为空');
+ case 5:
+ if (_params.name) {
+ _context9.next = 7;
+ break;
}
- _context9.next = 10;
+
+ return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目名不能为空'));
+
+ case 7:
+ _context9.next = 9;
+ return this.Model.checkNameRepeat(_params.name);
+
+ case 9:
+ checkRepeat = _context9.sent;
+
+ if (!(checkRepeat > 0)) {
+ _context9.next = 12;
+ break;
+ }
+
+ return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
+
+ case 12:
+ if (_params.basepath) {
+ _context9.next = 14;
+ break;
+ }
+
+ return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目basepath不能为空'));
+
+ case 14:
+ if (_params.prd_host) {
+ _context9.next = 16;
+ break;
+ }
+
+ return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目domain不能为空'));
+
+ case 16:
+ _context9.next = 18;
+ return this.Model.checkDomainRepeat(_params.prd_host, _params.basepath);
+
+ case 18:
+ checkRepeatDomain = _context9.sent;
+
+ if (!(checkRepeatDomain > 0)) {
+ _context9.next = 21;
+ break;
+ }
+
+ return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
+
+ case 21:
+ data = {
+ name: _params.name,
+ desc: _params.desc,
+ prd_host: _params.prd_host,
+ basepath: _params.basepath,
+ uid: this.getUid(),
+ up_time: _yapi2.default.commons.time(),
+ env: _params.env
+ };
+ _context9.next = 24;
return this.Model.up(id, data);
- case 10:
+ case 24:
result = _context9.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
- _context9.next = 17;
+ _context9.next = 31;
break;
- case 14:
- _context9.prev = 14;
+ case 28:
+ _context9.prev = 28;
_context9.t0 = _context9['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
- case 17:
+ case 31:
case 'end':
return _context9.stop();
}
}
- }, _callee9, this, [[0, 14]]);
+ }, _callee9, this, [[0, 28]]);
}));
function up(_x10) {
diff --git a/server_dist/models/project.js b/server_dist/models/project.js
index fb19485a..503bd1f6 100644
--- a/server_dist/models/project.js
+++ b/server_dist/models/project.js
@@ -54,7 +54,7 @@ var projectModel = function (_baseModel) {
group_id: { type: Number, required: true },
members: Array,
prd_host: { type: String, required: true },
- env: Array,
+ env: Object,
add_time: Number,
up_time: Number
};
@@ -107,7 +107,7 @@ var projectModel = function (_baseModel) {
data.up_time = _yapi2.default.commons.time();
return this.model.update({
_id: id
- }, data);
+ }, data, { runValidators: true });
}
}, {
key: 'addMember',