2017-07-10 11:56:53 +08:00
|
|
|
import yapi from '../yapi.js'
|
|
|
|
import baseModel from './base.js'
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
class interfaceModel extends baseModel{
|
|
|
|
getName(){
|
|
|
|
return 'interface'
|
|
|
|
}
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
getSchema(){
|
|
|
|
return {
|
2017-07-20 16:14:20 +08:00
|
|
|
title: {type: String, required: true},
|
2017-07-10 11:56:53 +08:00
|
|
|
uid: {type: Number, required: true},
|
2017-07-20 16:14:20 +08:00
|
|
|
path: {type: String, required: true},
|
2017-07-10 11:56:53 +08:00
|
|
|
method: {type: String, required: true},
|
|
|
|
project_id: {type: Number, required: true},
|
|
|
|
desc: String,
|
|
|
|
add_time: Number,
|
|
|
|
up_time: Number,
|
|
|
|
req_headers: [{
|
|
|
|
name: String, value: String, desc: String, required: Boolean
|
|
|
|
}],
|
|
|
|
req_params_type: {
|
|
|
|
type: String,
|
|
|
|
enum: ["form", "json", "text", "xml"]
|
|
|
|
},
|
|
|
|
req_params_form: [{
|
|
|
|
name: String, value: String,value_type: {type: String, enum: ["text", "file"]}, desc: String, required: Boolean
|
|
|
|
}],
|
|
|
|
req_params_other: String,
|
|
|
|
res_body_type: {
|
|
|
|
type: String,
|
|
|
|
enum: ["json", "text", "xml"]
|
|
|
|
},
|
|
|
|
res_body: String
|
|
|
|
}
|
|
|
|
}
|
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-10 11:56:53 +08:00
|
|
|
get(id){
|
|
|
|
return this.model.findOne({
|
|
|
|
_id: id
|
|
|
|
}).exec()
|
|
|
|
}
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
getByPath(project_id, path){
|
|
|
|
return this.model.find({
|
|
|
|
project_id: project_id,
|
|
|
|
path: path
|
|
|
|
}).exec()
|
|
|
|
}
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
checkRepeat(path, method){
|
|
|
|
return this.model.count({
|
|
|
|
path: path,
|
|
|
|
method: method
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-10 20:02:44 +08:00
|
|
|
countByProjectId(id){
|
|
|
|
return this.model.count({
|
|
|
|
project_id: id
|
|
|
|
})
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
|
|
list (group_id){
|
|
|
|
return this.model.find({
|
|
|
|
group_id: group_id
|
|
|
|
}).exec()
|
|
|
|
}
|
|
|
|
|
|
|
|
del(id){
|
|
|
|
return this.model.deleteOne({
|
|
|
|
_id: id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
up(id, data){
|
|
|
|
data.up_time = yapi.commons.time();
|
|
|
|
return this.model.update({
|
|
|
|
_id: id,
|
|
|
|
}, data, { runValidators: true })
|
|
|
|
}
|
2017-07-03 16:16:05 +08:00
|
|
|
}
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
module.exports = interfaceModel;
|