mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 19:37:54 +00:00
adding tag in space model will add tag to spaces
This commit is contained in:
@@ -12,6 +12,7 @@ import { ModifyTagDto } from '../dtos/tag/modify-tag.dto';
|
||||
import { ModifySubspaceDto } from '../dtos';
|
||||
import { ProcessTagDto } from 'src/tags/dtos';
|
||||
import { TagService as NewTagService } from 'src/tags/services';
|
||||
import { SpaceModelProductAllocationEntity } from '@app/common/modules/space-model';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceProductAllocationService {
|
||||
@@ -108,6 +109,71 @@ export class SpaceProductAllocationService {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async createAllocationFromModel(
|
||||
modelAllocations: SpaceModelProductAllocationEntity[],
|
||||
queryRunner: QueryRunner,
|
||||
spaces?: SpaceEntity[],
|
||||
) {
|
||||
if (!spaces || spaces.length === 0 || !modelAllocations.length) return;
|
||||
|
||||
const allocations: SpaceProductAllocationEntity[] = [];
|
||||
|
||||
for (const space of spaces) {
|
||||
for (const modelAllocation of modelAllocations) {
|
||||
const allocation = queryRunner.manager.create(
|
||||
SpaceProductAllocationEntity,
|
||||
{
|
||||
space,
|
||||
product: modelAllocation.product,
|
||||
tags: modelAllocation.tags,
|
||||
inheritedFromModel: modelAllocation,
|
||||
},
|
||||
);
|
||||
allocations.push(allocation);
|
||||
}
|
||||
}
|
||||
|
||||
if (allocations.length > 0) {
|
||||
await queryRunner.manager.save(SpaceProductAllocationEntity, allocations);
|
||||
}
|
||||
}
|
||||
|
||||
async addTagToAllocationFromModel(
|
||||
modelAllocation: SpaceModelProductAllocationEntity,
|
||||
queryRunner: QueryRunner,
|
||||
tag: NewTagEntity,
|
||||
spaces?: SpaceEntity[],
|
||||
) {
|
||||
try {
|
||||
if (!spaces || spaces.length === 0 || !modelAllocation) return;
|
||||
|
||||
const spaceAllocations = await queryRunner.manager.find(
|
||||
SpaceProductAllocationEntity,
|
||||
{
|
||||
where: { inheritedFromModel: { uuid: modelAllocation.uuid } },
|
||||
relations: ['tags'],
|
||||
},
|
||||
);
|
||||
|
||||
if (spaceAllocations.length === 0) return;
|
||||
|
||||
for (const allocation of spaceAllocations) {
|
||||
allocation.tags.push(tag);
|
||||
}
|
||||
|
||||
await queryRunner.manager.save(
|
||||
SpaceProductAllocationEntity,
|
||||
spaceAllocations,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Failed to add tag to allocation from model',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async updateSpaceProductAllocations(
|
||||
dtos: ModifyTagDto[],
|
||||
projectUuid: string,
|
||||
@@ -285,7 +351,7 @@ export class SpaceProductAllocationService {
|
||||
});
|
||||
}
|
||||
|
||||
private createNewAllocation(
|
||||
createNewAllocation(
|
||||
space: SpaceEntity,
|
||||
tag: NewTagEntity,
|
||||
queryRunner?: QueryRunner,
|
||||
@@ -312,7 +378,7 @@ export class SpaceProductAllocationService {
|
||||
: await this.spaceProductAllocationRepository.save(allocation);
|
||||
}
|
||||
|
||||
private async saveAllocations(
|
||||
async saveAllocations(
|
||||
allocations: SpaceProductAllocationEntity[],
|
||||
queryRunner?: QueryRunner,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user