yapi/server/models/interface.js

112 lines
2.8 KiB
JavaScript
Raw Normal View History

import yapi from '../yapi.js';
import baseModel from './base.js';
2017-07-03 16:16:05 +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
getSchema() {
2017-07-10 11:56:53 +08:00
return {
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-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,
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-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 12:08:59 +08:00
req_body_type: {
2017-07-10 11:56:53 +08:00
type: String,
2017-08-15 12:08:59 +08:00
enum: ['form', 'json', 'text', 'file']
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,
enum: ['json', 'text', 'xml']
2017-07-10 11:56:53 +08:00
},
res_body: String
};
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
get(id) {
2017-07-10 11:56:53 +08:00
return this.model.findOne({
_id: id
})
.exec();
2017-07-10 11:56:53 +08:00
}
getByPath(project_id, path, method) {
2017-07-10 20:02:44 +08:00
return this.model.find({
project_id: project_id,
path: path,
method: method
})
.exec();
2017-07-10 20:02:44 +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-10 11:56:53 +08:00
}
countByProjectId(id) {
2017-07-10 20:02:44 +08:00
return this.model.count({
project_id: id
});
2017-07-10 20:02:44 +08:00
}
2017-07-10 11:56:53 +08:00
list(project_id) {
2017-07-10 11:56:53 +08:00
return this.model.find({
project_id: project_id
})
.sort({ _id: -1 })
.exec();
2017-07-10 11:56:53 +08:00
}
del(id) {
2017-07-10 11:56:53 +08:00
return this.model.deleteOne({
_id: id
});
2017-07-10 11:56:53 +08:00
}
2017-08-10 12:14:35 +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
}, data, { 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;