mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 20:04:54 +00:00
changed endpoint for subspace device
This commit is contained in:
@ -12,6 +12,7 @@ import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||
import { GetDeviceDetailsInterface } from '../../../device/interfaces/get.device.interface';
|
||||
import { SpaceService } from '../space.service';
|
||||
|
||||
@Injectable()
|
||||
export class SubspaceDeviceService {
|
||||
@ -22,14 +23,19 @@ export class SubspaceDeviceService {
|
||||
private readonly deviceRepository: DeviceRepository,
|
||||
private readonly tuyaService: TuyaService,
|
||||
private readonly productRepository: ProductRepository,
|
||||
private readonly spaceService: SpaceService,
|
||||
) {}
|
||||
|
||||
async listDevicesInSubspace(
|
||||
params: GetSubSpaceParam,
|
||||
): 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);
|
||||
|
||||
@ -67,9 +73,14 @@ export class SubspaceDeviceService {
|
||||
async associateDeviceToSubspace(
|
||||
params: DeviceSubSpaceParam,
|
||||
): Promise<BaseResponseDto> {
|
||||
const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid } = params;
|
||||
const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid, projectUuid } =
|
||||
params;
|
||||
try {
|
||||
await this.validateCommunityAndSpace(communityUuid, spaceUuid);
|
||||
await this.spaceService.validateCommunityAndSpace(
|
||||
communityUuid,
|
||||
spaceUuid,
|
||||
projectUuid,
|
||||
);
|
||||
|
||||
const subspace = await this.findSubspace(subSpaceUuid);
|
||||
const device = await this.findDevice(deviceUuid);
|
||||
@ -97,9 +108,14 @@ export class SubspaceDeviceService {
|
||||
async disassociateDeviceFromSubspace(
|
||||
params: DeviceSubSpaceParam,
|
||||
): Promise<BaseResponseDto> {
|
||||
const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid } = params;
|
||||
const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid, projectUuid } =
|
||||
params;
|
||||
try {
|
||||
await this.validateCommunityAndSpace(communityUuid, spaceUuid);
|
||||
await this.spaceService.validateCommunityAndSpace(
|
||||
communityUuid,
|
||||
spaceUuid,
|
||||
projectUuid,
|
||||
);
|
||||
|
||||
const subspace = await this.findSubspace(subSpaceUuid);
|
||||
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
|
||||
private async findSubspaceWithDevices(subSpaceUuid: string) {
|
||||
|
||||
@ -18,8 +18,6 @@ import { SpaceService } from '../space.service';
|
||||
@Injectable()
|
||||
export class SubSpaceService {
|
||||
constructor(
|
||||
private readonly spaceRepository: SpaceRepository,
|
||||
private readonly communityRepository: CommunityRepository,
|
||||
private readonly subspaceRepository: SubspaceRepository,
|
||||
private readonly spaceService: SpaceService,
|
||||
) {}
|
||||
|
||||
Reference in New Issue
Block a user