fork from bc4552c5a8
This commit is contained in:
39
server/models/avatar.js
Normal file
39
server/models/avatar.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const yapi = require('../yapi.js');
|
||||
const baseModel = require('./base.js');
|
||||
|
||||
class avatarModel extends baseModel {
|
||||
getName() {
|
||||
return 'avatar';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
uid: { type: Number, required: true },
|
||||
basecode: String,
|
||||
type: String
|
||||
};
|
||||
}
|
||||
|
||||
get(uid) {
|
||||
return this.model.findOne({
|
||||
uid: uid
|
||||
});
|
||||
}
|
||||
|
||||
up(uid, basecode, type) {
|
||||
return this.model.update(
|
||||
{
|
||||
uid: uid
|
||||
},
|
||||
{
|
||||
type: type,
|
||||
basecode: basecode
|
||||
},
|
||||
{
|
||||
upsert: true
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = avatarModel;
|
||||
49
server/models/base.js
Normal file
49
server/models/base.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const yapi = require('../yapi.js');
|
||||
const mongoose = require('mongoose');
|
||||
const autoIncrement = require('../utils/mongoose-auto-increment');
|
||||
|
||||
/**
|
||||
* 所有的model都需要继承baseModel, 且需要 getSchema和getName方法,不然会报错
|
||||
*/
|
||||
|
||||
class baseModel {
|
||||
constructor() {
|
||||
this.schema = new mongoose.Schema(this.getSchema());
|
||||
this.name = this.getName();
|
||||
|
||||
if (this.isNeedAutoIncrement() === true) {
|
||||
this.schema.plugin(autoIncrement.plugin, {
|
||||
model: this.name,
|
||||
field: this.getPrimaryKey(),
|
||||
startAt: 11,
|
||||
incrementBy: yapi.commons.rand(1, 10)
|
||||
});
|
||||
}
|
||||
|
||||
this.model = yapi.db(this.name, this.schema);
|
||||
}
|
||||
|
||||
isNeedAutoIncrement() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 可通过覆盖此方法生成其他自增字段
|
||||
*/
|
||||
getPrimaryKey() {
|
||||
return '_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取collection的schema结构
|
||||
*/
|
||||
getSchema() {
|
||||
yapi.commons.log('Model Class need getSchema function', 'error');
|
||||
}
|
||||
|
||||
getName() {
|
||||
yapi.commons.log('Model Class need name', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = baseModel;
|
||||
84
server/models/follow.js
Normal file
84
server/models/follow.js
Normal file
@@ -0,0 +1,84 @@
|
||||
const baseModel = require('./base.js');
|
||||
|
||||
class followModel extends baseModel {
|
||||
getName() {
|
||||
return 'follow';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
uid: { type: Number, required: true },
|
||||
projectid: { type: Number, required: true },
|
||||
projectname: { type: String, required: true },
|
||||
icon: String,
|
||||
color: String
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} uid 用户id
|
||||
* @param {Number} projectid 项目id
|
||||
* @param {String} projectname 项目名
|
||||
* @param {String} icon 项目图标
|
||||
*/
|
||||
|
||||
save(data) {
|
||||
//关注
|
||||
let saveData = {
|
||||
uid: data.uid,
|
||||
projectid: data.projectid,
|
||||
projectname: data.projectname,
|
||||
icon: data.icon,
|
||||
color: data.color
|
||||
};
|
||||
let follow = new this.model(saveData);
|
||||
return follow.save();
|
||||
}
|
||||
|
||||
del(projectid, uid) {
|
||||
return this.model.remove({
|
||||
projectid: projectid,
|
||||
uid: uid
|
||||
});
|
||||
}
|
||||
|
||||
delByProjectId(projectid){
|
||||
return this.model.remove({
|
||||
projectid: projectid
|
||||
})
|
||||
}
|
||||
|
||||
list(uid) {
|
||||
return this.model
|
||||
.find({
|
||||
uid: uid
|
||||
})
|
||||
.exec();
|
||||
}
|
||||
|
||||
listByProjectId(projectid) {
|
||||
return this.model.find({
|
||||
projectid: projectid
|
||||
});
|
||||
}
|
||||
|
||||
checkProjectRepeat(uid, projectid) {
|
||||
return this.model.countDocuments({
|
||||
uid: uid,
|
||||
projectid: projectid
|
||||
});
|
||||
}
|
||||
|
||||
updateById(id, typeid, data) {
|
||||
return this.model.update(
|
||||
{
|
||||
uid: id,
|
||||
projectid: typeid
|
||||
},
|
||||
data,
|
||||
{ runValidators: true }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = followModel;
|
||||
211
server/models/group.js
Normal file
211
server/models/group.js
Normal file
@@ -0,0 +1,211 @@
|
||||
const yapi = require('../yapi.js');
|
||||
const baseModel = require('./base.js');
|
||||
|
||||
class groupModel extends baseModel {
|
||||
getName() {
|
||||
return 'group';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
uid: Number,
|
||||
group_name: String,
|
||||
group_desc: String,
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
type: { type: String, default: 'public', enum: ['public', 'private'] },
|
||||
members: [
|
||||
{
|
||||
uid: Number,
|
||||
role: { type: String, enum: ['owner', 'dev'] },
|
||||
username: String,
|
||||
email: String
|
||||
}
|
||||
],
|
||||
|
||||
custom_field1: {
|
||||
name: String,
|
||||
enable: { type: Boolean, default: false }
|
||||
}
|
||||
// custom_field2: {
|
||||
// name: String,
|
||||
// enable: { type: Boolean, default: false }
|
||||
// },
|
||||
// custom_field3: {
|
||||
// name: String,
|
||||
// enable: { type: Boolean, default: false }
|
||||
// }
|
||||
};
|
||||
}
|
||||
|
||||
save(data) {
|
||||
let m = new this.model(data);
|
||||
return m.save();
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this.model
|
||||
.findOne({
|
||||
_id: id
|
||||
})
|
||||
.exec();
|
||||
}
|
||||
|
||||
updateMember(data) {
|
||||
return this.model.update(
|
||||
{
|
||||
'members.uid': data.uid
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
'members.$.username': data.username,
|
||||
'members.$.email': data.email
|
||||
}
|
||||
},
|
||||
{ multi: true }
|
||||
);
|
||||
}
|
||||
|
||||
getByPrivateUid(uid) {
|
||||
return this.model
|
||||
.findOne({
|
||||
uid: uid,
|
||||
type: 'private'
|
||||
})
|
||||
.select('group_name _id group_desc add_time up_time type custom_field1')
|
||||
.exec();
|
||||
}
|
||||
|
||||
getGroupById(id) {
|
||||
return this.model
|
||||
.findOne({
|
||||
_id: id
|
||||
})
|
||||
.select('uid group_name group_desc add_time up_time type custom_field1')
|
||||
.exec();
|
||||
}
|
||||
|
||||
checkRepeat(name) {
|
||||
return this.model.countDocuments({
|
||||
group_name: name
|
||||
});
|
||||
}
|
||||
// 分组数量统计
|
||||
getGroupListCount() {
|
||||
return this.model.countDocuments({ type: 'public' });
|
||||
}
|
||||
|
||||
addMember(id, data) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
{
|
||||
// $push: { members: data },
|
||||
$push: { members: { $each: data } }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
delMember(id, uid) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
{
|
||||
$pull: { members: { uid: uid } }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
changeMemberRole(id, uid, role) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id,
|
||||
'members.uid': uid
|
||||
},
|
||||
{
|
||||
$set: { 'members.$.role': role }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
checkMemberRepeat(id, uid) {
|
||||
return this.model.countDocuments({
|
||||
_id: id,
|
||||
'members.uid': uid
|
||||
});
|
||||
}
|
||||
|
||||
list() {
|
||||
return this.model
|
||||
.find({
|
||||
type: 'public'
|
||||
})
|
||||
.select('group_name _id group_desc add_time up_time type uid custom_field1')
|
||||
.exec();
|
||||
}
|
||||
|
||||
getAuthList(uid){
|
||||
return this.model.find({
|
||||
$or: [{
|
||||
'members.uid': uid,
|
||||
'type': 'public'
|
||||
}, {
|
||||
'type': 'public',
|
||||
uid
|
||||
}]
|
||||
}).select(' _id group_name group_desc add_time up_time type uid custom_field1')
|
||||
.exec();
|
||||
|
||||
}
|
||||
|
||||
findByGroups(ids = []){
|
||||
return this.model.find({
|
||||
_id: {
|
||||
$in: ids
|
||||
},
|
||||
type: 'public'
|
||||
})
|
||||
}
|
||||
|
||||
del(id) {
|
||||
return this.model.remove({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
up(id, data) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
{
|
||||
custom_field1: data.custom_field1,
|
||||
group_name: data.group_name,
|
||||
group_desc: data.group_desc,
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getcustomFieldName(name) {
|
||||
return this.model
|
||||
.find({
|
||||
'custom_field1.name': name,
|
||||
'custom_field1.enable': true
|
||||
})
|
||||
.select('_id')
|
||||
.exec();
|
||||
}
|
||||
|
||||
search(keyword) {
|
||||
return this.model
|
||||
.find({
|
||||
group_name: new RegExp(keyword, 'i')
|
||||
})
|
||||
.limit(10);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = groupModel;
|
||||
360
server/models/interface.js
Normal file
360
server/models/interface.js
Normal file
@@ -0,0 +1,360 @@
|
||||
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,
|
||||
markdown: String,
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
type: { type: String, enum: ['static', 'var'], default: 'static' },
|
||||
query_path: {
|
||||
path: String,
|
||||
params: [
|
||||
{
|
||||
name: String,
|
||||
value: String
|
||||
}
|
||||
]
|
||||
},
|
||||
req_query: [
|
||||
{
|
||||
name: String,
|
||||
value: String,
|
||||
example: String,
|
||||
desc: String,
|
||||
required: {
|
||||
type: String,
|
||||
enum: ['1', '0'],
|
||||
default: '1'
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
enum: ['string', 'number'],
|
||||
default: 'string'
|
||||
}
|
||||
}
|
||||
],
|
||||
req_headers: [
|
||||
{
|
||||
name: String,
|
||||
value: String,
|
||||
example: String,
|
||||
desc: String,
|
||||
required: {
|
||||
type: String,
|
||||
enum: ['1', '0'],
|
||||
default: '1'
|
||||
}
|
||||
}
|
||||
],
|
||||
req_params: [
|
||||
{
|
||||
name: String,
|
||||
desc: String,
|
||||
example: String,
|
||||
type: {
|
||||
type: String,
|
||||
enum: ['string', 'number'],
|
||||
default: 'string'
|
||||
}
|
||||
}
|
||||
],
|
||||
req_body_type: {
|
||||
type: String,
|
||||
enum: ['form', 'json', 'text', 'file', 'raw']
|
||||
},
|
||||
req_body_is_json_schema: { type: Boolean, default: false },
|
||||
req_body_form: [
|
||||
{
|
||||
name: String,
|
||||
type: { type: String, enum: ['text', 'file'] },
|
||||
example: String,
|
||||
value: String,
|
||||
desc: String,
|
||||
required: {
|
||||
type: String,
|
||||
enum: ['1', '0'],
|
||||
default: '1'
|
||||
}
|
||||
}
|
||||
],
|
||||
req_body_other: String,
|
||||
res_body_type: {
|
||||
type: String,
|
||||
enum: ['json', 'text', 'xml', 'raw', 'json-schema']
|
||||
},
|
||||
res_body: String,
|
||||
res_body_is_json_schema: { type: Boolean, default: false },
|
||||
custom_field_value: String,
|
||||
field2: String,
|
||||
field3: String,
|
||||
api_opened: { type: Boolean, default: false },
|
||||
index: { type: Number, default: 0 },
|
||||
tag: Array
|
||||
}
|
||||
}
|
||||
|
||||
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({
|
||||
project_id: project_id,
|
||||
type: 'var',
|
||||
method: method
|
||||
})
|
||||
.select('_id path')
|
||||
.exec()
|
||||
}
|
||||
|
||||
getByQueryPath(project_id, path, method) {
|
||||
return this.model
|
||||
.find({
|
||||
'project_id': project_id,
|
||||
'query_path.path': path,
|
||||
'method': method
|
||||
})
|
||||
.exec()
|
||||
}
|
||||
|
||||
getByPath(project_id, path, method, select) {
|
||||
select =
|
||||
select ||
|
||||
'_id title uid path method project_id catid edit_uid status add_time up_time type query_path req_query req_headers req_params req_body_type req_body_form req_body_other res_body_type custom_field_value res_body res_body_is_json_schema req_body_is_json_schema'
|
||||
return this.model
|
||||
.find({
|
||||
project_id: project_id,
|
||||
path: path,
|
||||
method: method
|
||||
})
|
||||
.select(select)
|
||||
.exec()
|
||||
}
|
||||
|
||||
checkRepeat(id, path, method) {
|
||||
return this.model.countDocuments({
|
||||
project_id: id,
|
||||
path: path,
|
||||
method: method
|
||||
})
|
||||
}
|
||||
|
||||
countByProjectId(id) {
|
||||
return this.model.countDocuments({
|
||||
project_id: id
|
||||
})
|
||||
}
|
||||
|
||||
list(project_id, select) {
|
||||
select =
|
||||
select ||
|
||||
'_id title uid path method project_id catid edit_uid status add_time up_time'
|
||||
return this.model
|
||||
.find({
|
||||
project_id: project_id
|
||||
})
|
||||
.select(select)
|
||||
.sort({ title: 1 })
|
||||
.exec()
|
||||
}
|
||||
|
||||
listWithPage(project_id, page, limit) {
|
||||
page = parseInt(page)
|
||||
limit = parseInt(limit)
|
||||
return this.model
|
||||
.find({
|
||||
project_id: project_id
|
||||
})
|
||||
.sort({ title: 1 })
|
||||
.skip((page - 1) * limit)
|
||||
.limit(limit)
|
||||
.select(
|
||||
'_id title uid path method project_id catid api_opened edit_uid status add_time up_time tag',
|
||||
)
|
||||
.exec()
|
||||
}
|
||||
|
||||
listByPid(project_id) {
|
||||
return this.model
|
||||
.find({
|
||||
project_id: project_id
|
||||
})
|
||||
.sort({ title: 1 })
|
||||
.exec()
|
||||
}
|
||||
|
||||
//获取全部接口信息
|
||||
getInterfaceListCount() {
|
||||
return this.model.countDocuments({})
|
||||
}
|
||||
|
||||
listByCatid(catid, select) {
|
||||
select =
|
||||
select ||
|
||||
'_id title uid path method project_id catid edit_uid status add_time up_time index tag'
|
||||
return this.model
|
||||
.find({
|
||||
catid: catid
|
||||
})
|
||||
.select(select)
|
||||
.sort({ index: 1 })
|
||||
.exec()
|
||||
}
|
||||
|
||||
listByCatidWithPage(catid, page, limit) {
|
||||
page = parseInt(page)
|
||||
limit = parseInt(limit)
|
||||
return this.model
|
||||
.find({
|
||||
catid: catid
|
||||
})
|
||||
.sort({ index: 1 })
|
||||
.skip((page - 1) * limit)
|
||||
.limit(limit)
|
||||
.select(
|
||||
'_id title uid path method project_id catid edit_uid api_opened status add_time up_time, index, tag',
|
||||
)
|
||||
.exec()
|
||||
}
|
||||
|
||||
listByOptionWithPage(option, page, limit) {
|
||||
page = parseInt(page)
|
||||
limit = parseInt(limit)
|
||||
return this.model
|
||||
.find(option)
|
||||
.sort({ index: 1 })
|
||||
.skip((page - 1) * limit)
|
||||
.limit(limit)
|
||||
.select(
|
||||
'_id title uid path method project_id catid edit_uid api_opened status add_time up_time, index, tag',
|
||||
)
|
||||
.exec()
|
||||
}
|
||||
|
||||
listByInterStatus(catid, status) {
|
||||
let option = {}
|
||||
if (status === 'open') {
|
||||
option = {
|
||||
catid: catid,
|
||||
api_opened: true
|
||||
}
|
||||
} else {
|
||||
option = {
|
||||
catid: catid
|
||||
}
|
||||
}
|
||||
return this.model.find(option).select().sort({ title: 1 }).exec()
|
||||
}
|
||||
|
||||
del(id) {
|
||||
return this.model.remove({
|
||||
_id: id
|
||||
})
|
||||
}
|
||||
|
||||
delByCatid(id) {
|
||||
return this.model.remove({
|
||||
catid: id
|
||||
})
|
||||
}
|
||||
|
||||
delByProjectId(id) {
|
||||
return this.model.remove({
|
||||
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 },
|
||||
)
|
||||
}
|
||||
getcustomFieldValue(id, value) {
|
||||
return this.model
|
||||
.find({
|
||||
project_id: id,
|
||||
custom_field_value: value
|
||||
})
|
||||
.select(
|
||||
'title uid path method edit_uid status desc add_time up_time type query_path req_query req_headers req_params req_body_type req_body_form req_body_other res_body_type custom_field_value',
|
||||
)
|
||||
.exec()
|
||||
}
|
||||
|
||||
listCount(option) {
|
||||
return this.model.countDocuments(option)
|
||||
}
|
||||
|
||||
upIndex(id, index) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
{
|
||||
index: index
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
search(keyword) {
|
||||
return this.model
|
||||
.find({
|
||||
$or: [
|
||||
{ title: new RegExp(keyword, 'ig') },
|
||||
{ path: new RegExp(keyword, 'ig') }
|
||||
]
|
||||
})
|
||||
.limit(10)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = interfaceModel
|
||||
135
server/models/interfaceCase.js
Normal file
135
server/models/interfaceCase.js
Normal file
@@ -0,0 +1,135 @@
|
||||
const yapi = require('../yapi.js');
|
||||
const baseModel = require('./base.js');
|
||||
var mongoose = require('mongoose');
|
||||
var Schema = mongoose.Schema;
|
||||
|
||||
class interfaceCase extends baseModel {
|
||||
getName() {
|
||||
return 'interface_case';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
casename: { type: String, required: true },
|
||||
uid: { type: Number, required: true },
|
||||
col_id: { type: Number, required: true },
|
||||
index: { type: Number, default: 0 },
|
||||
project_id: { type: Number, required: true },
|
||||
interface_id: { type: Number, required: true },
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
case_env: { type: String },
|
||||
req_params: [
|
||||
{
|
||||
name: String,
|
||||
value: String
|
||||
}
|
||||
],
|
||||
req_headers: [
|
||||
{
|
||||
name: String,
|
||||
value: String
|
||||
}
|
||||
],
|
||||
req_query: [
|
||||
{
|
||||
name: String,
|
||||
value: String,
|
||||
enable: { type: Boolean, default: true }
|
||||
}
|
||||
],
|
||||
|
||||
req_body_form: [
|
||||
{
|
||||
name: String,
|
||||
value: String,
|
||||
enable: { type: Boolean, default: true }
|
||||
}
|
||||
],
|
||||
req_body_other: String,
|
||||
test_res_body: String,
|
||||
test_status: { type: String, enum: ['ok', 'invalid', 'error', ''] },
|
||||
test_res_header: Schema.Types.Mixed,
|
||||
mock_verify: { type: Boolean, default: false },
|
||||
enable_script: { type: Boolean, default: false },
|
||||
test_script: String
|
||||
};
|
||||
}
|
||||
|
||||
save(data) {
|
||||
let m = new this.model(data);
|
||||
return m.save();
|
||||
}
|
||||
|
||||
//获取全部测试接口信息
|
||||
getInterfaceCaseListCount() {
|
||||
return this.model.countDocuments({});
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this.model
|
||||
.findOne({
|
||||
_id: id
|
||||
})
|
||||
.exec();
|
||||
}
|
||||
|
||||
list(col_id, select) {
|
||||
select = select || 'casename uid col_id _id index interface_id project_id';
|
||||
if (select === 'all') {
|
||||
return this.model
|
||||
.find({
|
||||
col_id: col_id
|
||||
})
|
||||
.exec();
|
||||
}
|
||||
return this.model
|
||||
.find({
|
||||
col_id: col_id
|
||||
})
|
||||
.select(select)
|
||||
.exec();
|
||||
}
|
||||
|
||||
del(id) {
|
||||
return this.model.remove({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
delByProjectId(id) {
|
||||
return this.model.remove({
|
||||
project_id: id
|
||||
});
|
||||
}
|
||||
|
||||
delByInterfaceId(id) {
|
||||
return this.model.remove({
|
||||
interface_id: id
|
||||
});
|
||||
}
|
||||
|
||||
delByCol(id) {
|
||||
return this.model.remove({
|
||||
col_id: id
|
||||
});
|
||||
}
|
||||
|
||||
up(id, data) {
|
||||
data.up_time = yapi.commons.time();
|
||||
return this.model.update({ _id: id }, data);
|
||||
}
|
||||
|
||||
upCaseIndex(id, index) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
{
|
||||
index: index
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = interfaceCase;
|
||||
86
server/models/interfaceCat.js
Normal file
86
server/models/interfaceCat.js
Normal file
@@ -0,0 +1,86 @@
|
||||
const yapi = require('../yapi.js');
|
||||
const baseModel = require('./base.js');
|
||||
|
||||
/**
|
||||
* 接口分类
|
||||
*/
|
||||
class interfaceCat extends baseModel {
|
||||
getName() {
|
||||
return 'interface_cat';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
name: { type: String, required: true },
|
||||
uid: { type: Number, required: true },
|
||||
project_id: { type: Number, required: true },
|
||||
desc: String,
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
index: { type: Number, default: 0 }
|
||||
};
|
||||
}
|
||||
|
||||
save(data) {
|
||||
let m = new this.model(data);
|
||||
return m.save();
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this.model
|
||||
.findOne({
|
||||
_id: id
|
||||
})
|
||||
.exec();
|
||||
}
|
||||
|
||||
checkRepeat(name) {
|
||||
return this.model.countDocuments({
|
||||
name: name
|
||||
});
|
||||
}
|
||||
|
||||
list(project_id) {
|
||||
return this.model
|
||||
.find({
|
||||
project_id: project_id
|
||||
})
|
||||
.sort({ index: 1 })
|
||||
.exec();
|
||||
}
|
||||
|
||||
del(id) {
|
||||
return this.model.remove({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
delByProjectId(id) {
|
||||
return this.model.remove({
|
||||
project_id: id
|
||||
});
|
||||
}
|
||||
|
||||
up(id, data) {
|
||||
data.up_time = yapi.commons.time();
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
upCatIndex(id, index) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
{
|
||||
index: index
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = interfaceCat;
|
||||
117
server/models/interfaceCol.js
Normal file
117
server/models/interfaceCol.js
Normal file
@@ -0,0 +1,117 @@
|
||||
const yapi = require('../yapi.js');
|
||||
const baseModel = require('./base.js');
|
||||
|
||||
class interfaceCol extends baseModel {
|
||||
getName() {
|
||||
return 'interface_col';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
name: { type: String, required: true },
|
||||
uid: { type: Number, required: true },
|
||||
project_id: { type: Number, required: true },
|
||||
desc: String,
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
index: { type: Number, default: 0 },
|
||||
test_report: { type: String, default: '{}' },
|
||||
checkHttpCodeIs200: {
|
||||
type:Boolean,
|
||||
default: false
|
||||
},
|
||||
checkResponseSchema: {
|
||||
type:Boolean,
|
||||
default: false
|
||||
},
|
||||
checkResponseField: {
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
default: "code"
|
||||
},
|
||||
value: {
|
||||
type: String,
|
||||
required: true,
|
||||
default: "0"
|
||||
},
|
||||
enable: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
checkScript: {
|
||||
content: {
|
||||
type: String
|
||||
},
|
||||
enable: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
save(data) {
|
||||
let m = new this.model(data);
|
||||
return m.save();
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this.model
|
||||
.findOne({
|
||||
_id: id
|
||||
})
|
||||
.exec();
|
||||
}
|
||||
|
||||
checkRepeat(name) {
|
||||
return this.model.countDocuments({
|
||||
name: name
|
||||
});
|
||||
}
|
||||
|
||||
list(project_id) {
|
||||
return this.model
|
||||
.find({
|
||||
project_id: project_id
|
||||
})
|
||||
.select('name uid project_id desc add_time up_time, index')
|
||||
.exec();
|
||||
}
|
||||
|
||||
del(id) {
|
||||
return this.model.remove({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
delByProjectId(id) {
|
||||
return this.model.remove({
|
||||
project_id: id
|
||||
});
|
||||
}
|
||||
|
||||
up(id, data) {
|
||||
data.up_time = yapi.commons.time();
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
upColIndex(id, index) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
{
|
||||
index: index
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = interfaceCol;
|
||||
155
server/models/log.js
Normal file
155
server/models/log.js
Normal file
@@ -0,0 +1,155 @@
|
||||
const yapi = require('../yapi.js');
|
||||
const baseModel = require('./base.js');
|
||||
var mongoose = require('mongoose');
|
||||
var Schema = mongoose.Schema;
|
||||
|
||||
class logModel extends baseModel {
|
||||
getName() {
|
||||
return 'log';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
uid: { type: Number, required: true },
|
||||
typeid: { type: Number, required: true },
|
||||
type: {
|
||||
type: String,
|
||||
enum: ['user', 'group', 'interface', 'project', 'other', 'interface_col'],
|
||||
required: true
|
||||
},
|
||||
content: { type: String, required: true },
|
||||
username: { type: String, required: true },
|
||||
add_time: Number,
|
||||
data: Schema.Types.Mixed //用于原始数据存储
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} content log内容
|
||||
* @param {Enum} type log类型, ['user', 'group', 'interface', 'project', 'other']
|
||||
* @param {Number} uid 用户id
|
||||
* @param {String} username 用户名
|
||||
* @param {Number} typeid 类型id
|
||||
* @param {Number} add_time 时间
|
||||
*/
|
||||
save(data) {
|
||||
let saveData = {
|
||||
content: data.content,
|
||||
type: data.type,
|
||||
uid: data.uid,
|
||||
username: data.username,
|
||||
typeid: data.typeid,
|
||||
add_time: yapi.commons.time(),
|
||||
data: data.data
|
||||
};
|
||||
|
||||
let log = new this.model(saveData);
|
||||
|
||||
return log.save();
|
||||
}
|
||||
|
||||
del(id) {
|
||||
return this.model.remove({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
list(typeid, type) {
|
||||
return this.model
|
||||
.find({
|
||||
typeid: typeid,
|
||||
type: type
|
||||
})
|
||||
.exec();
|
||||
}
|
||||
|
||||
listWithPaging(typeid, type, page, limit, selectValue) {
|
||||
page = parseInt(page);
|
||||
limit = parseInt(limit);
|
||||
const params = {
|
||||
type: type,
|
||||
typeid: typeid
|
||||
};
|
||||
|
||||
if (selectValue === 'wiki') {
|
||||
params['data.type'] = selectValue;
|
||||
}
|
||||
if (selectValue && !isNaN(selectValue)) {
|
||||
params['data.interface_id'] = +selectValue;
|
||||
}
|
||||
return this.model
|
||||
.find(params)
|
||||
.sort({ add_time: -1 })
|
||||
.skip((page - 1) * limit)
|
||||
.limit(limit)
|
||||
.exec();
|
||||
}
|
||||
listWithPagingByGroup(typeid, pidList, page, limit) {
|
||||
page = parseInt(page);
|
||||
limit = parseInt(limit);
|
||||
return this.model
|
||||
.find({
|
||||
$or: [
|
||||
{
|
||||
type: 'project',
|
||||
typeid: { $in: pidList }
|
||||
},
|
||||
{
|
||||
type: 'group',
|
||||
typeid: typeid
|
||||
}
|
||||
]
|
||||
})
|
||||
.sort({ add_time: -1 })
|
||||
.skip((page - 1) * limit)
|
||||
.limit(limit)
|
||||
.exec();
|
||||
}
|
||||
listCountByGroup(typeid, pidList) {
|
||||
return this.model.countDocuments({
|
||||
$or: [
|
||||
{
|
||||
type: 'project',
|
||||
typeid: { $in: pidList }
|
||||
},
|
||||
{
|
||||
type: 'group',
|
||||
typeid: typeid
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
listCount(typeid, type, selectValue) {
|
||||
const params = {
|
||||
type: type,
|
||||
typeid: typeid
|
||||
};
|
||||
|
||||
if (selectValue === 'wiki') {
|
||||
params['data.type'] = selectValue;
|
||||
}
|
||||
|
||||
if (selectValue && !isNaN(selectValue)) {
|
||||
params['data.interface_id'] = +selectValue;
|
||||
}
|
||||
return this.model.countDocuments(params);
|
||||
}
|
||||
|
||||
listWithCatid(typeid, type, interfaceId) {
|
||||
const params = {
|
||||
type: type,
|
||||
typeid: typeid
|
||||
};
|
||||
if (interfaceId && !isNaN(interfaceId)) {
|
||||
params['data.interface_id'] = +interfaceId;
|
||||
}
|
||||
return this.model
|
||||
.find(params)
|
||||
.sort({ add_time: -1 })
|
||||
.limit(1)
|
||||
.select('uid content type username typeid add_time')
|
||||
.exec();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = logModel;
|
||||
309
server/models/project.js
Normal file
309
server/models/project.js
Normal file
@@ -0,0 +1,309 @@
|
||||
const yapi = require('../yapi.js');
|
||||
const baseModel = require('./base.js');
|
||||
|
||||
class projectModel extends baseModel {
|
||||
getName() {
|
||||
return 'project';
|
||||
}
|
||||
|
||||
constructor(){
|
||||
super()
|
||||
this.handleEnvNullData = this.handleEnvNullData.bind(this)
|
||||
}
|
||||
|
||||
getAuthList(uid){
|
||||
return this.model.find({
|
||||
$or: [{
|
||||
'members.uid': uid,
|
||||
project_type: 'private'
|
||||
}, {
|
||||
uid,
|
||||
project_type: 'private'
|
||||
}, {
|
||||
project_type: 'public'
|
||||
}]
|
||||
}).select('group_id')
|
||||
.exec();
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
uid: { type: Number, required: true },
|
||||
name: { type: String, required: true },
|
||||
basepath: { type: String },
|
||||
switch_notice: { type: Boolean, default: true },
|
||||
desc: String,
|
||||
group_id: { type: Number, required: true },
|
||||
project_type: { type: String, required: true, enum: ['public', 'private'] },
|
||||
members: [
|
||||
{
|
||||
uid: Number,
|
||||
role: { type: String, enum: ['owner', 'dev'] },
|
||||
username: String,
|
||||
email: String,
|
||||
email_notice: { type: Boolean, default: true }
|
||||
}
|
||||
],
|
||||
env: [{ name: String, domain: String, header: Array, global: [{
|
||||
name: String,
|
||||
value: String
|
||||
}] }],
|
||||
icon: String,
|
||||
color: String,
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
pre_script: String,
|
||||
after_script: String,
|
||||
project_mock_script: String,
|
||||
is_mock_open: { type: Boolean, default: false },
|
||||
strice: { type: Boolean, default: false },
|
||||
is_json5: { type: Boolean, default: true },
|
||||
tag: [{name: String, desc: String}]
|
||||
};
|
||||
}
|
||||
|
||||
updateMember(data) {
|
||||
return this.model.update(
|
||||
{
|
||||
'members.uid': data.uid
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
'members.$.username': data.username,
|
||||
'members.$.email': data.email
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
save(data) {
|
||||
let m = new this.model(data);
|
||||
return m.save();
|
||||
}
|
||||
|
||||
handleEnvNullData(data){
|
||||
if (data == null) {
|
||||
return false;
|
||||
}
|
||||
data = data.toObject();
|
||||
data.toObject = ()=> data;
|
||||
let isFix = false;
|
||||
if(Array.isArray(data.env)){
|
||||
data.env = data.env.map(item=>{
|
||||
item.global = item.global.filter(g=>{
|
||||
if(!g || typeof g !== 'object'){
|
||||
isFix = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
}
|
||||
|
||||
if(isFix){
|
||||
this.model.update(
|
||||
{
|
||||
_id: data._id
|
||||
|
||||
},
|
||||
{
|
||||
$set: { env: data.env }
|
||||
},
|
||||
{ runValidators: true }
|
||||
);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this.model
|
||||
.findOne({
|
||||
_id: id
|
||||
})
|
||||
.exec().then(this.handleEnvNullData)
|
||||
}
|
||||
|
||||
getByEnv(id) {
|
||||
return this.model
|
||||
.findOne({
|
||||
_id: id
|
||||
})
|
||||
.select('env')
|
||||
.exec().then(this.handleEnvNullData);
|
||||
}
|
||||
|
||||
getProjectWithAuth(group_id, uid) {
|
||||
return this.model.countDocuments({
|
||||
group_id: group_id,
|
||||
'members.uid': uid
|
||||
});
|
||||
}
|
||||
|
||||
getBaseInfo(id, select) {
|
||||
select =
|
||||
select ||
|
||||
'_id uid name basepath switch_notice desc group_id project_type env icon color add_time up_time pre_script after_script project_mock_script is_mock_open strice is_json5 tag';
|
||||
return this.model
|
||||
.findOne({
|
||||
_id: id
|
||||
})
|
||||
.select(select)
|
||||
.exec().then(this.handleEnvNullData);
|
||||
}
|
||||
|
||||
getByDomain(domain) {
|
||||
return this.model
|
||||
.find({
|
||||
prd_host: domain
|
||||
})
|
||||
.exec().then(this.handleEnvNullData);
|
||||
}
|
||||
|
||||
checkNameRepeat(name, groupid) {
|
||||
return this.model.countDocuments({
|
||||
name: name,
|
||||
group_id: groupid
|
||||
});
|
||||
}
|
||||
|
||||
checkDomainRepeat(domain, basepath) {
|
||||
return this.model.countDocuments({
|
||||
prd_host: domain,
|
||||
basepath: basepath
|
||||
});
|
||||
}
|
||||
|
||||
list(group_id) {
|
||||
let params = { group_id: group_id };
|
||||
return this.model
|
||||
.find(params)
|
||||
.select(
|
||||
'_id uid name basepath switch_notice desc group_id project_type color icon env add_time up_time'
|
||||
)
|
||||
.sort({ _id: -1 })
|
||||
.exec();
|
||||
}
|
||||
|
||||
// 获取项目数量统计
|
||||
getProjectListCount() {
|
||||
return this.model.countDocuments();
|
||||
}
|
||||
|
||||
countWithPublic(group_id) {
|
||||
let params = { group_id: group_id, project_type: 'public' };
|
||||
return this.model.countDocuments(params);
|
||||
}
|
||||
|
||||
listWithPaging(group_id, page, limit) {
|
||||
page = parseInt(page);
|
||||
limit = parseInt(limit);
|
||||
return this.model
|
||||
.find({
|
||||
group_id: group_id
|
||||
})
|
||||
.sort({ _id: -1 })
|
||||
.skip((page - 1) * limit)
|
||||
.limit(limit)
|
||||
.exec();
|
||||
}
|
||||
|
||||
listCount(group_id) {
|
||||
return this.model.countDocuments({
|
||||
group_id: group_id
|
||||
});
|
||||
}
|
||||
|
||||
countByGroupId(group_id) {
|
||||
return this.model.countDocuments({
|
||||
group_id: group_id
|
||||
});
|
||||
}
|
||||
|
||||
del(id) {
|
||||
return this.model.remove({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
delByGroupid(groupId) {
|
||||
return this.model.remove({
|
||||
group_id: groupId
|
||||
});
|
||||
}
|
||||
|
||||
up(id, data) {
|
||||
data.up_time = yapi.commons.time();
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
data,
|
||||
{ runValidators: true }
|
||||
);
|
||||
}
|
||||
|
||||
addMember(id, data) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
{
|
||||
// $push: { members: data }
|
||||
$push: { members: { $each: data } }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
delMember(id, uid) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
{
|
||||
$pull: { members: { uid: uid } }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
checkMemberRepeat(id, uid) {
|
||||
return this.model.countDocuments({
|
||||
_id: id,
|
||||
'members.uid': uid
|
||||
});
|
||||
}
|
||||
|
||||
changeMemberRole(id, uid, role) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id,
|
||||
'members.uid': uid
|
||||
},
|
||||
{
|
||||
$set: { 'members.$.role': role }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
changeMemberEmailNotice(id, uid, notice) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id,
|
||||
'members.uid': uid
|
||||
},
|
||||
{
|
||||
$set: { 'members.$.email_notice': notice }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
search(keyword) {
|
||||
return this.model
|
||||
.find({
|
||||
name: new RegExp(keyword, 'ig')
|
||||
})
|
||||
.limit(10);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = projectModel;
|
||||
70
server/models/storage.js
Normal file
70
server/models/storage.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const baseModel = require('./base.js');
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
class stroageModel extends baseModel {
|
||||
constructor() {
|
||||
super()
|
||||
let storageCol = mongoose.connection.db.collection('storage');
|
||||
storageCol.createIndex(
|
||||
{
|
||||
key: 1
|
||||
},
|
||||
{
|
||||
unique: true
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getName() {
|
||||
return 'storage';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
key: { type: Number, required: true },
|
||||
data: {
|
||||
type: String,
|
||||
default: ''
|
||||
} //用于原始数据存储
|
||||
};
|
||||
}
|
||||
save(key, data = {}, isInsert = false) {
|
||||
|
||||
let saveData = {
|
||||
key,
|
||||
data: JSON.stringify(data, null, 2)
|
||||
};
|
||||
if(isInsert){
|
||||
let r = new this.model(saveData);
|
||||
return r.save();
|
||||
}
|
||||
return this.model.updateOne({
|
||||
key
|
||||
}, saveData)
|
||||
}
|
||||
|
||||
del(key) {
|
||||
return this.model.remove({
|
||||
key
|
||||
});
|
||||
}
|
||||
|
||||
get(key) {
|
||||
return this.model
|
||||
.findOne({
|
||||
key
|
||||
})
|
||||
.exec().then(data => {
|
||||
this.save(key, {})
|
||||
if (!data) return null;
|
||||
data = data.toObject().data;
|
||||
try {
|
||||
return JSON.parse(data)
|
||||
} catch (e) {
|
||||
return {}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = stroageModel;
|
||||
48
server/models/token.js
Normal file
48
server/models/token.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const yapi = require('../yapi.js');
|
||||
const baseModel = require('./base.js');
|
||||
|
||||
class tokenModel extends baseModel {
|
||||
getName() {
|
||||
return 'token';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
project_id: { type: Number, required: true },
|
||||
token: String
|
||||
};
|
||||
}
|
||||
|
||||
save(data) {
|
||||
let m = new this.model(data);
|
||||
return m.save();
|
||||
}
|
||||
|
||||
get(project_id) {
|
||||
return this.model.findOne({
|
||||
project_id: project_id
|
||||
});
|
||||
}
|
||||
|
||||
findId(token) {
|
||||
return this.model
|
||||
.findOne({
|
||||
token: token
|
||||
})
|
||||
.select('project_id')
|
||||
.exec();
|
||||
}
|
||||
|
||||
up(project_id, token) {
|
||||
return this.model.update(
|
||||
{
|
||||
project_id: project_id
|
||||
},
|
||||
{
|
||||
token: token
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = tokenModel;
|
||||
114
server/models/user.js
Normal file
114
server/models/user.js
Normal file
@@ -0,0 +1,114 @@
|
||||
const baseModel = require('./base.js');
|
||||
|
||||
class userModel extends baseModel {
|
||||
getName() {
|
||||
return 'user';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return {
|
||||
username: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
passsalt: String,
|
||||
study: { type: Boolean, default: false },
|
||||
role: String,
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
type: { type: String, enum: ['site', 'third'], default: 'site' } //site用户是网站注册用户, third是第三方登录过来的用户
|
||||
};
|
||||
}
|
||||
|
||||
save(data) {
|
||||
let user = new this.model(data);
|
||||
return user.save();
|
||||
}
|
||||
|
||||
checkRepeat(email) {
|
||||
return this.model.countDocuments({
|
||||
email: email
|
||||
});
|
||||
}
|
||||
|
||||
list() {
|
||||
return this.model
|
||||
.find()
|
||||
.select('_id username email role type add_time up_time study')
|
||||
.exec(); //显示id name email role
|
||||
}
|
||||
|
||||
findByUids(uids) {
|
||||
return this.model
|
||||
.find({
|
||||
_id: { $in: uids }
|
||||
})
|
||||
.select('_id username email role type add_time up_time study')
|
||||
.exec();
|
||||
}
|
||||
|
||||
listWithPaging(page, limit) {
|
||||
page = parseInt(page);
|
||||
limit = parseInt(limit);
|
||||
return this.model
|
||||
.find()
|
||||
.sort({ _id: -1 })
|
||||
.skip((page - 1) * limit)
|
||||
.limit(limit)
|
||||
.select('_id username email role type add_time up_time study')
|
||||
.exec();
|
||||
}
|
||||
|
||||
listCount() {
|
||||
return this.model.countDocuments();
|
||||
}
|
||||
|
||||
findByEmail(email) {
|
||||
return this.model.findOne({ email: email });
|
||||
}
|
||||
|
||||
findById(id) {
|
||||
return this.model.findOne({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
del(id) {
|
||||
return this.model.remove({
|
||||
_id: id
|
||||
});
|
||||
}
|
||||
|
||||
update(id, data) {
|
||||
return this.model.update(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
search(keyword) {
|
||||
return this.model
|
||||
.find(
|
||||
{
|
||||
$or: [{ email: new RegExp(keyword, 'i') }, { username: new RegExp(keyword, 'i') }]
|
||||
},
|
||||
{
|
||||
passsalt: 0,
|
||||
password: 0
|
||||
}
|
||||
)
|
||||
.limit(10);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = userModel;
|
||||
Reference in New Issue
Block a user