2017-07-05 16:17:58 +08:00
|
|
|
'use strict';
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
|
|
|
|
|
|
|
|
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
|
|
|
|
|
|
|
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
|
|
|
|
|
|
|
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
|
|
|
|
|
|
|
var _createClass2 = require('babel-runtime/helpers/createClass');
|
|
|
|
|
|
|
|
var _createClass3 = _interopRequireDefault(_createClass2);
|
|
|
|
|
|
|
|
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
|
|
|
|
|
|
|
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
|
|
|
|
|
|
|
var _inherits2 = require('babel-runtime/helpers/inherits');
|
|
|
|
|
|
|
|
var _inherits3 = _interopRequireDefault(_inherits2);
|
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
var _yapi = require('../yapi.js');
|
|
|
|
|
|
|
|
var _yapi2 = _interopRequireDefault(_yapi);
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
var _base = require('./base.js');
|
|
|
|
|
|
|
|
var _base2 = _interopRequireDefault(_base);
|
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
var projectModel = function (_baseModel) {
|
|
|
|
(0, _inherits3.default)(projectModel, _baseModel);
|
|
|
|
|
|
|
|
function projectModel() {
|
|
|
|
(0, _classCallCheck3.default)(this, projectModel);
|
|
|
|
return (0, _possibleConstructorReturn3.default)(this, (projectModel.__proto__ || (0, _getPrototypeOf2.default)(projectModel)).apply(this, arguments));
|
2017-07-05 16:17:58 +08:00
|
|
|
}
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
(0, _createClass3.default)(projectModel, [{
|
|
|
|
key: 'getName',
|
|
|
|
value: function getName() {
|
|
|
|
return 'project';
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'getSchema',
|
|
|
|
value: function getSchema() {
|
|
|
|
return {
|
|
|
|
uid: { type: Number, required: true },
|
|
|
|
name: { type: String, required: true },
|
2017-08-01 15:37:07 +08:00
|
|
|
basepath: { type: String },
|
2017-07-06 19:21:54 +08:00
|
|
|
desc: String,
|
|
|
|
group_id: { type: Number, required: true },
|
2017-08-08 19:18:12 +08:00
|
|
|
project_type: { type: String, required: true, enum: ['public', 'private'] },
|
2017-08-08 14:45:19 +08:00
|
|
|
members: [{ uid: Number, role: { type: String, enum: ['owner', 'dev'], username: String, email: String } }],
|
2017-07-20 15:26:26 +08:00
|
|
|
protocol: { type: String, required: true },
|
2017-07-06 19:21:54 +08:00
|
|
|
prd_host: { type: String, required: true },
|
2017-07-10 20:02:44 +08:00
|
|
|
env: [{ name: String, domain: String }],
|
2017-07-06 19:21:54 +08:00
|
|
|
add_time: Number,
|
|
|
|
up_time: Number
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'save',
|
|
|
|
value: function save(data) {
|
|
|
|
var m = new this.model(data);
|
|
|
|
return m.save();
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'get',
|
|
|
|
value: function get(id) {
|
|
|
|
return this.model.findOne({
|
|
|
|
_id: id
|
|
|
|
}).exec();
|
|
|
|
}
|
2017-07-10 20:02:44 +08:00
|
|
|
}, {
|
|
|
|
key: 'getByDomain',
|
|
|
|
value: function getByDomain(domain) {
|
|
|
|
return this.model.find({
|
|
|
|
prd_host: domain
|
|
|
|
}).exec();
|
|
|
|
}
|
2017-07-06 19:21:54 +08:00
|
|
|
}, {
|
|
|
|
key: 'checkNameRepeat',
|
|
|
|
value: function checkNameRepeat(name) {
|
|
|
|
return this.model.count({
|
|
|
|
name: name
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'checkDomainRepeat',
|
|
|
|
value: function checkDomainRepeat(domain, basepath) {
|
|
|
|
return this.model.count({
|
|
|
|
prd_host: domain,
|
|
|
|
basepath: basepath
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'list',
|
2017-08-08 19:18:12 +08:00
|
|
|
value: function list(group_id, auth) {
|
|
|
|
var params = { group_id: group_id };
|
2017-08-09 16:16:35 +08:00
|
|
|
if (!auth) params.project_type = 'public';
|
2017-08-08 19:18:12 +08:00
|
|
|
return this.model.find(params).sort({ _id: -1 }).exec();
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
2017-07-18 16:37:28 +08:00
|
|
|
}, {
|
|
|
|
key: 'listWithPaging',
|
|
|
|
value: function listWithPaging(group_id, page, limit) {
|
|
|
|
page = parseInt(page);
|
|
|
|
limit = parseInt(limit);
|
|
|
|
return this.model.find({
|
|
|
|
group_id: group_id
|
2017-07-21 11:46:44 +08:00
|
|
|
}).sort({ _id: -1 }).skip((page - 1) * limit).limit(limit).exec();
|
2017-07-18 16:37:28 +08:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'listCount',
|
2017-07-20 11:19:39 +08:00
|
|
|
value: function listCount(group_id) {
|
|
|
|
return this.model.count({
|
|
|
|
group_id: group_id
|
|
|
|
});
|
2017-07-18 16:37:28 +08:00
|
|
|
}
|
2017-07-10 20:02:44 +08:00
|
|
|
}, {
|
|
|
|
key: 'countByGroupId',
|
|
|
|
value: function countByGroupId(group_id) {
|
|
|
|
return this.model.count({
|
|
|
|
group_id: group_id
|
|
|
|
});
|
|
|
|
}
|
2017-07-06 19:21:54 +08:00
|
|
|
}, {
|
|
|
|
key: 'del',
|
|
|
|
value: function del(id) {
|
|
|
|
return this.model.deleteOne({
|
|
|
|
_id: id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'up',
|
|
|
|
value: function up(id, data) {
|
|
|
|
data.up_time = _yapi2.default.commons.time();
|
|
|
|
return this.model.update({
|
|
|
|
_id: id
|
2017-07-06 20:53:26 +08:00
|
|
|
}, data, { runValidators: true });
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'addMember',
|
2017-08-08 14:45:19 +08:00
|
|
|
value: function addMember(id, data) {
|
2017-07-06 19:21:54 +08:00
|
|
|
return this.model.update({
|
2017-07-10 11:56:53 +08:00
|
|
|
_id: id
|
2017-07-06 19:21:54 +08:00
|
|
|
}, {
|
2017-08-08 14:45:19 +08:00
|
|
|
$push: { members: data }
|
2017-07-06 19:21:54 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'delMember',
|
|
|
|
value: function delMember(id, uid) {
|
|
|
|
return this.model.update({
|
|
|
|
_id: id
|
|
|
|
}, {
|
|
|
|
$pull: { members: uid }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'checkMemberRepeat',
|
|
|
|
value: function checkMemberRepeat(id, uid) {
|
|
|
|
return this.model.count({
|
|
|
|
_id: id,
|
2017-08-08 14:45:19 +08:00
|
|
|
"members.uid": uid
|
2017-07-06 19:21:54 +08:00
|
|
|
});
|
|
|
|
}
|
2017-08-08 19:18:12 +08:00
|
|
|
}, {
|
|
|
|
key: 'changeMemberRole',
|
|
|
|
value: function changeMemberRole(id, uid, role) {
|
|
|
|
return this.model.update({
|
|
|
|
_id: id,
|
|
|
|
"members.uid": uid
|
|
|
|
}, {
|
|
|
|
"$set": { "members.$.uid": role }
|
|
|
|
});
|
|
|
|
}
|
2017-07-14 16:41:14 +08:00
|
|
|
}, {
|
|
|
|
key: 'search',
|
|
|
|
value: function search(keyword) {
|
|
|
|
return this.model.find({
|
|
|
|
name: new RegExp(keyword, 'ig')
|
|
|
|
}).limit(10);
|
|
|
|
}
|
2017-07-06 19:21:54 +08:00
|
|
|
}]);
|
|
|
|
return projectModel;
|
|
|
|
}(_base2.default);
|
|
|
|
|
|
|
|
module.exports = projectModel;
|