postman export V2 & request body huge update!!!

pull/275/head
Bosn 7 years ago
parent 443db96b62
commit 314c3a303e

@ -0,0 +1,2 @@
ALTER TABLE `properties`
ADD COLUMN `pos` INT(10) NULL DEFAULT 2;

@ -0,0 +1,6 @@
# V2.6 更新说明 2018-7-5
* 数据库字段变更请执行 `datbase/v2.6***`
* 因字段变更需要清空redis缓存
1. 运行redis-cli
2. 执行 `flushall` 命令清空缓存

@ -4,6 +4,12 @@ import { User, Interface, Module, Repository } from '../'
export enum SCOPES { REQUEST = 'request', RESPONSE = 'response' }
export enum TYPES { STRING = 'String', NUMBER = 'Number', BOOLEAN = 'Boolean', OBJECT = 'Object', ARRAY = 'Array', FUNCTION = 'Function', REGEXP = 'RegExp' }
export enum REQUEST_PARAMS_TYPE {
HEADERS = 1,
QUERY_PARAMS = 2,
BODY_PARAMS = 3,
}
@Table({ paranoid: true, freezeTableName: false, timestamps: true })
export default class Property extends Model<Property> {
public static TYPES = TYPES
@ -30,8 +36,15 @@ export default class Property extends Model<Property> {
type: DataType.ENUM(TYPES.STRING, TYPES.NUMBER, TYPES.BOOLEAN, TYPES.OBJECT, TYPES.ARRAY, TYPES.FUNCTION, TYPES.REGEXP),
comment: 'property type',
})
/** Data Type */
type: string
@AllowNull(false)
@Default(2)
@Column
/** request params type (position) */
pos: number
@AllowNull(false)
@Column(DataType.STRING(256))
name: string

@ -689,10 +689,27 @@ router.post('/property/update', async (ctx) => {
}
})
router.post('/properties/update', async (ctx, next) => {
let { itf } = ctx.query
let properties = ctx.request.body // JSON.parse(ctx.request.body)
const itfId = +ctx.query.itf
let { properties, summary } = ctx.request.body // JSON.parse(ctx.request.body)
properties = Array.isArray(properties) ? properties : [properties]
const itf = await Interface.findById(itfId)
if (typeof summary.name !== 'undefined') {
itf.name = summary.name
}
if (typeof summary.url !== 'undefined') {
itf.url = summary.url
}
if (typeof summary.method !== 'undefined') {
itf.method = summary.method
}
if (typeof summary.description !== 'undefined') {
itf.description = summary.description
}
await itf.save()
// 删除不在更新列表中的属性
// DONE 2.2 清除幽灵属性:子属性的父属性不存在(原因:前端删除父属性后,没有一并删除后代属性,依然传给了后端)
// SELECT * FROM properties WHERE parentId!=-1 AND parentId NOT IN (SELECT id FROM properties)
@ -711,7 +728,7 @@ router.post('/properties/update', async (ctx, next) => {
let result = await Property.destroy({
where: {
id: { [Op.notIn]: existingProperties.map((item: any) => item.id) },
interfaceId: itf
interfaceId: itfId
}
})
// 更新已存在的属性

@ -1,6 +1,7 @@
import { PostmanCollection, Folder, Item } from "../types/postman"
import { Repository, Interface, Module, Property } from "../models"
import * as url from 'url'
import { REQUEST_PARAMS_TYPE } from "../models/bo/property";
const SCHEMA_V_2_1_0 = 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
@ -48,17 +49,20 @@ export default class PostmanService {
name: itf.name,
request: {
method: itf.method as any,
header: getHeader(requestParams),
body: getBody(requestParams),
url: {
raw: itf.url,
protocol: parseResult.protocol,
protocol: parseResult.protocol || 'http',
host: parseResult.hostname ? parseResult.hostname.split('.') : [],
port: parseResult.port || '80',
port: parseResult.port || '',
hash: parseResult.hash,
query: requestParams.map(x => ({ key: x.name, value: x.value })),
path: [parseResult.path],
query: getQuery(requestParams),
},
description: itf.description,
},
response: responseParams.map(x => ({ key: x.name, vlaue: x.value })),
response: responseParams.map(x => ({ key: x.name, value: x.value })),
}
modItem.item.push(itfItem)
}
@ -67,3 +71,21 @@ export default class PostmanService {
return result
}
}
function getBody(pList: Property[]) {
return {
"mode": "formdata" as "formdata",
"formdata": pList.filter(x => x.pos === REQUEST_PARAMS_TYPE.BODY_PARAMS)
.map(x => ({ key: x.name, value: x.value, description: x.description, type: "text" as "text"})),
}
}
function getQuery(pList: Property[]) {
return pList.filter(x => x.pos === null || x.pos === REQUEST_PARAMS_TYPE.QUERY_PARAMS)
.map(x => ({ key: x.name, value: x.value, description: x.description }))
}
function getHeader(pList: Property[]) {
return pList.filter(x => x.pos === REQUEST_PARAMS_TYPE.HEADERS)
.map(x => ({ key: x.name, value: x.value, description: x.description }))
}
Loading…
Cancel
Save