Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
chore: relese 1.8.1 (#15)
Browse files Browse the repository at this point in the history
* fix: add projectID for dto

* fix: sync workspace error

* fix: import data will lose

* chore: 1.8.1
  • Loading branch information
buqiyuan authored Oct 13, 2022
1 parent dd88ff8 commit 0421bad
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -15,6 +16,6 @@ export class AppController {
@Get('system/status')
@Public()
status() {
return 'success';
return `v${version}`;
}
}
3 changes: 0 additions & 3 deletions src/common/class/res.class.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/migrations/1665660716453-update-table_1_8_1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class updateTable1811665660716453 implements MigrationInterface {
name = 'updateTable1811665660716453'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`api_test_history\` CHANGE \`general\` \`general\` json NOT NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`api_test_history\` CHANGE \`general\` \`general\` json NULL`);
}

}
3 changes: 2 additions & 1 deletion src/modules/workspace/apiData/apiData.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UpdateDto>) {
return await this.repository.save(updateDto);
Expand Down
21 changes: 15 additions & 6 deletions src/modules/workspace/apiGroup/apiGroup.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ export class ApiGroupController {
}

@Post('batch')
async batchCreate(@Body() createDto: Array<CreateDto>) {
return this.service.batchCreate(createDto);
async batchCreate(
@Param('projectID') projectID,
@Body() createDto: Array<CreateDto>,
) {
return this.service.batchCreate(
createDto.map((n) => ({ ...n, projectID })),
);
}

@Get()
Expand All @@ -48,13 +53,17 @@ export class ApiGroupController {
return this.service.findOne({ where: { uuid, projectID } });
}
@Put('batch')
async batchUpdate(@Body() updateDtos: Array<UpdateDto>) {
async batchUpdate(
@Param('projectID') projectID,
@Body() updateDtos: Array<UpdateDto>,
) {
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,
};
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand Down
14 changes: 11 additions & 3 deletions src/modules/workspace/apiGroup/apiGroup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UpdateDto>) {
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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/modules/workspace/environment/environment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
10 changes: 8 additions & 2 deletions src/modules/workspace/environment/environment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 2 additions & 2 deletions src/modules/workspace/project/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
20 changes: 17 additions & 3 deletions src/modules/workspace/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
});
Expand All @@ -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 });

Expand Down

0 comments on commit 0421bad

Please sign in to comment.