2017-07-03 16:16:05 +08:00
|
|
|
'use strict';
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
|
|
|
|
|
|
|
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
|
|
|
|
|
|
|
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
|
|
|
|
|
|
|
var _createClass2 = require('babel-runtime/helpers/createClass');
|
|
|
|
|
|
|
|
var _createClass3 = _interopRequireDefault(_createClass2);
|
|
|
|
|
|
|
|
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
|
|
|
|
|
|
|
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
|
|
|
|
|
|
|
var _inherits2 = require('babel-runtime/helpers/inherits');
|
|
|
|
|
|
|
|
var _inherits3 = _interopRequireDefault(_inherits2);
|
|
|
|
|
|
|
|
var _yapi = require('../yapi.js');
|
|
|
|
|
|
|
|
var _yapi2 = _interopRequireDefault(_yapi);
|
|
|
|
|
|
|
|
var _base = require('./base.js');
|
|
|
|
|
|
|
|
var _base2 = _interopRequireDefault(_base);
|
2017-07-03 16:16:05 +08:00
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
2017-07-10 11:56:53 +08:00
|
|
|
var interfaceModel = function (_baseModel) {
|
|
|
|
(0, _inherits3.default)(interfaceModel, _baseModel);
|
|
|
|
|
|
|
|
function interfaceModel() {
|
|
|
|
(0, _classCallCheck3.default)(this, interfaceModel);
|
|
|
|
return (0, _possibleConstructorReturn3.default)(this, (interfaceModel.__proto__ || (0, _getPrototypeOf2.default)(interfaceModel)).apply(this, arguments));
|
|
|
|
}
|
|
|
|
|
|
|
|
(0, _createClass3.default)(interfaceModel, [{
|
|
|
|
key: 'getName',
|
|
|
|
value: function getName() {
|
|
|
|
return 'interface';
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'getSchema',
|
|
|
|
value: function getSchema() {
|
|
|
|
return {
|
2017-07-20 16:44:41 +08:00
|
|
|
title: { type: String, required: true },
|
2017-07-10 11:56:53 +08:00
|
|
|
uid: { type: Number, required: true },
|
2017-07-20 16:44:41 +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 },
|
2017-08-18 20:35:31 +08:00
|
|
|
catid: { type: Number, required: true },
|
2017-08-17 12:03:55 +08:00
|
|
|
edit_uid: { type: Number, default: 0 },
|
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,
|
2017-08-16 10:56:42 +08:00
|
|
|
type: { type: String, enum: ['static', 'var'], default: 'static' },
|
2017-08-08 19:18:12 +08:00
|
|
|
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-08-08 19:18:12 +08:00
|
|
|
}],
|
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 17:38:22 +08:00
|
|
|
req_params: [{
|
|
|
|
name: String,
|
|
|
|
desc: String
|
|
|
|
}],
|
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,
|
2017-07-26 22:03:18 +08:00
|
|
|
enum: ['json', 'text', 'xml']
|
2017-07-10 11:56:53 +08:00
|
|
|
},
|
|
|
|
res_body: String
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'save',
|
|
|
|
value: function save(data) {
|
|
|
|
var m = new this.model(data);
|
|
|
|
return m.save();
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'get',
|
|
|
|
value: function get(id) {
|
|
|
|
return this.model.findOne({
|
|
|
|
_id: id
|
|
|
|
}).exec();
|
|
|
|
}
|
2017-08-16 10:56:42 +08:00
|
|
|
}, {
|
|
|
|
key: 'getVar',
|
|
|
|
value: function getVar(project_id, method) {
|
|
|
|
return this.model.find({
|
|
|
|
type: 'var',
|
|
|
|
method: method
|
|
|
|
}).select('_id path').exec();
|
|
|
|
}
|
2017-07-10 20:02:44 +08:00
|
|
|
}, {
|
|
|
|
key: 'getByPath',
|
2017-07-31 10:15:16 +08:00
|
|
|
value: function getByPath(project_id, path, method) {
|
2017-07-10 20:02:44 +08:00
|
|
|
return this.model.find({
|
|
|
|
project_id: project_id,
|
2017-07-31 10:15:16 +08:00
|
|
|
path: path,
|
|
|
|
method: method
|
2017-07-10 20:02:44 +08:00
|
|
|
}).exec();
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
}, {
|
|
|
|
key: 'checkRepeat',
|
2017-07-26 17:56:51 +08:00
|
|
|
value: function 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 20:02:44 +08:00
|
|
|
}, {
|
|
|
|
key: 'countByProjectId',
|
|
|
|
value: function countByProjectId(id) {
|
|
|
|
return this.model.count({
|
|
|
|
project_id: id
|
|
|
|
});
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
}, {
|
|
|
|
key: 'list',
|
2017-08-18 20:35:31 +08:00
|
|
|
value: function list(project_id, select) {
|
|
|
|
select = select || '_id title uid path method project_id catid edit_uid status desc add_time up_time';
|
2017-07-10 11:56:53 +08:00
|
|
|
return this.model.find({
|
2017-07-20 18:37:00 +08:00
|
|
|
project_id: project_id
|
2017-08-18 20:35:31 +08:00
|
|
|
}).select(select).sort({ _id: -1 }).exec();
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'listByCatid',
|
|
|
|
value: function 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();
|
2017-07-10 11:56:53 +08:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'del',
|
|
|
|
value: function del(id) {
|
|
|
|
return this.model.deleteOne({
|
|
|
|
_id: id
|
|
|
|
});
|
|
|
|
}
|
2017-08-18 20:35:31 +08:00
|
|
|
}, {
|
|
|
|
key: 'delByCatid',
|
|
|
|
value: function delByCatid(id) {
|
|
|
|
return this.model.deleteMany({
|
|
|
|
catid: id
|
|
|
|
});
|
|
|
|
}
|
2017-08-16 10:56:42 +08:00
|
|
|
}, {
|
|
|
|
key: 'delByProjectId',
|
|
|
|
value: function 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-07-10 11:56:53 +08:00
|
|
|
}, {
|
|
|
|
key: 'up',
|
|
|
|
value: function up(id, data) {
|
|
|
|
data.up_time = _yapi2.default.commons.time();
|
|
|
|
return this.model.update({
|
|
|
|
_id: id
|
|
|
|
}, data, { runValidators: true });
|
|
|
|
}
|
2017-08-17 15:19:47 +08:00
|
|
|
}, {
|
|
|
|
key: 'upEditUid',
|
|
|
|
value: function upEditUid(id, uid) {
|
|
|
|
return this.model.update({
|
|
|
|
_id: id
|
|
|
|
}, { edit_uid: uid }, { runValidators: true });
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
}]);
|
|
|
|
return interfaceModel;
|
|
|
|
}(_base2.default);
|
|
|
|
|
|
|
|
module.exports = interfaceModel;
|