fixed issues in create space model

This commit is contained in:
hannathkadher
2025-03-04 00:44:22 +04:00
parent b4c3ee486e
commit d059171b72
6 changed files with 102 additions and 70 deletions

View File

@ -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`,
);
}
}
}

View File

@ -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
? {

View File

@ -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`,
);
}
}