mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
Merge branch 'dev' of https://github.com/SyncrowIOT/backend into dev
This commit is contained in:
@ -1,8 +1,15 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { PropogateUpdateSpaceModelCommand } from '../commands';
|
||||
import { SpaceRepository } from '@app/common/modules/space';
|
||||
import { SubspaceRepository } from '@app/common/modules/space/repositories/subspace.repository';
|
||||
import { SpaceModelEntity, TagModel } from '@app/common/modules/space-model';
|
||||
import {
|
||||
SubspaceProductAllocationRepository,
|
||||
SubspaceRepository,
|
||||
} from '@app/common/modules/space/repositories/subspace.repository';
|
||||
import {
|
||||
SpaceModelEntity,
|
||||
SubspaceModelProductAllocationRepoitory,
|
||||
TagModel,
|
||||
} from '@app/common/modules/space-model';
|
||||
import { DataSource, QueryRunner } from 'typeorm';
|
||||
import { SubSpaceService } from 'src/space/services';
|
||||
import { TagService } from 'src/space/services/tag';
|
||||
@ -23,17 +30,15 @@ export class PropogateUpdateSpaceModelHandler
|
||||
private readonly dataSource: DataSource,
|
||||
private readonly subSpaceService: SubSpaceService,
|
||||
private readonly tagService: TagService,
|
||||
private readonly subspaceModelProductRepository: SubspaceModelProductAllocationRepoitory,
|
||||
private readonly subspaceProductRepository: SubspaceProductAllocationRepository,
|
||||
) {}
|
||||
|
||||
async execute(command: PropogateUpdateSpaceModelCommand): Promise<void> {
|
||||
console.log("propagate");
|
||||
const { spaceModel, subspaceModels, spaces } = command.param;
|
||||
const { subspaceModels, spaces } = command.param;
|
||||
|
||||
if (!subspaceModels || subspaceModels.length === 0) return;
|
||||
|
||||
if (!spaces) {
|
||||
return;
|
||||
}
|
||||
if (!spaces || spaces.length === 0) return;
|
||||
|
||||
for (const subspaceModel of subspaceModels) {
|
||||
if (subspaceModel.action === ModifyAction.ADD) {
|
||||
@ -46,7 +51,37 @@ export class PropogateUpdateSpaceModelHandler
|
||||
subspaceModel: ISingleSubspaceModel,
|
||||
spaces: SpaceEntity[],
|
||||
) {
|
||||
console.log(`subspace is ${JSON.stringify(subspaceModel)}`);
|
||||
const subspaceModelAllocations =
|
||||
await this.subspaceModelProductRepository.find({
|
||||
where: {
|
||||
subspaceModel: {
|
||||
uuid: subspaceModel.subspaceModel.uuid,
|
||||
},
|
||||
},
|
||||
relations: ['tags', 'product'],
|
||||
});
|
||||
|
||||
for (const space of spaces) {
|
||||
const subspace = this.subspaceRepository.create({
|
||||
subspaceName: subspaceModel.subspaceModel.subspaceName,
|
||||
space: space,
|
||||
});
|
||||
|
||||
subspace.subSpaceModel = subspaceModel.subspaceModel;
|
||||
await this.subspaceRepository.save(subspace);
|
||||
|
||||
if (subspaceModelAllocations?.length > 0) {
|
||||
for (const allocation of subspaceModelAllocations) {
|
||||
const subspaceAllocation = this.subspaceProductRepository.create({
|
||||
subspace: subspace,
|
||||
product: allocation.product,
|
||||
tags: allocation.tags,
|
||||
inheritedFromModel: allocation,
|
||||
});
|
||||
await this.subspaceProductRepository.save(subspaceAllocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async updateSubspaceModels(
|
||||
|
Reference in New Issue
Block a user