mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
added moving tags
This commit is contained in:
@ -323,6 +323,8 @@ export class SpaceService {
|
||||
updateSpaceDto: UpdateSpaceDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
const { communityUuid, spaceUuid, projectUuid } = params;
|
||||
console.log(communityUuid, spaceUuid, projectUuid);
|
||||
console.log(updateSpaceDto);
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
|
||||
try {
|
||||
|
@ -11,6 +11,7 @@ import { ValidationService } from '../space-validation.service';
|
||||
import { SubspaceRepository } from '@app/common/modules/space/repositories/subspace.repository';
|
||||
import { In, QueryRunner } from 'typeorm';
|
||||
import { DeviceEntity } from '@app/common/modules/device/entities';
|
||||
import { TagRepository } from '@app/common/modules/space';
|
||||
|
||||
@Injectable()
|
||||
export class SubspaceDeviceService {
|
||||
@ -20,6 +21,7 @@ export class SubspaceDeviceService {
|
||||
private readonly tuyaService: TuyaService,
|
||||
private readonly productRepository: ProductRepository,
|
||||
private readonly validationService: ValidationService,
|
||||
private readonly tagRepository: TagRepository,
|
||||
) {}
|
||||
|
||||
async listDevicesInSubspace(
|
||||
@ -80,6 +82,35 @@ export class SubspaceDeviceService {
|
||||
|
||||
const subspace = await this.findSubspace(subSpaceUuid);
|
||||
const device = await this.findDevice(deviceUuid);
|
||||
console.log(device);
|
||||
|
||||
if (device.tag) {
|
||||
console.log(device.tag);
|
||||
const tag = device.tag;
|
||||
if (tag.subspace !== null && tag.subspace.uuid === subspace.uuid) {
|
||||
//do nothing
|
||||
}
|
||||
if (tag.subspace !== null && tag.subspace.uuid !== subspace.uuid) {
|
||||
await this.tagRepository.update(
|
||||
{
|
||||
uuid: tag.uuid,
|
||||
},
|
||||
{
|
||||
subspace: subspace,
|
||||
},
|
||||
);
|
||||
}
|
||||
if (tag.subspace === null) {
|
||||
await this.tagRepository.update(
|
||||
{
|
||||
uuid: tag.uuid,
|
||||
},
|
||||
{
|
||||
subspace: subspace,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
device.subspace = subspace;
|
||||
|
||||
@ -123,6 +154,24 @@ export class SubspaceDeviceService {
|
||||
);
|
||||
}
|
||||
|
||||
if (device.tag) {
|
||||
console.log(device.tag);
|
||||
const tag = device.tag;
|
||||
if (tag.subspace === null) {
|
||||
//do nothing
|
||||
}
|
||||
if (tag.subspace !== null) {
|
||||
await this.tagRepository.update(
|
||||
{
|
||||
uuid: tag.uuid,
|
||||
},
|
||||
{
|
||||
subspace: null,
|
||||
space: device.subspace,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
device.subspace = null;
|
||||
const updatedDevice = await this.deviceRepository.save(device);
|
||||
|
||||
@ -167,7 +216,7 @@ export class SubspaceDeviceService {
|
||||
private async findDevice(deviceUuid: string) {
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: { uuid: deviceUuid },
|
||||
relations: ['subspace'],
|
||||
relations: ['subspace', 'tag', 'tag.space', 'tag.subspace'],
|
||||
});
|
||||
if (!device) {
|
||||
this.throwNotFound('Device', deviceUuid);
|
||||
|
@ -8,7 +8,6 @@ import {
|
||||
import { TagModel } from '@app/common/modules/space-model';
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { ProductService } from 'src/product/services';
|
||||
import { ModifyTagModelDto } from 'src/space-model/dtos';
|
||||
import { CreateTagDto, ModifySubspaceDto } from 'src/space/dtos';
|
||||
import { ModifyTagDto } from 'src/space/dtos/tag/modify-tag.dto';
|
||||
import { QueryRunner } from 'typeorm';
|
||||
@ -32,10 +31,13 @@ export class TagService {
|
||||
|
||||
const combinedTags = this.combineTags(tags, additionalTags);
|
||||
this.ensureNoDuplicateTags(combinedTags);
|
||||
console.log(tags);
|
||||
|
||||
const tagEntitiesToCreate = tags.filter((tagDto) => tagDto.uuid === null);
|
||||
const tagEntitiesToCreate = tags.filter((tagDto) => !tagDto.uuid);
|
||||
const tagEntitiesToUpdate = tags.filter((tagDto) => tagDto.uuid !== null);
|
||||
|
||||
console.log(tagEntitiesToCreate);
|
||||
|
||||
try {
|
||||
const createdTags = await this.bulkSaveTags(
|
||||
tagEntitiesToCreate,
|
||||
@ -79,7 +81,8 @@ export class TagService {
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
console.log('here');
|
||||
console.log(JSON.stringify(tags));
|
||||
try {
|
||||
return await queryRunner.manager.save(tagEntities);
|
||||
} catch (error) {
|
||||
|
Reference in New Issue
Block a user