mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-15 05:10:47 +08:00
161 lines
4.1 KiB
JavaScript
161 lines
4.1 KiB
JavaScript
const yapi = require('../yapi.js');
|
|
const baseModel = require('./base.js');
|
|
|
|
class interfaceModel extends baseModel {
|
|
getName() {
|
|
return 'interface';
|
|
}
|
|
|
|
getSchema() {
|
|
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 },
|
|
catid: {type: Number, required: true},
|
|
edit_uid: {type: Number, default: 0},
|
|
status: {type: String, enum: ['undone', 'done'], default: 'undone'},
|
|
desc: String,
|
|
add_time: Number,
|
|
up_time: Number,
|
|
type: {type: String, enum: ['static', 'var'], default:'static'},
|
|
req_query:[{
|
|
name: String, value: String, desc: String, required: {
|
|
type:String,
|
|
enum: ["1", "0"],
|
|
default: "1"
|
|
}
|
|
}],
|
|
req_headers: [{
|
|
name: String, value: String, desc: String, required: {
|
|
type:String,
|
|
enum: ["1", "0"],
|
|
default: "1"
|
|
}
|
|
}],
|
|
req_params:[{
|
|
name: String,
|
|
desc: String
|
|
}],
|
|
req_body_type: {
|
|
type: String,
|
|
enum: ['form', 'json', 'text', 'file', 'raw']
|
|
},
|
|
req_body_form: [{
|
|
name: String, type: { type: String, enum: ['text', 'file'] }, desc: String, required: {
|
|
type:String,
|
|
enum: ["1", "0"],
|
|
default: "1"
|
|
}
|
|
}],
|
|
req_body_other: String,
|
|
res_body_type: {
|
|
type: String,
|
|
enum: ['json', 'text', 'xml', 'raw']
|
|
},
|
|
res_body: String
|
|
};
|
|
}
|
|
|
|
save(data) {
|
|
let m = new this.model(data);
|
|
return m.save();
|
|
}
|
|
|
|
get(id) {
|
|
return this.model.findOne({
|
|
_id: id
|
|
})
|
|
.exec();
|
|
}
|
|
|
|
getBaseinfo(id){
|
|
return this.model.findOne({
|
|
_id: id
|
|
}).select('path method uid title project_id cat_id status').exec()
|
|
}
|
|
|
|
getVar(project_id, method){
|
|
return this.model.find({
|
|
type: 'var',
|
|
method: method
|
|
}).select('_id path').exec()
|
|
}
|
|
|
|
getByPath(project_id, path, method) {
|
|
return this.model.find({
|
|
project_id: project_id,
|
|
path: path,
|
|
method: method
|
|
})
|
|
.exec();
|
|
}
|
|
|
|
checkRepeat(id, path, method) {
|
|
return this.model.count({
|
|
project_id: id,
|
|
path: path,
|
|
method: method
|
|
});
|
|
}
|
|
|
|
countByProjectId(id) {
|
|
return this.model.count({
|
|
project_id: id
|
|
});
|
|
}
|
|
|
|
list(project_id, select) {
|
|
select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time'
|
|
return this.model.find({
|
|
project_id: project_id
|
|
})
|
|
.select(select)
|
|
.sort({ _id: -1 })
|
|
.exec();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
del(id) {
|
|
return this.model.deleteOne({
|
|
_id: id
|
|
});
|
|
}
|
|
|
|
delByCatid(id){
|
|
return this.model.deleteMany({
|
|
catid: id
|
|
})
|
|
}
|
|
|
|
delByProjectId(id){
|
|
return this.model.deleteMany({
|
|
project_id: id
|
|
})
|
|
}
|
|
|
|
up(id, data) {
|
|
data.up_time = yapi.commons.time();
|
|
return this.model.update({
|
|
_id: id
|
|
}, data, {runValidators: true });
|
|
}
|
|
|
|
upEditUid(id, uid){
|
|
return this.model.update({
|
|
_id: id
|
|
},
|
|
{edit_uid: uid},
|
|
{runValidators: true });
|
|
}
|
|
}
|
|
|
|
module.exports = interfaceModel;
|