mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 07:34:54 +00:00
added service to delete space model
This commit is contained in:
@ -1,3 +1,2 @@
|
||||
export * from './space-model.service';
|
||||
export * from './subspace';
|
||||
export * from './tag-model.service';
|
||||
|
||||
@ -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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user