mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 01:04:54 +00:00
added proper validations
This commit is contained in:
@ -124,15 +124,56 @@ export class SpaceModelProductAllocationService {
|
||||
modifySubspaceModels?: ModifySubspaceModelDto[],
|
||||
): Promise<void> {
|
||||
try {
|
||||
const addDtos = dtos.filter((dto) => dto.action === ModifyAction.ADD);
|
||||
const deleteDtos = dtos.filter(
|
||||
(dto) => dto.action === ModifyAction.DELETE,
|
||||
);
|
||||
|
||||
const addTagDtos: ProcessTagDto[] = addDtos.map((dto) => ({
|
||||
name: dto.name,
|
||||
productUuid: dto.productUuid,
|
||||
uuid: dto.newTagUuid,
|
||||
}));
|
||||
|
||||
const processedTags = await this.tagService.processTags(
|
||||
addTagDtos,
|
||||
projectUuid,
|
||||
queryRunner,
|
||||
);
|
||||
const addTagUuidMap = new Map<string, ModifyTagModelDto>();
|
||||
processedTags.forEach((tag, index) => {
|
||||
addTagUuidMap.set(tag.uuid, addDtos[index]);
|
||||
});
|
||||
|
||||
const addTagUuids = new Set(processedTags.map((tag) => tag.uuid));
|
||||
const deleteTagUuids = new Set(deleteDtos.map((dto) => dto.tagUuid));
|
||||
|
||||
const tagsToIgnore = new Set(
|
||||
[...addTagUuids].filter((uuid) => deleteTagUuids.has(uuid)),
|
||||
);
|
||||
|
||||
const filteredDtos = dtos.filter(
|
||||
(dto) =>
|
||||
!(
|
||||
tagsToIgnore.has(dto.tagUuid) ||
|
||||
(dto.action === ModifyAction.ADD &&
|
||||
tagsToIgnore.has(
|
||||
[...addTagUuidMap.keys()].find(
|
||||
(uuid) => addTagUuidMap.get(uuid) === dto,
|
||||
),
|
||||
))
|
||||
),
|
||||
);
|
||||
|
||||
await Promise.all([
|
||||
this.processAddActions(
|
||||
dtos,
|
||||
filteredDtos,
|
||||
projectUuid,
|
||||
spaceModel,
|
||||
queryRunner,
|
||||
modifySubspaceModels,
|
||||
),
|
||||
this.processDeleteActions(dtos, queryRunner),
|
||||
this.processDeleteActions(filteredDtos, queryRunner),
|
||||
]);
|
||||
} catch (error) {
|
||||
throw this.handleError(error, 'Error while updating product allocations');
|
||||
@ -238,7 +279,7 @@ export class SpaceModelProductAllocationService {
|
||||
): Promise<SpaceModelProductAllocationEntity[]> {
|
||||
try {
|
||||
if (!dtos || dtos.length === 0) {
|
||||
throw new Error('No DTOs provided for deletion.');
|
||||
return;
|
||||
}
|
||||
|
||||
const tagUuidsToDelete = dtos
|
||||
|
||||
Reference in New Issue
Block a user