mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 22:57:55 +00:00
added moving tags
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user