mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-08-25 08:22:26 +00:00
Merge pull request #483 from SyncrowIOT/refactor/duplicate-space-response
return proper response in duplicate space API
This commit is contained in:
@ -204,20 +204,23 @@ export class SpaceService {
|
||||
projectUuid,
|
||||
queryRunner,
|
||||
);
|
||||
await this.handleSpaceDuplication(spaceUuid, dto.spaceName, queryRunner);
|
||||
|
||||
const result = await this.handleSpaceDuplication(
|
||||
spaceUuid,
|
||||
dto.spaceName,
|
||||
queryRunner,
|
||||
);
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
const { data } = await this.getSpacesHierarchyForCommunity(
|
||||
{
|
||||
projectUuid,
|
||||
communityUuid,
|
||||
},
|
||||
{ onlyWithDevices: false },
|
||||
);
|
||||
return new SuccessResponseDto({
|
||||
message: `Space with ID ${spaceUuid} successfully duplicated`,
|
||||
data: result,
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
console.log((error as Error).stack);
|
||||
throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
@ -239,7 +242,6 @@ export class SpaceService {
|
||||
],
|
||||
});
|
||||
const clonedSpace = structuredClone(space);
|
||||
console.log(`creating duplicate for space ${clonedSpace.spaceName}`);
|
||||
const newSpace = queryRunner.manager.create(SpaceEntity, {
|
||||
...clonedSpace,
|
||||
spaceName: newSpaceName || clonedSpace.spaceName,
|
||||
@ -250,7 +252,6 @@ export class SpaceService {
|
||||
uuid: uuidV4(),
|
||||
});
|
||||
|
||||
console.log(`handling space ${newSpace.spaceName} allocations`);
|
||||
if (clonedSpace.productAllocations?.length) {
|
||||
newSpace.productAllocations = this.copySpaceAllocations(
|
||||
newSpace,
|
||||
@ -258,7 +259,6 @@ export class SpaceService {
|
||||
queryRunner,
|
||||
);
|
||||
}
|
||||
console.log(`handling space ${newSpace.spaceName} subspaces`);
|
||||
if (clonedSpace.subspaces?.length) {
|
||||
newSpace.subspaces = this.copySpaceSubspaces(
|
||||
newSpace,
|
||||
@ -268,7 +268,6 @@ export class SpaceService {
|
||||
}
|
||||
const savedSpace = await queryRunner.manager.save(newSpace);
|
||||
|
||||
console.log(`handling space ${newSpace.spaceName} children`);
|
||||
if (clonedSpace.children?.length) {
|
||||
for (const child of clonedSpace.children) {
|
||||
if (child.disabled) continue;
|
||||
|
Reference in New Issue
Block a user