mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:24:55 +00:00
clear subspace tags allocation
This commit is contained in:
@ -505,4 +505,39 @@ export class SubspaceProductAllocationService {
|
|||||||
: HttpStatus.INTERNAL_SERVER_ERROR,
|
: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
async clearAllAllocations(subspaceUuids: string[], queryRunner: QueryRunner) {
|
||||||
|
try {
|
||||||
|
await queryRunner.manager
|
||||||
|
.createQueryBuilder()
|
||||||
|
.delete()
|
||||||
|
.from('subspace_product_tags')
|
||||||
|
.where('subspace_product_allocation_uuid IN (:...allocationUuids)', {
|
||||||
|
allocationUuids: await queryRunner.manager
|
||||||
|
.createQueryBuilder(SubspaceProductAllocationEntity, 'allocation')
|
||||||
|
.select('allocation.uuid')
|
||||||
|
.where('allocation.subspaceUuid IN (:...subspaceUuids)', {
|
||||||
|
subspaceUuids,
|
||||||
|
})
|
||||||
|
.getRawMany()
|
||||||
|
.then((results) => results.map((r) => r.allocation_uuid)),
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
await queryRunner.manager
|
||||||
|
.createQueryBuilder()
|
||||||
|
.delete()
|
||||||
|
.from(SubspaceProductAllocationEntity)
|
||||||
|
.where('subspaceUuid IN (:...subspaceUuids)', { subspaceUuids })
|
||||||
|
.execute();
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
error instanceof HttpException
|
||||||
|
? error.message
|
||||||
|
: 'An unexpected error occurred while clearing allocations',
|
||||||
|
error instanceof HttpException
|
||||||
|
? error.getStatus()
|
||||||
|
: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -574,4 +574,27 @@ export class SubSpaceService {
|
|||||||
extractTagsFromSubspace(addSubspaceDto: AddSubspaceDto[]): ProcessTagDto[] {
|
extractTagsFromSubspace(addSubspaceDto: AddSubspaceDto[]): ProcessTagDto[] {
|
||||||
return addSubspaceDto.flatMap((subspace) => subspace.tags || []);
|
return addSubspaceDto.flatMap((subspace) => subspace.tags || []);
|
||||||
}
|
}
|
||||||
|
async clearSubspaces(subspaceUuids: string[], queryRunner: QueryRunner) {
|
||||||
|
try {
|
||||||
|
await queryRunner.manager.update(
|
||||||
|
SubspaceEntity,
|
||||||
|
{ uuid: In(subspaceUuids) },
|
||||||
|
{ disabled: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.subspaceProductAllocationService.clearAllAllocations(
|
||||||
|
subspaceUuids,
|
||||||
|
queryRunner,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
error instanceof HttpException
|
||||||
|
? error.message
|
||||||
|
: 'An unexpected error occurred while clearing subspaces',
|
||||||
|
error instanceof HttpException
|
||||||
|
? error.getStatus()
|
||||||
|
: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user