2017-09-03 08:43:13 +08:00
|
|
|
const yapi = require('../yapi.js');
|
|
|
|
const baseModel = require('./base.js');
|
2017-07-05 16:17:58 +08:00
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
class projectModel extends baseModel {
|
|
|
|
getName() {
|
|
|
|
return 'project';
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
getSchema() {
|
2017-07-06 19:21:54 +08:00
|
|
|
return {
|
2017-08-08 14:45:19 +08:00
|
|
|
uid: {type: Number, required: true},
|
2017-07-26 22:03:18 +08:00
|
|
|
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,
|
2017-07-26 22:03:18 +08:00
|
|
|
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: [
|
2017-08-15 12:08:59 +08:00
|
|
|
{uid: Number, role: {type: String, enum:['owner', 'dev']},username: String, email: String}
|
2017-08-08 14:45:19 +08:00
|
|
|
],
|
2017-07-10 20:02:44 +08:00
|
|
|
env: [
|
2017-07-26 22:03:18 +08:00
|
|
|
{ name: String, domain: String }
|
2017-07-10 20:02:44 +08:00
|
|
|
],
|
2017-08-17 12:14:58 +08:00
|
|
|
icon: String,
|
|
|
|
color: String,
|
2017-07-06 19:21:54 +08:00
|
|
|
add_time: Number,
|
|
|
|
up_time: Number
|
2017-07-26 22:03:18 +08:00
|
|
|
};
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
2017-07-05 16:17:58 +08:00
|
|
|
|
2017-07-06 19:21:54 +08:00
|
|
|
save(data) {
|
|
|
|
let m = new this.model(data);
|
2017-07-05 16:17:58 +08:00
|
|
|
return m.save();
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
|
|
|
|
2017-08-25 18:19:10 +08:00
|
|
|
get(id) {
|
2017-07-06 19:21:54 +08:00
|
|
|
return this.model.findOne({
|
|
|
|
_id: id
|
2017-07-26 22:03:18 +08:00
|
|
|
}).exec();
|
2017-08-25 18:19:10 +08:00
|
|
|
}
|
2017-08-21 12:05:18 +08:00
|
|
|
|
|
|
|
getBaseInfo(id){
|
|
|
|
return this.model.findOne({
|
|
|
|
_id: id
|
2017-08-25 18:19:10 +08:00
|
|
|
}).select('_id uid name basepath desc group_id project_type env icon color add_time up_time')
|
2017-08-21 12:05:18 +08:00
|
|
|
.exec()
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
getByDomain(domain) {
|
2017-07-10 20:02:44 +08:00
|
|
|
return this.model.find({
|
|
|
|
prd_host: domain
|
2017-07-26 22:03:18 +08:00
|
|
|
}).exec();
|
2017-07-10 20:02:44 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
checkNameRepeat(name) {
|
2017-07-06 19:21:54 +08:00
|
|
|
return this.model.count({
|
|
|
|
name: name
|
2017-07-26 22:03:18 +08:00
|
|
|
});
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
checkDomainRepeat(domain, basepath) {
|
2017-07-06 19:21:54 +08:00
|
|
|
return this.model.count({
|
|
|
|
prd_host: domain,
|
2017-07-05 16:17:58 +08:00
|
|
|
basepath: basepath
|
2017-07-26 22:03:18 +08:00
|
|
|
});
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
|
|
|
|
2017-08-28 15:19:07 +08:00
|
|
|
list(group_id) {
|
2017-08-08 19:18:12 +08:00
|
|
|
let params = {group_id: group_id}
|
2017-08-17 12:14:58 +08:00
|
|
|
return this.model.find(params).select("_id uid name basepath desc group_id project_type color icon env add_time up_time").sort({ _id: -1 }).exec();
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
|
|
|
|
2017-09-27 11:13:06 +08:00
|
|
|
countWithPublic(group_id){
|
|
|
|
let params = {group_id: group_id, project_type: 'public'};
|
|
|
|
return this.model.count(params);
|
|
|
|
}
|
|
|
|
|
2017-07-18 16:37:28 +08:00
|
|
|
listWithPaging(group_id, page, limit) {
|
|
|
|
page = parseInt(page);
|
|
|
|
limit = parseInt(limit);
|
|
|
|
return this.model.find({
|
|
|
|
group_id: group_id
|
2017-07-26 22:03:18 +08:00
|
|
|
}).sort({ _id: -1 }).skip((page - 1) * limit).limit(limit).exec();
|
2017-07-18 16:37:28 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 11:19:39 +08:00
|
|
|
listCount(group_id) {
|
|
|
|
return this.model.count({
|
|
|
|
group_id: group_id
|
|
|
|
});
|
2017-07-18 16:37:28 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
countByGroupId(group_id) {
|
2017-07-10 20:02:44 +08:00
|
|
|
return this.model.count({
|
|
|
|
group_id: group_id
|
2017-07-26 22:03:18 +08:00
|
|
|
});
|
2017-07-10 20:02:44 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
del(id) {
|
2017-07-06 19:21:54 +08:00
|
|
|
return this.model.deleteOne({
|
2017-07-05 16:17:58 +08:00
|
|
|
_id: id
|
2017-07-26 22:03:18 +08:00
|
|
|
});
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
2017-07-26 22:03:18 +08:00
|
|
|
|
2017-08-16 17:13:14 +08:00
|
|
|
delByGroupid(groupId){
|
|
|
|
return this.model.deleteMany({
|
|
|
|
group_id: groupId
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
up(id, data) {
|
2017-07-05 16:17:58 +08:00
|
|
|
data.up_time = yapi.commons.time();
|
2017-07-06 19:21:54 +08:00
|
|
|
return this.model.update({
|
2017-07-27 19:49:26 +08:00
|
|
|
_id: id
|
2017-07-26 22:03:18 +08:00
|
|
|
}, data, { runValidators: true });
|
2017-07-05 16:17:58 +08:00
|
|
|
}
|
2017-07-06 19:21:54 +08:00
|
|
|
|
2017-08-08 14:45:19 +08:00
|
|
|
addMember(id, data) {
|
2017-07-26 22:03:18 +08:00
|
|
|
return this.model.update(
|
|
|
|
{
|
|
|
|
_id: id
|
|
|
|
}, {
|
2017-09-27 20:11:04 +08:00
|
|
|
// $push: { members: data }
|
|
|
|
$push: { members: { $each: data } }
|
2017-07-26 22:03:18 +08:00
|
|
|
}
|
|
|
|
);
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
delMember(id, uid) {
|
|
|
|
return this.model.update(
|
|
|
|
{
|
|
|
|
_id: id
|
|
|
|
}, {
|
2017-08-15 12:08:59 +08:00
|
|
|
$pull: { members: {uid: uid} }
|
2017-07-26 22:03:18 +08:00
|
|
|
}
|
|
|
|
);
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
checkMemberRepeat(id, uid) {
|
2017-07-06 19:21:54 +08:00
|
|
|
return this.model.count({
|
|
|
|
_id: id,
|
2017-08-08 14:45:19 +08:00
|
|
|
"members.uid": uid
|
2017-07-26 22:03:18 +08:00
|
|
|
});
|
2017-07-06 19:21:54 +08:00
|
|
|
}
|
|
|
|
|
2017-08-08 19:18:12 +08:00
|
|
|
changeMemberRole(id, uid, role) {
|
|
|
|
return this.model.update(
|
|
|
|
{
|
|
|
|
_id: id,
|
|
|
|
"members.uid": uid
|
|
|
|
}, {
|
2017-08-18 17:08:37 +08:00
|
|
|
"$set": { "members.$.role": role}
|
2017-08-08 19:18:12 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-14 16:41:14 +08:00
|
|
|
search(keyword) {
|
|
|
|
return this.model.find({
|
|
|
|
name: new RegExp(keyword, 'ig')
|
|
|
|
})
|
2017-07-26 22:03:18 +08:00
|
|
|
.limit(10);
|
2017-07-14 16:41:14 +08:00
|
|
|
}
|
2017-08-10 12:14:35 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-08-10 12:14:35 +08:00
|
|
|
module.exports = projectModel;
|