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 14:45:19 +08:00
|
|
|
members: [
|
|
|
|
{uid: Number, role: {type: String, enum:['owner', 'dev'], username: String, email: String}}
|
|
|
|
],
|
2017-07-26 22:03:18 +08:00
|
|
|
protocol: { type: String, required: true },
|
|
|
|
prd_host: { type: String, required: true },
|
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-07-26 22:03:18 +08:00
|
|
|
list(group_id) {
|
2017-07-06 19:21:54 +08:00
|
|
|
return this.model.find({
|
|
|
|
group_id: group_id
|
2017-07-26 22:03:18 +08:00
|
|
|
}).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
|
|
|
|
|
|
|
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
|
|
|
|
}, {
|
|
|
|
$pull: { members: uid }
|
|
|
|
}
|
|
|
|
);
|
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-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-07-06 19:21:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = projectModel;
|