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

Commit

Permalink
fix: export project data struct (#14)
Browse files Browse the repository at this point in the history
 fix: export project data struct
  • Loading branch information
buqiyuan authored Oct 12, 2022
1 parent 5c73c6b commit dd88ff8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/modules/workspace/apiData/apiData.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@ export class ApiDataService {
async remove(id: number) {
return await this.repository.delete(id);
}
async removeByGroupIDs(groupIDs = []) {
this.repository
.createQueryBuilder()
.delete()
.from(ApiData)
.where('groupID IN (:...groupIDs)', { groupIDs })
.execute();
}
}
8 changes: 6 additions & 2 deletions src/modules/workspace/apiGroup/apiGroup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { CreateDto } from './dto/create.dto';
import { UpdateDto } from './dto/update.dto';
import { QueryDto } from './dto/query.dto';
import { ApiGroup } from '@/entities/apiGroup.entity';
import { ApiDataService } from '@/modules/workspace/apiData/apiData.service';

@Injectable()
export class ApiGroupService {
constructor(
@InjectRepository(ApiGroup)
private readonly repository: Repository<ApiGroup>,
private apiDataService: ApiDataService,
) {}

async create(createDto: CreateDto) {
Expand Down Expand Up @@ -43,7 +45,9 @@ export class ApiGroupService {
async bulkUpdate(updateDto: Array<UpdateDto>) {
return await this.repository.save(updateDto);
}
async remove(id: number) {
return await this.repository.delete(id);
async remove(ids: number[]) {
const deleteResult = await this.repository.delete(ids);
this.apiDataService.removeByGroupIDs(ids);
return deleteResult;
}
}
18 changes: 16 additions & 2 deletions src/modules/workspace/project/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,26 @@ export class ProjectController {
};
}

@Get(':uuid/export')
@Get(':uuid/export/collections')
async export(
@Param('uuid') uuid: string,
@Param('workspaceID', ParseIntPipe) workspaceID,
) {
// console.log('uuid', uuid, importDto);
return this.service.export(workspaceID, Number(uuid));
return this.service.exportCollections(workspaceID, Number(uuid));
}

@Get(':uuid/export')
async projectExport(
@Param('uuid') uuid: string,
@Param('workspaceID', ParseIntPipe) workspaceID,
) {
// console.log('uuid', uuid, importDto);
return this.service.projectExport(Number(uuid));
}

@Get(':uuid/collections')
async getProjectCollection(@Param('uuid', ParseIntPipe) uuid: number) {
return this.service.getProjectCollection(uuid);
}
}
23 changes: 22 additions & 1 deletion src/modules/workspace/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class ProjectService {
.concat(apiDataFilters);
}

async export(workspaceID: number, uuid: number) {
async exportCollections(workspaceID: number, uuid: number) {
const project = await this.findOne(workspaceID, uuid);
if (project) {
const apiData = await this.apiDataService.findAll({ projectID: uuid });
Expand Down Expand Up @@ -178,4 +178,25 @@ export class ProjectService {
return prev;
}, errors);
}

async getProjectCollection(projectID: number) {
const groups = await this.apiGroupService.findAll({ projectID });
const apis = await this.apiDataService.findAll({ projectID });

return {
groups,
apis,
};
}

async projectExport(projectID: number) {
return {
environment: await this.environmentService.findAll({
where: { projectID },
}),
group: await this.apiGroupService.findAll({ projectID }),
project: await this.repository.findOne({ where: { uuid: projectID } }),
apiData: await this.apiDataService.findAll({ projectID }),
};
}
}

0 comments on commit dd88ff8

Please sign in to comment.