mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 07:54:53 +00:00
added validation for subspaces
This commit is contained in:
@ -530,7 +530,7 @@ export class SpaceService {
|
||||
}
|
||||
|
||||
throw new HttpException(
|
||||
'An error occurred while updating the space',
|
||||
`An error occurred while updating the space: error ${error}`,
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
} finally {
|
||||
|
||||
@ -79,10 +79,9 @@ export class SubspaceProductAllocationService {
|
||||
spaceTagUpdateDtos?: ModifyTagDto[],
|
||||
) {
|
||||
const spaceAllocationToExclude: SpaceProductAllocationEntity[] = [];
|
||||
|
||||
for (const subspace of subspaces) {
|
||||
if (!subspace.tags || subspace.tags.length === 0) continue;
|
||||
const tagDtos = subspace.tags;
|
||||
if (tagDtos.length > 0) {
|
||||
const tagsToAddDto: ProcessTagDto[] = tagDtos
|
||||
.filter((dto) => dto.action === ModifyAction.ADD)
|
||||
.map((dto) => ({
|
||||
@ -293,7 +292,6 @@ export class SubspaceProductAllocationService {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async processDeleteActions(
|
||||
dtos: ModifyTagDto[],
|
||||
|
||||
@ -324,6 +324,9 @@ export class SubSpaceService {
|
||||
projectUuid?: string,
|
||||
spaceTagUpdateDtos?: ModifyTagDto[],
|
||||
) {
|
||||
if (!subspaceDtos || subspaceDtos.length === 0) {
|
||||
return;
|
||||
}
|
||||
const addedSubspaces = [];
|
||||
const updatedSubspaces = [];
|
||||
|
||||
@ -335,14 +338,17 @@ export class SubSpaceService {
|
||||
space,
|
||||
queryRunner,
|
||||
);
|
||||
addedSubspaces.push(addedSubspace);
|
||||
if (addedSubspace) addedSubspaces.push(addedSubspace);
|
||||
|
||||
break;
|
||||
case ModifyAction.UPDATE:
|
||||
const updatedSubspace = await this.handleUpdateAction(
|
||||
subspace,
|
||||
queryRunner,
|
||||
);
|
||||
if (updatedSubspace) {
|
||||
updatedSubspaces.push(updatedSubspace);
|
||||
}
|
||||
break;
|
||||
case ModifyAction.DELETE:
|
||||
await this.handleDeleteAction(subspace, queryRunner);
|
||||
@ -355,7 +361,9 @@ export class SubSpaceService {
|
||||
}
|
||||
}
|
||||
|
||||
const combinedSubspaces = [...addedSubspaces, ...updatedSubspaces];
|
||||
const combinedSubspaces = [...addedSubspaces, ...updatedSubspaces].filter(
|
||||
(subspace) => subspace !== undefined,
|
||||
);
|
||||
|
||||
if (combinedSubspaces.length > 0) {
|
||||
await this.subspaceProductAllocationService.updateSubspaceProductAllocations(
|
||||
@ -436,32 +444,22 @@ export class SubSpaceService {
|
||||
private async handleUpdateAction(
|
||||
modifyDto: ModifySubspaceDto,
|
||||
queryRunner: QueryRunner,
|
||||
): Promise<void> {
|
||||
): Promise<SubspaceEntity> {
|
||||
const subspace = await this.findOne(modifyDto.uuid);
|
||||
await this.update(
|
||||
const updatedSubspace = await this.update(
|
||||
queryRunner,
|
||||
subspace,
|
||||
modifyDto.subspaceName,
|
||||
modifyDto.tags,
|
||||
);
|
||||
return updatedSubspace;
|
||||
}
|
||||
|
||||
async update(
|
||||
queryRunner: QueryRunner,
|
||||
subspace: SubspaceEntity,
|
||||
subspaceName?: string,
|
||||
modifyTagDto?: ModifyTagDto[],
|
||||
) {
|
||||
await this.updateSubspaceName(queryRunner, subspace, subspaceName);
|
||||
|
||||
if (modifyTagDto?.length) {
|
||||
await this.tagService.modifyTags(
|
||||
modifyTagDto,
|
||||
queryRunner,
|
||||
null,
|
||||
subspace,
|
||||
);
|
||||
}
|
||||
return await this.updateSubspaceName(queryRunner, subspace, subspaceName);
|
||||
}
|
||||
|
||||
async handleDeleteAction(
|
||||
@ -517,11 +515,12 @@ export class SubSpaceService {
|
||||
queryRunner: QueryRunner,
|
||||
subSpace: SubspaceEntity,
|
||||
subspaceName?: string,
|
||||
): Promise<void> {
|
||||
): Promise<SubspaceEntity> {
|
||||
if (subspaceName) {
|
||||
subSpace.subspaceName = subspaceName;
|
||||
await queryRunner.manager.save(subSpace);
|
||||
return await queryRunner.manager.save(subSpace);
|
||||
}
|
||||
return subSpace;
|
||||
}
|
||||
|
||||
private async checkForDuplicateNames(names: string[]): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user