2017-09-03 08:43:13 +08:00
|
|
|
const yapi = require('../yapi.js');
|
|
|
|
const baseModel = require('./base.js');
|
2017-08-08 19:18:34 +08:00
|
|
|
|
|
|
|
class interfaceCase extends baseModel {
|
|
|
|
getName() {
|
2017-08-09 20:01:51 +08:00
|
|
|
return 'interface_case';
|
2017-08-08 19:18:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getSchema() {
|
|
|
|
return {
|
|
|
|
casename: { type: String, required: true },
|
|
|
|
uid: { type: Number, required: true },
|
|
|
|
col_id: { type: Number, required: true },
|
2017-08-21 15:52:22 +08:00
|
|
|
index: { type: Number, default: 0 },
|
2017-08-08 19:18:34 +08:00
|
|
|
project_id: { type: Number, required: true },
|
2017-08-28 15:19:07 +08:00
|
|
|
interface_id: { type: Number, required: true },
|
2017-08-08 19:18:34 +08:00
|
|
|
add_time: Number,
|
|
|
|
up_time: Number,
|
2017-08-29 10:01:27 +08:00
|
|
|
case_env: { type: String },
|
2017-08-28 15:19:07 +08:00
|
|
|
// path: { type: String },
|
|
|
|
// method: { type: String },
|
2017-08-17 11:24:46 +08:00
|
|
|
req_params: [{
|
|
|
|
name: String, value: String
|
2017-08-21 15:52:22 +08:00
|
|
|
}],
|
2017-08-08 19:18:34 +08:00
|
|
|
req_query: [{
|
|
|
|
name: String, value: String
|
|
|
|
}],
|
2017-08-28 15:19:07 +08:00
|
|
|
// req_headers: [{
|
|
|
|
// name: String, value: String
|
|
|
|
// }],
|
|
|
|
// req_body_type: {
|
|
|
|
// type: String,
|
|
|
|
// enum: ['form', 'json', 'text', 'xml']
|
|
|
|
// },
|
2017-08-24 17:02:39 +08:00
|
|
|
req_body_form: [{
|
2017-08-08 19:18:34 +08:00
|
|
|
name: String, value: String
|
|
|
|
}],
|
2017-08-24 17:02:39 +08:00
|
|
|
req_body_other: String
|
2017-08-08 19:18:34 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
save(data) {
|
|
|
|
let m = new this.model(data);
|
|
|
|
return m.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
get(id) {
|
|
|
|
return this.model.findOne({
|
|
|
|
_id: id
|
|
|
|
}).exec();
|
|
|
|
}
|
|
|
|
|
2017-08-21 15:52:22 +08:00
|
|
|
list(col_id, select) {
|
|
|
|
select = select || 'casename uid col_id _id index'
|
|
|
|
if (select === 'all') {
|
|
|
|
return this.model.find({
|
|
|
|
col_id: col_id
|
|
|
|
}).exec();
|
|
|
|
}
|
2017-08-14 19:58:33 +08:00
|
|
|
return this.model.find({
|
|
|
|
col_id: col_id
|
|
|
|
}).select("casename uid col_id _id index").exec();
|
2017-08-08 19:18:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
del(id) {
|
|
|
|
return this.model.deleteOne({
|
|
|
|
_id: id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-21 15:52:22 +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-08-28 18:01:28 +08:00
|
|
|
delByInterfaceId(id){
|
|
|
|
return this.model.deleteMany({
|
|
|
|
interface_id: id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-21 15:52:22 +08:00
|
|
|
delByCol(id) {
|
2017-08-18 20:35:31 +08:00
|
|
|
return this.model.deleteMany({
|
|
|
|
col_id: id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-08 19:18:34 +08:00
|
|
|
up(id, data) {
|
|
|
|
data.up_time = yapi.commons.time()
|
|
|
|
return this.model.update(
|
|
|
|
{ _id: id },
|
|
|
|
data
|
|
|
|
);
|
|
|
|
}
|
2017-08-09 20:01:51 +08:00
|
|
|
|
2017-08-21 15:52:22 +08:00
|
|
|
upCaseIndex(id, index) {
|
2017-08-09 20:01:51 +08:00
|
|
|
return this.model.update({
|
|
|
|
_id: id
|
2017-08-21 15:52:22 +08:00
|
|
|
}, {
|
|
|
|
index: index
|
|
|
|
})
|
2017-08-09 20:01:51 +08:00
|
|
|
}
|
2017-08-08 19:18:34 +08:00
|
|
|
}
|
|
|
|
|
2017-08-22 10:02:50 +08:00
|
|
|
module.exports = interfaceCase;
|