diff --git a/database/v2.6_change_20180705.sql b/database/v2.6_change_20180705.sql new file mode 100644 index 0000000..6073bce --- /dev/null +++ b/database/v2.6_change_20180705.sql @@ -0,0 +1,2 @@ +ALTER TABLE `properties` + ADD COLUMN `pos` INT(10) NULL DEFAULT 2; \ No newline at end of file diff --git a/release/v2.6_20180705.md b/release/v2.6_20180705.md new file mode 100644 index 0000000..614e792 --- /dev/null +++ b/release/v2.6_20180705.md @@ -0,0 +1,6 @@ +# V2.6 更新说明 2018-7-5 + +* 数据库字段变更请执行 `datbase/v2.6***` +* 因字段变更,需要清空redis缓存 + 1. 运行redis-cli + 2. 执行 `flushall` 命令清空缓存 \ No newline at end of file diff --git a/src/models/bo/property.ts b/src/models/bo/property.ts index 4a63378..c11f7c8 100644 --- a/src/models/bo/property.ts +++ b/src/models/bo/property.ts @@ -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 { public static TYPES = TYPES @@ -30,8 +36,15 @@ export default class Property extends Model { 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 @@ -39,7 +52,7 @@ export default class Property extends Model { @Column({ type: DataType.STRING(128), comment: 'property generation rules' }) rule: string - @Column({ type: DataType.TEXT, comment: 'value of this property'}) + @Column({ type: DataType.TEXT, comment: 'value of this property' }) value: string @Column(DataType.TEXT) diff --git a/src/routes/repository.ts b/src/routes/repository.ts index e870734..b077098 100644 --- a/src/routes/repository.ts +++ b/src/routes/repository.ts @@ -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 } }) // 更新已存在的属性 diff --git a/src/service/postman.ts b/src/service/postman.ts index 50d6158..50681b5 100644 --- a/src/service/postman.ts +++ b/src/service/postman.ts @@ -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) } @@ -66,4 +70,22 @@ 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 })) } \ No newline at end of file