2017-07-26 22:03:18 +08:00
|
|
|
import yapi from '../yapi.js';
|
|
|
|
import baseModel from './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-14 15:06:32 +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-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-07-26 22:03:18 +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-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-08 19:18:12 +08:00
|
|
|
list(group_id, auth) {
|
|
|
|
let params = {group_id: group_id}
|
2017-08-09 16:16:35 +08:00
|
|
|
if(!auth) params.project_type = 'public';
|
2017-08-15 11:12:39 +08:00
|
|
|
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
|
|
|
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 10:56:42 +08:00
|
|
|
delByGroupid(groupId){
|
2017-08-16 12:19:53 +08:00
|
|
|
return this.model.deleteMany({
|
2017-08-16 10:56:42 +08:00
|
|
|
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-08-08 14:45:19 +08:00
|
|
|
$push: { members: 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-14 15:06:32 +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
|
|
|
|
}, {
|
|
|
|
"$set": { "members.$.uid": role}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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;
|