mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 20:34:53 +00:00
fixed issues in create space model
This commit is contained in:
@ -28,6 +28,7 @@ export class SpaceModelProductAllocationService {
|
||||
queryRunner?: QueryRunner,
|
||||
modifySubspaceModels?: ModifySubspaceModelDto[],
|
||||
): Promise<SpaceModelProductAllocationEntity[]> {
|
||||
|
||||
try {
|
||||
if (!tags.length) return [];
|
||||
|
||||
@ -37,6 +38,8 @@ export class SpaceModelProductAllocationService {
|
||||
queryRunner,
|
||||
);
|
||||
|
||||
|
||||
|
||||
const productAllocations: SpaceModelProductAllocationEntity[] = [];
|
||||
const existingAllocations = new Map<
|
||||
string,
|
||||
@ -344,26 +347,17 @@ export class SpaceModelProductAllocationService {
|
||||
|
||||
async clearAllAllocations(spaceModelUuid: string, queryRunner: QueryRunner) {
|
||||
try {
|
||||
await queryRunner.manager
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(SpaceModelProductAllocationEntity, 'allocation')
|
||||
.relation(SpaceModelProductAllocationEntity, 'tags')
|
||||
.of(
|
||||
await queryRunner.manager.find(SpaceModelProductAllocationEntity, {
|
||||
where: { spaceModel: { uuid: spaceModelUuid } },
|
||||
}),
|
||||
)
|
||||
.execute();
|
||||
|
||||
await queryRunner.manager
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(SpaceModelProductAllocationEntity)
|
||||
.where('spaceModelUuid = :spaceModelUuid', { spaceModelUuid })
|
||||
.where('space_model_uuid = :spaceModelUuid', { spaceModelUuid })
|
||||
.execute();
|
||||
} catch (error) {
|
||||
throw this.handleError(error, `Failed to clear all allocations`);
|
||||
throw this.handleError(
|
||||
error,
|
||||
`Failed to clear all allocations in the space model product allocation`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -593,6 +593,12 @@ export class SpaceModelService {
|
||||
}
|
||||
tagUuidSet.add(tag.uuid);
|
||||
} else {
|
||||
if (!tag.name || !tag.productUuid) {
|
||||
throw new HttpException(
|
||||
`Tag name and product should not be null.`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
const tagKey = `${tag.name}-${tag.productUuid}`;
|
||||
if (tagNameProductSet.has(tagKey)) {
|
||||
throw new HttpException(
|
||||
@ -668,7 +674,7 @@ export class SpaceModelService {
|
||||
uuid: tag.uuid,
|
||||
createdAt: tag.createdAt,
|
||||
updatedAt: tag.updatedAt,
|
||||
tag: tag.tag,
|
||||
name: tag.name,
|
||||
disabled: tag.disabled,
|
||||
product: tag.product
|
||||
? {
|
||||
|
||||
@ -493,16 +493,16 @@ export class SubspaceModelProductAllocationService {
|
||||
await queryRunner.manager
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from('subspace_model_product_tags') // Replace with entity name if you have one
|
||||
.where(
|
||||
'"subspace_model_product_allocation_uuid" IN (:...subspaceIds)',
|
||||
{
|
||||
subspaceIds,
|
||||
},
|
||||
)
|
||||
.from(SubspaceModelProductAllocationEntity)
|
||||
.where('"subspace_model_uuid" IN (:...subspaceIds)', {
|
||||
subspaceIds,
|
||||
})
|
||||
.execute();
|
||||
} catch (error) {
|
||||
throw this.handleError(error, `Failed to clear all allocations`);
|
||||
throw this.handleError(
|
||||
error,
|
||||
`Failed to clear all allocations subspace model product allocation`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user