diff --git a/docker-compose.yaml b/docker-compose.yaml index c80031f..4f7d9de 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -4,7 +4,7 @@ services: eoapi-remote-server: # build: 从当前路径构建镜像 build: . - image: eoapi/eoapi-remote-server:1.8.0 + image: eoapi/eoapi-remote-server:1.8.1 container_name: eoapi-remote-server restart: always env_file: diff --git a/package.json b/package.json index 105bfee..9e7b12e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eoapi-remote-server", - "version": "1.8.0", + "version": "1.8.1", "description": "Storage api data in remote server", "author": "eoapi", "private": true, diff --git a/src/app.controller.ts b/src/app.controller.ts index 85df3c5..306e395 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -1,4 +1,5 @@ import { Controller, Get } from '@nestjs/common'; +import { version } from '../package.json'; import { AppService } from './app.service'; import { Public } from '@/common/decorators/public.decorator'; @@ -15,6 +16,6 @@ export class AppController { @Get('system/status') @Public() status() { - return 'success'; + return `v${version}`; } } diff --git a/src/common/class/res.class.ts b/src/common/class/res.class.ts index 6e03a9f..39ac2fd 100644 --- a/src/common/class/res.class.ts +++ b/src/common/class/res.class.ts @@ -1,10 +1,7 @@ -import { version } from '../../../package.json'; - export class ResOp { readonly data: any; readonly statusCode: number; readonly message: string; - readonly version = version; constructor(code: number, data?: any, message = 'success') { this.statusCode = code; diff --git a/src/migrations/1665660716453-update-table_1_8_1.ts b/src/migrations/1665660716453-update-table_1_8_1.ts new file mode 100644 index 0000000..8d14ac0 --- /dev/null +++ b/src/migrations/1665660716453-update-table_1_8_1.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class updateTable1811665660716453 implements MigrationInterface { + name = 'updateTable1811665660716453' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`api_test_history\` CHANGE \`general\` \`general\` json NOT NULL`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`api_test_history\` CHANGE \`general\` \`general\` json NULL`); + } + +} diff --git a/src/modules/workspace/apiData/apiData.service.ts b/src/modules/workspace/apiData/apiData.service.ts index 7e4693b..4969954 100644 --- a/src/modules/workspace/apiData/apiData.service.ts +++ b/src/modules/workspace/apiData/apiData.service.ts @@ -54,7 +54,8 @@ export class ApiDataService { } async update(id: number, updateDto: UpdateDto) { - return await this.repository.update(id, updateDto); + await this.repository.update(id, updateDto); + return this.repository.findOneBy({ uuid: id }); } async bulkUpdate(updateDto: Array) { return await this.repository.save(updateDto); diff --git a/src/modules/workspace/apiGroup/apiGroup.controller.ts b/src/modules/workspace/apiGroup/apiGroup.controller.ts index 4b25e1e..51bfcd2 100644 --- a/src/modules/workspace/apiGroup/apiGroup.controller.ts +++ b/src/modules/workspace/apiGroup/apiGroup.controller.ts @@ -31,8 +31,13 @@ export class ApiGroupController { } @Post('batch') - async batchCreate(@Body() createDto: Array) { - return this.service.batchCreate(createDto); + async batchCreate( + @Param('projectID') projectID, + @Body() createDto: Array, + ) { + return this.service.batchCreate( + createDto.map((n) => ({ ...n, projectID })), + ); } @Get() @@ -48,13 +53,17 @@ export class ApiGroupController { return this.service.findOne({ where: { uuid, projectID } }); } @Put('batch') - async batchUpdate(@Body() updateDtos: Array) { + async batchUpdate( + @Param('projectID') projectID, + @Body() updateDtos: Array, + ) { const ids = updateDtos.map((val) => val.uuid); const array = await this.service.findByIds(ids); const newArr = array.map((el) => { const item = updateDtos.find((val) => val.uuid == el.uuid); return { ...el, + projectID, parentID: item.parentID, weight: item.weight, }; @@ -71,7 +80,7 @@ export class ApiGroupController { @Param('projectID') projectID, @Body() updateDto: UpdateDto, ) { - const data = await this.service.update(+uuid, updateDto); + const data = await this.service.update(+uuid, { ...updateDto, projectID }); if (data) { return await this.findOne(uuid, projectID); } @@ -80,8 +89,8 @@ export class ApiGroupController { } @Delete() - async remove(@Query(ValidateQueryPipe) query) { - const data = await this.service.remove(query.uuids); + async remove(@Param('projectID') projectID, @Query(ValidateQueryPipe) query) { + const data = await this.service.remove(query.uuids, projectID); if (data && data.affected > 0) { return data; } diff --git a/src/modules/workspace/apiGroup/apiGroup.service.ts b/src/modules/workspace/apiGroup/apiGroup.service.ts index 9189cac..a2ba629 100644 --- a/src/modules/workspace/apiGroup/apiGroup.service.ts +++ b/src/modules/workspace/apiGroup/apiGroup.service.ts @@ -40,13 +40,21 @@ export class ApiGroupService { } async update(id: number, updateDto: UpdateDto) { - return await this.repository.update(id, updateDto); + await this.repository.update(id, updateDto); + return this.repository.findOneBy({ uuid: id }); } async bulkUpdate(updateDto: Array) { return await this.repository.save(updateDto); } - async remove(ids: number[]) { - const deleteResult = await this.repository.delete(ids); + async remove(ids: number[], projectID: number) { + const deleteResult = await this.repository + .createQueryBuilder() + .delete() + .from(ApiGroup) + .where('uuid IN (:...ids)', { ids }) + .andWhere('projectID = :projectID', { projectID }) + .execute(); + this.apiDataService.removeByGroupIDs(ids); return deleteResult; } diff --git a/src/modules/workspace/environment/environment.controller.ts b/src/modules/workspace/environment/environment.controller.ts index 19c6fe4..ae0d29b 100644 --- a/src/modules/workspace/environment/environment.controller.ts +++ b/src/modules/workspace/environment/environment.controller.ts @@ -79,6 +79,7 @@ export class EnvironmentController { this.JSON_FIELDS.forEach((field) => { if (updateDto[field]) { updateDto[field] = JSON.stringify(updateDto[field]); + updateDto.projectID = projectID; } }); const data = await this.service.update(+uuid, updateDto); @@ -90,7 +91,7 @@ export class EnvironmentController { } @Delete(':uuid') - async remove(@Param('uuid') uuid: string) { - return this.service.remove(+uuid); + async remove(@Param('uuid') uuid: string, @Param('projectID') projectID) { + return this.service.remove(+uuid, projectID); } } diff --git a/src/modules/workspace/environment/environment.service.ts b/src/modules/workspace/environment/environment.service.ts index c8e4f27..e1a9059 100644 --- a/src/modules/workspace/environment/environment.service.ts +++ b/src/modules/workspace/environment/environment.service.ts @@ -38,7 +38,13 @@ export class EnvironmentService { return await this.repository.update(id, updateDto); } - async remove(id: number) { - return await this.repository.delete(id); + async remove(uuid: number, projectID: number) { + return this.repository + .createQueryBuilder() + .delete() + .from(Environment) + .where('uuid = :uuid', { uuid }) + .andWhere('projectID = :projectID', { projectID }) + .execute(); } } diff --git a/src/modules/workspace/project/project.controller.ts b/src/modules/workspace/project/project.controller.ts index ed9e0ee..06d4072 100644 --- a/src/modules/workspace/project/project.controller.ts +++ b/src/modules/workspace/project/project.controller.ts @@ -113,7 +113,7 @@ export class ProjectController { } @Get(':uuid/collections') - async getProjectCollection(@Param('uuid', ParseIntPipe) uuid: number) { - return this.service.getProjectCollection(uuid); + async getProjectCollections(@Param('uuid', ParseIntPipe) uuid: number) { + return this.service.getProjectCollections(uuid); } } diff --git a/src/modules/workspace/project/project.service.ts b/src/modules/workspace/project/project.service.ts index 019a847..fdf49b5 100644 --- a/src/modules/workspace/project/project.service.ts +++ b/src/modules/workspace/project/project.service.ts @@ -139,6 +139,20 @@ export class ProjectService { }); } + getJSONString(target: any) { + try { + if (typeof target === 'object') { + return target; + } else if (typeof JSON.parse(target) === 'object') { + return JSON.parse(target); + } else { + return JSON.stringify(target); + } + } catch (error) { + return JSON.stringify(target); + } + } + async importCollects( collections: Child[], projectID: number, @@ -154,8 +168,8 @@ export class ProjectService { } else { await this.apiDataService.create({ ...curr, - requestBody: curr.requestBody || [], - responseBody: curr.responseBody || [], + requestBody: this.getJSONString(curr.requestBody || []), + responseBody: this.getJSONString(curr.responseBody || []), projectID, groupID: parentID, }); @@ -179,7 +193,7 @@ export class ProjectService { }, errors); } - async getProjectCollection(projectID: number) { + async getProjectCollections(projectID: number) { const groups = await this.apiGroupService.findAll({ projectID }); const apis = await this.apiDataService.findAll({ projectID });