added service to delete space model

This commit is contained in:
hannathkadher
2025-02-26 00:36:37 +04:00
parent 8ecd368b16
commit 6b20428719
3 changed files with 26 additions and 17 deletions

View File

@ -1,3 +1,2 @@
export * from './space-model.service';
export * from './subspace';
export * from './tag-model.service';

View File

@ -311,16 +311,6 @@ export class SpaceModelProductAllocationService {
}
}
private async getAllocationByTagUuid(
tagUuid: string,
queryRunner: QueryRunner,
): Promise<SpaceModelProductAllocationEntity | null> {
return queryRunner.manager.findOne(SpaceModelProductAllocationEntity, {
where: { tags: { uuid: tagUuid } },
relations: ['tags'],
});
}
private async validateTagWithinSpaceModel(
queryRunner: QueryRunner,
tag: NewTagEntity,
@ -351,4 +341,29 @@ 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 })
.execute();
} catch (error) {
throw this.handleError(error, `Failed to clear all allocations`);
}
}
}

View File

@ -2,11 +2,7 @@ import { SpaceRepositoryModule } from '@app/common/modules/space/space.repositor
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { SpaceModelController } from './controllers';
import {
SpaceModelService,
SubSpaceModelService,
TagModelService,
} from './services';
import { SpaceModelService, SubSpaceModelService } from './services';
import {
SpaceModelProductAllocationRepoitory,
SpaceModelRepository,
@ -64,7 +60,6 @@ const CommandHandlers = [
SubspaceModelRepository,
ProductRepository,
SubspaceRepository,
TagModelService,
TagModelRepository,
SubSpaceService,
ValidationService,