yapi/exts/yapi-plugin-advanced-mock/caseModel.js

75 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-10-17 19:52:04 +08:00
const yapi = require('yapi.js');
const baseModel = require('models/base.js');
const mongoose = require('mongoose');
2017-10-17 19:52:04 +08:00
class caseModel extends baseModel {
getName() {
2017-10-18 15:59:23 +08:00
return 'adv_mock_case';
2017-10-17 19:52:04 +08:00
}
getSchema() {
return {
interface_id: { type: Number, required: true },
project_id: {type: Number, required: true},
2017-10-18 15:59:23 +08:00
ip: {type: String},
ip_enable: {type: Boolean, default: false},
2017-10-17 19:52:04 +08:00
name: {type: String, required: true},
2017-10-18 15:59:23 +08:00
code: {type: Number, default: 200},
2017-10-19 12:09:16 +08:00
delay: {type: Number, default: 0},
2017-10-17 19:52:04 +08:00
headers: [{
name: {type: String, required: true},
value: {type: String}
}],
params: mongoose.Schema.Types.Mixed,
2017-10-17 19:52:04 +08:00
uid: String,
2017-10-19 10:31:57 +08:00
up_time: Number,
res_body: {type: String, required: true}
2017-10-17 19:52:04 +08:00
};
}
get(data) {
return this.model.findOne(data);
}
2017-10-18 15:59:23 +08:00
list(id){
return this.model.find({
interface_id: id
})
}
2017-10-17 19:52:04 +08:00
delByInterfaceId(interface_id) {
2017-10-18 10:04:16 +08:00
return this.model.remove({
2017-10-17 19:52:04 +08:00
interface_id: interface_id
});
}
delByProjectId(project_id){
2017-10-18 10:04:16 +08:00
return this.model.remove({
2017-10-17 19:52:04 +08:00
project_id: project_id
})
}
save(data) {
2017-10-18 15:59:23 +08:00
data.up_time = yapi.commons.time();
let m = new this.model(data);
return m.save();
2017-10-17 19:52:04 +08:00
}
up(data) {
2017-10-18 15:59:23 +08:00
let id = data.id;
delete data.id;
data.up_time = yapi.commons.time();
return this.model.update({
_id: id
}, data)
}
del(id){
return this.model.remove({
_id: id
})
2017-10-17 19:52:04 +08:00
}
}
module.exports = caseModel;