2017-07-26 22:03:18 +08:00
|
|
|
import yapi from '../yapi.js';
|
|
|
|
import baseModel from './base.js';
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
class interfaceModel extends baseModel {
|
|
|
|
getName() {
|
|
|
|
return 'interface';
|
2017-07-10 11:56:53 +08:00
|
|
|
}
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
getSchema() {
|
2017-07-10 11:56:53 +08:00
|
|
|
return {
|
2017-07-26 22:03:18 +08:00
|
|
|
title: { type: String, required: true },
|
|
|
|
uid: { type: Number, required: true },
|
|
|
|
path: { type: String, required: true },
|
|
|
|
method: { type: String, required: true },
|
|
|
|
project_id: { type: Number, required: true },
|
2017-08-18 20:35:31 +08:00
|
|
|
catid: {type: Number, required: true},
|
2017-08-17 12:03:55 +08:00
|
|
|
edit_uid: {type: Number, default: 0},
|
2017-08-15 12:08:59 +08:00
|
|
|
status: {type: String, enum: ['undone', 'done'], default: 'undone'},
|
2017-07-10 11:56:53 +08:00
|
|
|
desc: String,
|
|
|
|
add_time: Number,
|
|
|
|
up_time: Number,
|
2017-08-16 10:56:42 +08:00
|
|
|
type: {type: String, enum: ['static', 'var'], default:'static'},
|
2017-08-08 19:18:12 +08:00
|
|
|
req_query:[{
|
2017-08-15 12:08:59 +08:00
|
|
|
name: String, value: String, desc: String, required: {
|
|
|
|
type:String,
|
|
|
|
enum: ["1", "0"],
|
|
|
|
default: "1"
|
|
|
|
}
|
2017-08-08 19:18:12 +08:00
|
|
|
}],
|
2017-07-10 11:56:53 +08:00
|
|
|
req_headers: [{
|
2017-08-15 12:08:59 +08:00
|
|
|
name: String, value: String, desc: String, required: {
|
|
|
|
type:String,
|
|
|
|
enum: ["1", "0"],
|
|
|
|
default: "1"
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
}],
|
2017-08-15 17:38:22 +08:00
|
|
|
req_params:[{
|
|
|
|
name: String,
|
|
|
|
desc: String
|
|
|
|
}],
|
2017-08-15 12:08:59 +08:00
|
|
|
req_body_type: {
|
2017-07-10 11:56:53 +08:00
|
|
|
type: String,
|
2017-08-24 16:37:45 +08:00
|
|
|
enum: ['form', 'json', 'text', 'file', 'raw']
|
2017-07-10 11:56:53 +08:00
|
|
|
},
|
2017-08-15 12:08:59 +08:00
|
|
|
req_body_form: [{
|
|
|
|
name: String, type: { type: String, enum: ['text', 'file'] }, desc: String, required: {
|
|
|
|
type:String,
|
|
|
|
enum: ["1", "0"],
|
|
|
|
default: "1"
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
}],
|
2017-08-15 12:08:59 +08:00
|
|
|
req_body_other: String,
|
2017-07-10 11:56:53 +08:00
|
|
|
res_body_type: {
|
|
|
|
type: String,
|
2017-08-24 16:37:45 +08:00
|
|
|
enum: ['json', 'text', 'xml', 'raw']
|
2017-07-10 11:56:53 +08:00
|
|
|
},
|
|
|
|
res_body: String
|
2017-08-17 15:19:47 +08:00
|
|
|
};
|
2017-07-10 11:56:53 +08:00
|
|
|
}
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
save(data) {
|
|
|
|
let m = new this.model(data);
|
|
|
|
return m.save();
|
|
|
|
}
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
get(id) {
|
2017-07-10 11:56:53 +08:00
|
|
|
return this.model.findOne({
|
|
|
|
_id: id
|
2017-07-26 22:03:18 +08:00
|
|
|
})
|
|
|
|
.exec();
|
2017-07-10 11:56:53 +08:00
|
|
|
}
|
|
|
|
|
2017-08-16 10:56:42 +08:00
|
|
|
getVar(project_id, method){
|
|
|
|
return this.model.find({
|
|
|
|
type: 'var',
|
|
|
|
method: method
|
|
|
|
}).select('_id path').exec()
|
|
|
|
}
|
|
|
|
|
2017-07-31 10:15:16 +08:00
|
|
|
getByPath(project_id, path, method) {
|
2017-07-10 20:02:44 +08:00
|
|
|
return this.model.find({
|
|
|
|
project_id: project_id,
|
2017-07-31 10:15:16 +08:00
|
|
|
path: path,
|
|
|
|
method: method
|
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
|
|
|
checkRepeat(id, path, method) {
|
2017-07-10 11:56:53 +08:00
|
|
|
return this.model.count({
|
2017-07-26 17:56:51 +08:00
|
|
|
project_id: id,
|
2017-07-10 11:56:53 +08:00
|
|
|
path: path,
|
|
|
|
method: method
|
2017-07-26 22:03:18 +08:00
|
|
|
});
|
2017-07-10 11:56:53 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
countByProjectId(id) {
|
2017-07-10 20:02:44 +08:00
|
|
|
return this.model.count({
|
|
|
|
project_id: id
|
2017-07-26 22:03:18 +08:00
|
|
|
});
|
2017-07-10 20:02:44 +08:00
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
2017-08-18 20:35:31 +08:00
|
|
|
list(project_id, select) {
|
|
|
|
select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time'
|
2017-07-10 11:56:53 +08:00
|
|
|
return this.model.find({
|
2017-07-20 18:37:00 +08:00
|
|
|
project_id: project_id
|
2017-07-26 22:03:18 +08:00
|
|
|
})
|
2017-08-18 20:35:31 +08:00
|
|
|
.select(select)
|
2017-07-26 22:03:18 +08:00
|
|
|
.sort({ _id: -1 })
|
|
|
|
.exec();
|
2017-07-10 11:56:53 +08:00
|
|
|
}
|
|
|
|
|
2017-08-18 20:35:31 +08:00
|
|
|
listByCatid(catid, select){
|
|
|
|
select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time'
|
|
|
|
return this.model.find({
|
|
|
|
catid: catid
|
|
|
|
}).select(select).exec();
|
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
del(id) {
|
2017-07-10 11:56:53 +08:00
|
|
|
return this.model.deleteOne({
|
|
|
|
_id: id
|
2017-07-26 22:03:18 +08:00
|
|
|
});
|
2017-07-10 11:56:53 +08:00
|
|
|
}
|
2017-08-10 12:14:35 +08:00
|
|
|
|
2017-08-18 20:35:31 +08:00
|
|
|
delByCatid(id){
|
|
|
|
return this.model.deleteMany({
|
|
|
|
catid: id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-16 10:56:42 +08:00
|
|
|
delByProjectId(id){
|
2017-08-16 12:19:53 +08:00
|
|
|
return this.model.deleteMany({
|
2017-08-16 10:56:42 +08:00
|
|
|
project_id: id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-26 22:03:18 +08:00
|
|
|
up(id, data) {
|
2017-07-10 11:56:53 +08:00
|
|
|
data.up_time = yapi.commons.time();
|
|
|
|
return this.model.update({
|
2017-07-27 15:06:42 +08:00
|
|
|
_id: id
|
2017-08-17 15:19:47 +08:00
|
|
|
}, data, {runValidators: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
upEditUid(id, uid){
|
|
|
|
return this.model.update({
|
|
|
|
_id: id
|
|
|
|
},
|
|
|
|
{edit_uid: uid},
|
|
|
|
{runValidators: true });
|
2017-07-10 11:56:53 +08:00
|
|
|
}
|
2017-07-03 16:16:05 +08:00
|
|
|
}
|
|
|
|
|
2017-08-10 12:14:35 +08:00
|
|
|
module.exports = interfaceModel;
|