yapi/server_dist/models/project.js

205 lines
6.1 KiB
JavaScript
Raw Normal View History

'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);
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);
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-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 },
basepath: { type: String },
2017-07-06 19:21:54 +08:00
desc: String,
group_id: { type: Number, required: true },
project_type: { type: String, required: true, enum: ['public', 'private'] },
2017-08-14 15:06:32 +08:00
members: [{ uid: Number, role: { type: String, enum: ['owner', 'dev'] }, username: String, email: String }],
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',
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';
return this.model.find(params).select("_id uid name basepath desc group_id project_type env add_time up_time").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',
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
});
}
2017-08-16 10:56:42 +08:00
}, {
key: 'delByGroupid',
value: function delByGroupid(groupId) {
return this.model.deleteMany({
2017-08-16 10:56:42 +08:00
group_id: groupId
});
}
2017-07-06 19:21:54 +08:00
}, {
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
}, {
2017-08-14 15:06:32 +08:00
$pull: { members: { uid: uid } }
2017-07-06 19:21:54 +08:00
});
}
}, {
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
});
}
}, {
key: 'changeMemberRole',
value: function changeMemberRole(id, uid, role) {
return this.model.update({
_id: id,
"members.uid": uid
}, {
"$set": { "members.$.uid": role }
});
}
}, {
key: 'search',
value: function search(keyword) {
return this.model.find({
name: new RegExp(keyword, 'ig')
}).limit(10);
}
2017-08-10 12:14:35 +08:00
}, {
key: 'download',
value: function download(id) {
console.log('models in download');
// return this.model.find({
// name: new RegExp(id, 'ig')
// })
// .limit(10);
}
2017-07-06 19:21:54 +08:00
}]);
return projectModel;
}(_base2.default);
module.exports = projectModel;