mirror of
https://github.com/YMFE/yapi.git
synced 2025-02-17 13:49:43 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
dfa0b0f6a7
@ -5,6 +5,7 @@ import { connect } from 'react-redux'
|
||||
import PropTypes from 'prop-types'
|
||||
import Breadcrumb from '../../components/Breadcrumb/Breadcrumb'
|
||||
import { Button } from 'antd'
|
||||
import { getMockUrl } from '../../reducer/modules/news.js'
|
||||
|
||||
@connect(
|
||||
state => {
|
||||
@ -14,15 +15,30 @@ import { Button } from 'antd'
|
||||
}
|
||||
},
|
||||
{
|
||||
getMockUrl: getMockUrl
|
||||
}
|
||||
)
|
||||
|
||||
class News extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
super(props);
|
||||
this.state = {
|
||||
mockURL:""
|
||||
}
|
||||
}
|
||||
static propTypes = {
|
||||
uid: PropTypes.string
|
||||
uid: PropTypes.string,
|
||||
getMockUrl: PropTypes.func
|
||||
}
|
||||
componentWillMount(){
|
||||
const that = this;
|
||||
this.props.getMockUrl(2724).then(function(data){
|
||||
const { prd_host, basepath, protocol } = data.payload.data.data;
|
||||
const mockURL = `${protocol}://${prd_host}${basepath}/{path}`;
|
||||
that.setState({
|
||||
mockURL: mockURL
|
||||
})
|
||||
})
|
||||
}
|
||||
render () {
|
||||
return (
|
||||
@ -31,7 +47,7 @@ class News extends Component {
|
||||
<Breadcrumb />
|
||||
<div className="Mockurl">
|
||||
<span>Mock地址:</span>
|
||||
<p>mockurl</p>
|
||||
<p>{this.state.mockURL}</p>
|
||||
<Button type="primary">下载Mock数据</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -62,12 +62,14 @@ function timeago(timestamp) {
|
||||
},
|
||||
{
|
||||
fetchNewsData: fetchNewsData
|
||||
|
||||
}
|
||||
)
|
||||
class NewsTimeline extends Component {
|
||||
static propTypes = {
|
||||
newsData: PropTypes.object,
|
||||
fetchNewsData: PropTypes.func,
|
||||
|
||||
setLoading: PropTypes.func,
|
||||
loading: PropTypes.bool,
|
||||
curpage: PropTypes.number
|
||||
@ -93,8 +95,7 @@ class NewsTimeline extends Component {
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
this.props.fetchNewsData(21, this.props.curpage, 8).then(function () {
|
||||
})
|
||||
this.props.fetchNewsData(21, this.props.curpage, 8)
|
||||
}
|
||||
|
||||
|
||||
|
56
client/containers/User/Avatar.js
Normal file
56
client/containers/User/Avatar.js
Normal file
@ -0,0 +1,56 @@
|
||||
import './index.scss'
|
||||
import React, { Component } from 'react'
|
||||
// import PropTypes from 'prop-types'
|
||||
import { Upload, Icon, message } from 'antd'
|
||||
class Avatar extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
imageUrl:""
|
||||
}
|
||||
}
|
||||
handleChange(info){
|
||||
if (info.file.status === 'done') {
|
||||
// Get this url from response in real world.
|
||||
getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
|
||||
}
|
||||
}
|
||||
render() {
|
||||
const imageUrl = this.state.imageUrl;
|
||||
return <div className="avatar-box">
|
||||
<Upload
|
||||
className="avatar-uploader"
|
||||
name="avatar"
|
||||
showUploadList={true}
|
||||
action="//jsonplaceholder.typicode.com/posts/"
|
||||
beforeUpload={beforeUpload}
|
||||
onChange={this.handleChange.bind(this)} >
|
||||
{
|
||||
imageUrl ?
|
||||
<img src={imageUrl} alt="" className="avatar" /> :
|
||||
<Icon type="plus" className="avatar-uploader-trigger" />
|
||||
}
|
||||
</Upload>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
function beforeUpload(file) {
|
||||
const isJPG = file.type === 'image/jpeg';
|
||||
if (!isJPG) {
|
||||
message.error('You can only upload JPG file!');
|
||||
}
|
||||
const isLt2M = file.size / 1024 / 1024 < 2;
|
||||
if (!isLt2M) {
|
||||
message.error('Image must smaller than 2MB!');
|
||||
}
|
||||
return isJPG && isLt2M;
|
||||
}
|
||||
|
||||
function getBase64(img, callback) {
|
||||
const reader = new FileReader();
|
||||
reader.addEventListener('load', () => callback(reader.result));
|
||||
reader.readAsDataURL(img);
|
||||
}
|
||||
|
||||
export default Avatar;
|
@ -4,6 +4,7 @@ import { Row, Col, Menu, AutoComplete, Input, Icon } from 'antd'
|
||||
import axios from 'axios'
|
||||
import { connect } from 'react-redux'
|
||||
import PropTypes from 'prop-types'
|
||||
import Avatar from './Avatar.js'
|
||||
|
||||
const Option = AutoComplete.Option;
|
||||
@connect(
|
||||
@ -87,6 +88,7 @@ class LeftMenu extends Component {
|
||||
const { dataSource } = this.state;
|
||||
return (<div className="user-list">
|
||||
<div className='cur-user'>
|
||||
<Avatar />
|
||||
<div className='user-name'><span>用户名 :</span>{`${this.props.curUserName}`}</div>
|
||||
</div>
|
||||
<Row type="flex" justify="start" className="search">
|
||||
|
@ -11,6 +11,7 @@
|
||||
display: -webkit-box;
|
||||
-webkit-box-flex: 1;
|
||||
margin: 0 auto;
|
||||
margin-top: 24px;
|
||||
.user-list {
|
||||
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20);
|
||||
background: #FFF;
|
||||
@ -108,4 +109,28 @@
|
||||
border-bottom-left-radius: .04rem;
|
||||
border-bottom-right-radius: .04rem;
|
||||
}
|
||||
.avatar-uploader,
|
||||
.avatar-uploader-trigger,
|
||||
.avatar {
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
}
|
||||
.avatar-uploader {
|
||||
display: block;
|
||||
border: 1px dashed #d9d9d9;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.avatar-uploader {
|
||||
display: block;
|
||||
border: 1px dashed #d9d9d9;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.avatar-uploader-trigger {
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
font-size: 28px;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
// Actions
|
||||
const FETCH_NEWS_DATA = 'yapi/news/FETCH_NEWS_DATA';
|
||||
const FETCH_MORE_NEWS = 'yapi/news/FETCH_MORE_NEWS';
|
||||
|
||||
// Reducer
|
||||
const initialState = {
|
||||
@ -16,6 +15,9 @@ export default (state = initialState, action) => {
|
||||
case FETCH_NEWS_DATA: {
|
||||
const list = action.payload.data.data.list;
|
||||
state.newsData.list.push(...list);
|
||||
state.newsData.list.sort(function(a,b){
|
||||
return b.add_time - a.add_time;
|
||||
})
|
||||
if(list && list.length){
|
||||
state.curpage++;
|
||||
}
|
||||
@ -27,14 +29,6 @@ export default (state = initialState, action) => {
|
||||
}
|
||||
};
|
||||
}
|
||||
case FETCH_MORE_NEWS: {
|
||||
return {
|
||||
newsData: {
|
||||
...state.newsData,
|
||||
newsList: action.payload
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
@ -44,9 +38,9 @@ export default (state = initialState, action) => {
|
||||
import axios from 'axios';
|
||||
import variable from '../../constants/variable';
|
||||
|
||||
export function fetchNewsData (groupid,page,limit) {
|
||||
export function fetchNewsData (typeid,page,limit) {
|
||||
const param = {
|
||||
groupid: groupid,
|
||||
typeid: typeid,
|
||||
page: page,
|
||||
limit: limit?limit:variable.PAGE_LIMIT
|
||||
}
|
||||
@ -58,25 +52,12 @@ export function fetchNewsData (groupid,page,limit) {
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchMoreNews (current,pageSize) {
|
||||
// id,type,news,time,totalPage
|
||||
const newsList = [
|
||||
{ key: 1,title: '日志标题1', username: 'John Brown', content: '您好!亲爱的用户:您已成功申请接口:实时空气质量数据查询,请于两个月内进行应用验证,逾期接口将不能正常使用。如果您在使用的过程中遇到任何问题,欢迎前往交流社区反馈意见,谢谢!',time: '2014-12-01' },
|
||||
{ key: 2,title: '日志标题', username: 'John Brown', content: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2014-12-01' },
|
||||
{ key: 3,title: '日志标题', username: 'John Brown', content: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2014-12-01' }
|
||||
]
|
||||
console.log(current,pageSize);
|
||||
return ({
|
||||
type: FETCH_MORE_NEWS,
|
||||
payload: new Promise(function(resolve,reject){
|
||||
if(newsList){
|
||||
resolve(newsList);
|
||||
}else{
|
||||
reject("出现了错误");
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
export function getMockUrl(project_id){
|
||||
const params = {id: project_id};
|
||||
return {
|
||||
type:"",
|
||||
payload: axios.get('/project/get', {params: params})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ class interfaceColController extends baseController{
|
||||
async list(ctx){
|
||||
try {
|
||||
let id = ctx.query.project_id;
|
||||
let inst = yapi.getInst(interfaceColModel);
|
||||
let inst = this.colModel(interfaceColModel);
|
||||
let result = await inst.list(id);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
@ -59,6 +59,7 @@ class interfaceColController extends baseController{
|
||||
if(!params.name){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '名称不能为空');
|
||||
}
|
||||
|
||||
let result = await this.colModel.save({
|
||||
name: params.name,
|
||||
project_id: params.project_id,
|
||||
@ -139,6 +140,10 @@ class interfaceColController extends baseController{
|
||||
if (!params.env) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '缺少环境配置');
|
||||
}
|
||||
if (!params.path) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, 'path 不能为空');
|
||||
}
|
||||
|
||||
|
||||
if(!params.casename){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '用例名称不能为空');
|
||||
@ -181,7 +186,7 @@ class interfaceColController extends baseController{
|
||||
/**
|
||||
* 更新一个接口集name或描述
|
||||
* @interface /col/up_col
|
||||
* @method GET
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {String} name
|
||||
@ -204,9 +209,41 @@ class interfaceColController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新多个接口case index
|
||||
* @interface /col/up_col_index
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {Array} [id, index]
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async upCaseIndex(ctx){
|
||||
try{
|
||||
let params = ctx.request.body;
|
||||
if(!params || !Array.isArray(params)){
|
||||
ctx.body = yapi.commons.resReturn(null, 400, "请求参数必须是数组")
|
||||
}
|
||||
params.forEach((item) => {
|
||||
if(item.id && item.index){
|
||||
this.caseModel.upCaseIndex(item.id, item.index).then((res) => {}, (err) => {
|
||||
yapi.commons.log(err.message, 'error')
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return ctx.body = yapi.commons.resReturn('success')
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 400, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个接口集
|
||||
* @interface /col/del
|
||||
* @interface /col/del_col
|
||||
* @method GET
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
@ -216,7 +253,27 @@ class interfaceColController extends baseController{
|
||||
*/
|
||||
|
||||
async delCol(ctx){
|
||||
try{
|
||||
let id = ctx.request.body.colid;
|
||||
let colData = await this.colModel.get(id);
|
||||
if(!colData){
|
||||
ctx.body = yapi.commons.resReturn(null, 400, "不存在的id")
|
||||
}
|
||||
|
||||
if(colData.uid !== this.getUid()){
|
||||
let auth = await this.checkAuth(colData.project_id, 'project', 'danger')
|
||||
if(!auth){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
}
|
||||
|
||||
let result = await this.colModel.del(caseid);
|
||||
return ctx.body = yapi.commons.resReturn(result);
|
||||
|
||||
|
||||
}catch(e){
|
||||
yapi.commons.resReturn(null, 400, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -225,7 +282,27 @@ class interfaceColController extends baseController{
|
||||
*/
|
||||
|
||||
async delCase(ctx){
|
||||
try{
|
||||
let caseid = ctx.request.body.caseid;
|
||||
let caseData = await this.caseModel.get(caseid);
|
||||
if(!caseData){
|
||||
ctx.body = yapi.commons.resReturn(null, 400, "不存在的caseid")
|
||||
}
|
||||
|
||||
if(caseData.uid !== this.getUid()){
|
||||
let auth = await this.checkAuth(caseData.project_id, 'project', 'danger')
|
||||
if(!auth){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '没有权限');
|
||||
}
|
||||
}
|
||||
|
||||
let result = await this.caseModel.del(caseid);
|
||||
return ctx.body = yapi.commons.resReturn(result);
|
||||
|
||||
|
||||
}catch(e){
|
||||
yapi.commons.resReturn(null, 400, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,10 +11,10 @@ class logController extends baseController {
|
||||
try{
|
||||
// var res = this.Model.save({
|
||||
// uid: 107,
|
||||
// groupid: 21,
|
||||
// typeid: 21,
|
||||
// type: 'project',
|
||||
// username: 'xiaomingg',
|
||||
// content: '小明修改了 <b>小明</b> 的项目',
|
||||
// username: '小明明宝宝',
|
||||
// content: '小明应该修改了的项目宝宝',
|
||||
// time: yapi.commons.time()
|
||||
// });
|
||||
// var res = this.Model.del(107);
|
||||
@ -40,17 +40,17 @@ class logController extends baseController {
|
||||
*/
|
||||
|
||||
async list(ctx) {
|
||||
let groupid = ctx.request.query.groupid,
|
||||
let typeid = ctx.request.query.typeid,
|
||||
page = ctx.request.query.page || 1,
|
||||
limit = ctx.request.query.limit || 10;
|
||||
|
||||
if (!groupid) {
|
||||
if (!typeid) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
try {
|
||||
let result = await this.Model.listWithPaging(groupid, page, limit);
|
||||
let count = await this.Model.listCount(groupid);
|
||||
let result = await this.Model.listWithPaging(typeid, page, limit);
|
||||
let count = await this.Model.listCount(typeid);
|
||||
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
total: Math.ceil(count / limit),
|
||||
|
@ -3,7 +3,7 @@ import baseModel from './base.js';
|
||||
|
||||
class interfaceCase extends baseModel {
|
||||
getName() {
|
||||
return 'interface_col';
|
||||
return 'interface_case';
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
@ -16,7 +16,7 @@ class interfaceCase extends baseModel {
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
env: { type: String, required: true },
|
||||
domain: {type: String, required:true },
|
||||
domain: {type: String },
|
||||
path: { type: String, required: true },
|
||||
method: { type: String, required: true },
|
||||
req_query: [{
|
||||
@ -65,6 +65,14 @@ class interfaceCase extends baseModel {
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
upCaseIndex(id, index){
|
||||
return this.model.update({
|
||||
_id: id
|
||||
},{
|
||||
index: index
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = interfaceCase;
|
@ -10,7 +10,7 @@ class logModel extends baseModel {
|
||||
getSchema() {
|
||||
return {
|
||||
uid: { type: Number, required: true },
|
||||
groupid: { 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 },
|
||||
@ -29,7 +29,7 @@ class logModel extends baseModel {
|
||||
type: data.type,
|
||||
uid: data.uid,
|
||||
username: data.username,
|
||||
groupid: data.groupid,
|
||||
typeid: data.typeid,
|
||||
add_time: yapi.commons.time()
|
||||
};
|
||||
let log = new this.model(saveData);
|
||||
@ -43,26 +43,26 @@ class logModel extends baseModel {
|
||||
});
|
||||
}
|
||||
|
||||
list(groupid) {
|
||||
list(typeid) {
|
||||
return this.model.find({
|
||||
groupid: groupid
|
||||
typeid: typeid
|
||||
})
|
||||
.exec();
|
||||
}
|
||||
|
||||
|
||||
listWithPaging(groupid, page, limit) {
|
||||
listWithPaging(typeid, page, limit) {
|
||||
page = parseInt(page);
|
||||
limit = parseInt(limit);
|
||||
|
||||
return this.model.find({
|
||||
groupid: groupid
|
||||
typeid: typeid
|
||||
}).skip((page - 1) * limit).limit(limit).exec();
|
||||
}
|
||||
|
||||
listCount(groupid) {
|
||||
listCount(typeid) {
|
||||
return this.model.count({
|
||||
groupid: groupid
|
||||
typeid: typeid
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -232,14 +232,43 @@ const routerConfig = {
|
||||
}
|
||||
],
|
||||
"col": [{
|
||||
action: "add",
|
||||
path: "add",
|
||||
action: "addCol",
|
||||
path: "add_col",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "list",
|
||||
path: "list",
|
||||
method: "get"
|
||||
}]
|
||||
},{
|
||||
action: "getCaseList",
|
||||
path: "case_list",
|
||||
method: "get"
|
||||
},{
|
||||
action: "addCase",
|
||||
path: "add_case",
|
||||
method: "post"
|
||||
},{
|
||||
action: "getCase",
|
||||
path: "case",
|
||||
method: "get"
|
||||
},{
|
||||
action: "upCol",
|
||||
path: "up_col",
|
||||
method: "post"
|
||||
},{
|
||||
action: "upCaseIndex",
|
||||
path: "up_col_index",
|
||||
method: "post"
|
||||
},{
|
||||
action: "delCol",
|
||||
path: "del_col",
|
||||
method: "post"
|
||||
},{
|
||||
action: "delCase",
|
||||
path: "del_case",
|
||||
method: "post"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
for(let ctrl in routerConfig){
|
||||
@ -265,7 +294,7 @@ function createAction(controller, action, path, method) {
|
||||
if (inst.$auth === true) {
|
||||
await inst[action].call(inst, ctx);
|
||||
} else {
|
||||
ctx.body = yapi.commons.resReturn(null, 400, 'Without Permission.');
|
||||
ctx.body = yapi.commons.resReturn(null, 40011, '请登录.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ var interfaceColController = function (_baseController) {
|
||||
case 0:
|
||||
_context.prev = 0;
|
||||
id = ctx.query.project_id;
|
||||
inst = _yapi2.default.getInst(_interfaceCol2.default);
|
||||
inst = this.colModel(_interfaceCol2.default);
|
||||
_context.next = 5;
|
||||
return inst.list(id);
|
||||
|
||||
@ -321,43 +321,51 @@ var interfaceColController = function (_baseController) {
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '缺少环境配置'));
|
||||
|
||||
case 9:
|
||||
if (params.casename) {
|
||||
if (params.path) {
|
||||
_context4.next = 11;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, 'path 不能为空'));
|
||||
|
||||
case 11:
|
||||
if (params.casename) {
|
||||
_context4.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '用例名称不能为空'));
|
||||
|
||||
case 11:
|
||||
case 13:
|
||||
|
||||
params.uid = this.getUid();
|
||||
params.index = 0;
|
||||
params.add_time = _yapi2.default.commons.time();
|
||||
params.up_time = _yapi2.default.commons.time();
|
||||
_context4.next = 17;
|
||||
_context4.next = 19;
|
||||
return this.caseModel.save(params);
|
||||
|
||||
case 17:
|
||||
case 19:
|
||||
result = _context4.sent;
|
||||
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
|
||||
_context4.next = 24;
|
||||
_context4.next = 26;
|
||||
break;
|
||||
|
||||
case 21:
|
||||
_context4.prev = 21;
|
||||
case 23:
|
||||
_context4.prev = 23;
|
||||
_context4.t0 = _context4['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
||||
|
||||
case 24:
|
||||
case 26:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[0, 21]]);
|
||||
}, _callee4, this, [[0, 23]]);
|
||||
}));
|
||||
|
||||
function addCase(_x4) {
|
||||
@ -423,7 +431,7 @@ var interfaceColController = function (_baseController) {
|
||||
/**
|
||||
* 更新一个接口集name或描述
|
||||
* @interface /col/up_col
|
||||
* @method GET
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {String} name
|
||||
@ -478,9 +486,68 @@ var interfaceColController = function (_baseController) {
|
||||
return upCol;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 更新多个接口case index
|
||||
* @interface /col/up_col_index
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {Array} [id, index]
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'upCaseIndex',
|
||||
value: function () {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
var _this2 = this;
|
||||
|
||||
var params;
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
while (1) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
case 0:
|
||||
_context7.prev = 0;
|
||||
params = ctx.request.body;
|
||||
|
||||
if (!params || !Array.isArray(params)) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, "请求参数必须是数组");
|
||||
}
|
||||
params.forEach(function (item) {
|
||||
if (item.id && item.index) {
|
||||
_this2.caseModel.upCaseIndex(item.id, item.index).then(function (res) {}, function (err) {
|
||||
_yapi2.default.commons.log(err.message, 'error');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn('success'));
|
||||
|
||||
case 7:
|
||||
_context7.prev = 7;
|
||||
_context7.t0 = _context7['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, _context7.t0.message);
|
||||
|
||||
case 10:
|
||||
case 'end':
|
||||
return _context7.stop();
|
||||
}
|
||||
}
|
||||
}, _callee7, this, [[0, 7]]);
|
||||
}));
|
||||
|
||||
function upCaseIndex(_x7) {
|
||||
return _ref7.apply(this, arguments);
|
||||
}
|
||||
|
||||
return upCaseIndex;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 删除一个接口集
|
||||
* @interface /col/del
|
||||
* @interface /col/del_col
|
||||
* @method GET
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
@ -492,20 +559,66 @@ var interfaceColController = function (_baseController) {
|
||||
}, {
|
||||
key: 'delCol',
|
||||
value: function () {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
var id, colData, auth, result;
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
while (1) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
switch (_context8.prev = _context8.next) {
|
||||
case 0:
|
||||
_context8.prev = 0;
|
||||
id = ctx.request.body.colid;
|
||||
_context8.next = 4;
|
||||
return this.colModel.get(id);
|
||||
|
||||
case 4:
|
||||
colData = _context8.sent;
|
||||
|
||||
if (!colData) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, "不存在的id");
|
||||
}
|
||||
|
||||
if (!(colData.uid !== this.getUid())) {
|
||||
_context8.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
_context8.next = 9;
|
||||
return this.checkAuth(colData.project_id, 'project', 'danger');
|
||||
|
||||
case 9:
|
||||
auth = _context8.sent;
|
||||
|
||||
if (auth) {
|
||||
_context8.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '没有权限'));
|
||||
|
||||
case 12:
|
||||
_context8.next = 14;
|
||||
return this.colModel.del(caseid);
|
||||
|
||||
case 14:
|
||||
result = _context8.sent;
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
|
||||
|
||||
case 18:
|
||||
_context8.prev = 18;
|
||||
_context8.t0 = _context8['catch'](0);
|
||||
|
||||
_yapi2.default.commons.resReturn(null, 400, _context8.t0.message);
|
||||
|
||||
case 21:
|
||||
case 'end':
|
||||
return _context7.stop();
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee7, this);
|
||||
}, _callee8, this, [[0, 18]]);
|
||||
}));
|
||||
|
||||
function delCol(_x7) {
|
||||
return _ref7.apply(this, arguments);
|
||||
function delCol(_x8) {
|
||||
return _ref8.apply(this, arguments);
|
||||
}
|
||||
|
||||
return delCol;
|
||||
@ -519,20 +632,67 @@ var interfaceColController = function (_baseController) {
|
||||
}, {
|
||||
key: 'delCase',
|
||||
value: function () {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
||||
var _caseid, caseData, auth, result;
|
||||
|
||||
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
||||
while (1) {
|
||||
switch (_context8.prev = _context8.next) {
|
||||
switch (_context9.prev = _context9.next) {
|
||||
case 0:
|
||||
_context9.prev = 0;
|
||||
_caseid = ctx.request.body.caseid;
|
||||
_context9.next = 4;
|
||||
return this.caseModel.get(_caseid);
|
||||
|
||||
case 4:
|
||||
caseData = _context9.sent;
|
||||
|
||||
if (!caseData) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, "不存在的caseid");
|
||||
}
|
||||
|
||||
if (!(caseData.uid !== this.getUid())) {
|
||||
_context9.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
_context9.next = 9;
|
||||
return this.checkAuth(caseData.project_id, 'project', 'danger');
|
||||
|
||||
case 9:
|
||||
auth = _context9.sent;
|
||||
|
||||
if (auth) {
|
||||
_context9.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '没有权限'));
|
||||
|
||||
case 12:
|
||||
_context9.next = 14;
|
||||
return this.caseModel.del(_caseid);
|
||||
|
||||
case 14:
|
||||
result = _context9.sent;
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
|
||||
|
||||
case 18:
|
||||
_context9.prev = 18;
|
||||
_context9.t0 = _context9['catch'](0);
|
||||
|
||||
_yapi2.default.commons.resReturn(null, 400, _context9.t0.message);
|
||||
|
||||
case 21:
|
||||
case 'end':
|
||||
return _context8.stop();
|
||||
return _context9.stop();
|
||||
}
|
||||
}
|
||||
}, _callee8, this);
|
||||
}, _callee9, this, [[0, 18]]);
|
||||
}));
|
||||
|
||||
function delCase(_x8) {
|
||||
return _ref8.apply(this, arguments);
|
||||
function delCase(_x9) {
|
||||
return _ref9.apply(this, arguments);
|
||||
}
|
||||
|
||||
return delCase;
|
||||
|
@ -59,10 +59,10 @@ var logController = function (_baseController) {
|
||||
try {
|
||||
// var res = this.Model.save({
|
||||
// uid: 107,
|
||||
// groupid: 21,
|
||||
// typeid: 21,
|
||||
// type: 'project',
|
||||
// username: 'xiaomingg',
|
||||
// content: '小明修改了 <b>小明</b> 的项目',
|
||||
// username: '小明明宝宝',
|
||||
// content: '小明应该修改了的项目宝宝',
|
||||
// time: yapi.commons.time()
|
||||
// });
|
||||
// var res = this.Model.del(107);
|
||||
@ -91,14 +91,14 @@ var logController = function (_baseController) {
|
||||
key: 'list',
|
||||
value: function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
|
||||
var groupid, page, limit, result, count;
|
||||
var typeid, page, limit, result, count;
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
groupid = ctx.request.query.groupid, page = ctx.request.query.page || 1, limit = ctx.request.query.limit || 10;
|
||||
typeid = ctx.request.query.typeid, page = ctx.request.query.page || 1, limit = ctx.request.query.limit || 10;
|
||||
|
||||
if (groupid) {
|
||||
if (typeid) {
|
||||
_context.next = 3;
|
||||
break;
|
||||
}
|
||||
@ -108,12 +108,12 @@ var logController = function (_baseController) {
|
||||
case 3:
|
||||
_context.prev = 3;
|
||||
_context.next = 6;
|
||||
return this.Model.listWithPaging(groupid, page, limit);
|
||||
return this.Model.listWithPaging(typeid, page, limit);
|
||||
|
||||
case 6:
|
||||
result = _context.sent;
|
||||
_context.next = 9;
|
||||
return this.Model.listCount(groupid);
|
||||
return this.Model.listCount(typeid);
|
||||
|
||||
case 9:
|
||||
count = _context.sent;
|
||||
|
@ -41,7 +41,7 @@ var interfaceCase = function (_baseModel) {
|
||||
(0, _createClass3.default)(interfaceCase, [{
|
||||
key: 'getName',
|
||||
value: function getName() {
|
||||
return 'interface_col';
|
||||
return 'interface_case';
|
||||
}
|
||||
}, {
|
||||
key: 'getSchema',
|
||||
@ -55,7 +55,7 @@ var interfaceCase = function (_baseModel) {
|
||||
add_time: Number,
|
||||
up_time: Number,
|
||||
env: { type: String, required: true },
|
||||
domain: { type: String, required: true },
|
||||
domain: { type: String },
|
||||
path: { type: String, required: true },
|
||||
method: { type: String, required: true },
|
||||
req_query: [{
|
||||
@ -106,6 +106,15 @@ var interfaceCase = function (_baseModel) {
|
||||
data.up_time = _yapi2.default.commons.time();
|
||||
return this.model.update({ _id: id }, data);
|
||||
}
|
||||
}, {
|
||||
key: 'upCaseIndex',
|
||||
value: function upCaseIndex(id, index) {
|
||||
return this.model.update({
|
||||
_id: id
|
||||
}, {
|
||||
index: index
|
||||
});
|
||||
}
|
||||
}]);
|
||||
return interfaceCase;
|
||||
}(_base2.default);
|
||||
|
@ -50,7 +50,7 @@ var logModel = function (_baseModel) {
|
||||
value: function getSchema() {
|
||||
return {
|
||||
uid: { type: Number, required: true },
|
||||
groupid: { 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 },
|
||||
@ -72,7 +72,7 @@ var logModel = function (_baseModel) {
|
||||
type: data.type,
|
||||
uid: data.uid,
|
||||
username: data.username,
|
||||
groupid: data.groupid,
|
||||
typeid: data.typeid,
|
||||
add_time: _yapi2.default.commons.time()
|
||||
};
|
||||
var log = new this.model(saveData);
|
||||
@ -88,26 +88,26 @@ var logModel = function (_baseModel) {
|
||||
}
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function list(groupid) {
|
||||
value: function list(typeid) {
|
||||
return this.model.find({
|
||||
groupid: groupid
|
||||
typeid: typeid
|
||||
}).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'listWithPaging',
|
||||
value: function listWithPaging(groupid, page, limit) {
|
||||
value: function listWithPaging(typeid, page, limit) {
|
||||
page = parseInt(page);
|
||||
limit = parseInt(limit);
|
||||
|
||||
return this.model.find({
|
||||
groupid: groupid
|
||||
typeid: typeid
|
||||
}).skip((page - 1) * limit).limit(limit).exec();
|
||||
}
|
||||
}, {
|
||||
key: 'listCount',
|
||||
value: function listCount(groupid) {
|
||||
value: function listCount(typeid) {
|
||||
return this.model.count({
|
||||
groupid: groupid
|
||||
typeid: typeid
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
@ -226,13 +226,41 @@ var routerConfig = {
|
||||
"method": "get"
|
||||
}],
|
||||
"col": [{
|
||||
action: "add",
|
||||
path: "add",
|
||||
action: "addCol",
|
||||
path: "add_col",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "list",
|
||||
path: "list",
|
||||
method: "get"
|
||||
}, {
|
||||
action: "getCaseList",
|
||||
path: "case_list",
|
||||
method: "get"
|
||||
}, {
|
||||
action: "addCase",
|
||||
path: "add_case",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "getCase",
|
||||
path: "case",
|
||||
method: "get"
|
||||
}, {
|
||||
action: "upCol",
|
||||
path: "up_col",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "upCaseIndex",
|
||||
path: "up_col_index",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "delCol",
|
||||
path: "del_col",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "delCase",
|
||||
path: "del_case",
|
||||
method: "post"
|
||||
}]
|
||||
};
|
||||
|
||||
@ -282,7 +310,7 @@ function createAction(controller, action, path, method) {
|
||||
break;
|
||||
|
||||
case 8:
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, 'Without Permission.');
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 40011, '请登录.');
|
||||
|
||||
case 9:
|
||||
case 'end':
|
||||
|
Loading…
Reference in New Issue
Block a user