mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 00:54:55 +00:00
changed endpoint for subspace device
This commit is contained in:
@ -246,7 +246,7 @@ export class ControllerRoute {
|
|||||||
|
|
||||||
static SUBSPACE_DEVICE = class {
|
static SUBSPACE_DEVICE = class {
|
||||||
public static readonly ROUTE =
|
public static readonly ROUTE =
|
||||||
'/communities/:communityUuid/spaces/:spaceUuid/subspaces/:subSpaceUuid/devices';
|
'/projects/:projectUuid/communities/:communityUuid/spaces/:spaceUuid/subspaces/:subSpaceUuid/devices';
|
||||||
|
|
||||||
static ACTIONS = class {
|
static ACTIONS = class {
|
||||||
public static readonly LIST_SUBSPACE_DEVICE_SUMMARY =
|
public static readonly LIST_SUBSPACE_DEVICE_SUMMARY =
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
|||||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||||
import { GetDeviceDetailsInterface } from '../../../device/interfaces/get.device.interface';
|
import { GetDeviceDetailsInterface } from '../../../device/interfaces/get.device.interface';
|
||||||
|
import { SpaceService } from '../space.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SubspaceDeviceService {
|
export class SubspaceDeviceService {
|
||||||
@ -22,14 +23,19 @@ export class SubspaceDeviceService {
|
|||||||
private readonly deviceRepository: DeviceRepository,
|
private readonly deviceRepository: DeviceRepository,
|
||||||
private readonly tuyaService: TuyaService,
|
private readonly tuyaService: TuyaService,
|
||||||
private readonly productRepository: ProductRepository,
|
private readonly productRepository: ProductRepository,
|
||||||
|
private readonly spaceService: SpaceService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async listDevicesInSubspace(
|
async listDevicesInSubspace(
|
||||||
params: GetSubSpaceParam,
|
params: GetSubSpaceParam,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
const { subSpaceUuid, spaceUuid, communityUuid } = params;
|
const { subSpaceUuid, spaceUuid, communityUuid, projectUuid } = params;
|
||||||
|
|
||||||
await this.validateCommunityAndSpace(communityUuid, spaceUuid);
|
await this.spaceService.validateCommunityAndSpace(
|
||||||
|
communityUuid,
|
||||||
|
spaceUuid,
|
||||||
|
projectUuid,
|
||||||
|
);
|
||||||
|
|
||||||
const subspace = await this.findSubspaceWithDevices(subSpaceUuid);
|
const subspace = await this.findSubspaceWithDevices(subSpaceUuid);
|
||||||
|
|
||||||
@ -67,9 +73,14 @@ export class SubspaceDeviceService {
|
|||||||
async associateDeviceToSubspace(
|
async associateDeviceToSubspace(
|
||||||
params: DeviceSubSpaceParam,
|
params: DeviceSubSpaceParam,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid } = params;
|
const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid, projectUuid } =
|
||||||
|
params;
|
||||||
try {
|
try {
|
||||||
await this.validateCommunityAndSpace(communityUuid, spaceUuid);
|
await this.spaceService.validateCommunityAndSpace(
|
||||||
|
communityUuid,
|
||||||
|
spaceUuid,
|
||||||
|
projectUuid,
|
||||||
|
);
|
||||||
|
|
||||||
const subspace = await this.findSubspace(subSpaceUuid);
|
const subspace = await this.findSubspace(subSpaceUuid);
|
||||||
const device = await this.findDevice(deviceUuid);
|
const device = await this.findDevice(deviceUuid);
|
||||||
@ -97,9 +108,14 @@ export class SubspaceDeviceService {
|
|||||||
async disassociateDeviceFromSubspace(
|
async disassociateDeviceFromSubspace(
|
||||||
params: DeviceSubSpaceParam,
|
params: DeviceSubSpaceParam,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid } = params;
|
const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid, projectUuid } =
|
||||||
|
params;
|
||||||
try {
|
try {
|
||||||
await this.validateCommunityAndSpace(communityUuid, spaceUuid);
|
await this.spaceService.validateCommunityAndSpace(
|
||||||
|
communityUuid,
|
||||||
|
spaceUuid,
|
||||||
|
projectUuid,
|
||||||
|
);
|
||||||
|
|
||||||
const subspace = await this.findSubspace(subSpaceUuid);
|
const subspace = await this.findSubspace(subSpaceUuid);
|
||||||
const device = await this.findDevice(deviceUuid);
|
const device = await this.findDevice(deviceUuid);
|
||||||
@ -129,26 +145,6 @@ export class SubspaceDeviceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Helper method to validate community and space
|
|
||||||
private async validateCommunityAndSpace(
|
|
||||||
communityUuid: string,
|
|
||||||
spaceUuid: string,
|
|
||||||
) {
|
|
||||||
const community = await this.communityRepository.findOne({
|
|
||||||
where: { uuid: communityUuid },
|
|
||||||
});
|
|
||||||
if (!community) {
|
|
||||||
this.throwNotFound('Community', communityUuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
const space = await this.spaceRepository.findOne({
|
|
||||||
where: { uuid: spaceUuid, community: { uuid: communityUuid } },
|
|
||||||
});
|
|
||||||
if (!space) {
|
|
||||||
this.throwNotFound('Space', spaceUuid);
|
|
||||||
}
|
|
||||||
return space;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper method to find subspace with devices relation
|
// Helper method to find subspace with devices relation
|
||||||
private async findSubspaceWithDevices(subSpaceUuid: string) {
|
private async findSubspaceWithDevices(subSpaceUuid: string) {
|
||||||
|
|||||||
@ -18,8 +18,6 @@ import { SpaceService } from '../space.service';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class SubSpaceService {
|
export class SubSpaceService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly spaceRepository: SpaceRepository,
|
|
||||||
private readonly communityRepository: CommunityRepository,
|
|
||||||
private readonly subspaceRepository: SubspaceRepository,
|
private readonly subspaceRepository: SubspaceRepository,
|
||||||
private readonly spaceService: SpaceService,
|
private readonly spaceService: SpaceService,
|
||||||
) {}
|
) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user