reduced duplication

This commit is contained in:
hannathkadher
2024-12-12 09:29:25 +04:00
parent ba002ae474
commit 72bebe3b06
4 changed files with 32 additions and 43 deletions

View File

@ -1,33 +1,29 @@
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
import { CommunityRepository } from '@app/common/modules/community/repositories';
import { SpaceRepository } from '@app/common/modules/space/repositories';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { GetDeviceDetailsInterface } from 'src/device/interfaces/get.device.interface';
import { GetSpaceParam } from '../dtos';
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
import { ProductRepository } from '@app/common/modules/product/repositories';
import { SpaceService } from './space.service';
import { ValidationService } from './space-validation.service';
@Injectable()
export class SpaceDeviceService {
constructor(
private readonly spaceRepository: SpaceRepository,
private readonly tuyaService: TuyaService,
private readonly productRepository: ProductRepository,
private readonly communityRepository: CommunityRepository,
private readonly spaceService: SpaceService,
private readonly validationService: ValidationService,
) {}
async listDevicesInSpace(params: GetSpaceParam): Promise<BaseResponseDto> {
const { spaceUuid, communityUuid, projectUuid } = params;
try {
const space = await this.spaceService.validateCommunityAndSpace(
communityUuid,
spaceUuid,
projectUuid,
);
const space =
await this.validationService.validateSpaceWithinCommunityAndProject(
communityUuid,
projectUuid,
spaceUuid,
);
const safeFetch = async (device: any) => {
try {

View File

@ -1,16 +1,16 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { GetSpaceParam } from '../dtos';
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { SpaceService } from './space.service';
import { SceneService } from '../../scene/services';
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
import { GetSceneDto } from '../../scene/dtos';
import { ValidationService } from './space-validation.service';
@Injectable()
export class SpaceSceneService {
constructor(
private readonly spaceSevice: SpaceService,
private readonly sceneSevice: SceneService,
private readonly validationService: ValidationService,
) {}
async getScenes(
@ -20,10 +20,10 @@ export class SpaceSceneService {
try {
const { spaceUuid, communityUuid, projectUuid } = params;
await this.spaceSevice.validateCommunityAndSpace(
await this.validationService.validateSpaceWithinCommunityAndProject(
communityUuid,
spaceUuid,
projectUuid,
spaceUuid,
);
const scenes = await this.sceneSevice.findScenesBySpace(

View File

@ -1,21 +1,19 @@
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
import { SpaceRepository } from '@app/common/modules/space/repositories';
import {
UserRepository,
UserSpaceRepository,
} from '@app/common/modules/user/repositories';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { SpaceService } from './space.service';
import { UserSpaceParam } from '../dtos';
import { ValidationService } from './space-validation.service';
@Injectable()
export class SpaceUserService {
constructor(
private readonly spaceRepository: SpaceRepository,
private readonly validationService: ValidationService,
private readonly userRepository: UserRepository,
private readonly userSpaceRepository: UserSpaceRepository,
private readonly spaceService: SpaceService,
) {}
async associateUserToSpace(params: UserSpaceParam): Promise<BaseResponseDto> {
const { communityUuid, spaceUuid, userUuid, projectUuid } = params;
@ -31,11 +29,12 @@ export class SpaceUserService {
}
// Find the space by ID
const space = await this.spaceService.validateCommunityAndSpace(
communityUuid,
spaceUuid,
projectUuid,
);
const space =
await this.validationService.validateSpaceWithinCommunityAndProject(
communityUuid,
projectUuid,
spaceUuid,
);
// Check if the association already exists
const existingAssociation = await this.userSpaceRepository.findOne({
@ -73,10 +72,10 @@ export class SpaceUserService {
}
// Find the space by ID
await this.spaceService.validateCommunityAndSpace(
await this.validationService.validateSpaceWithinCommunityAndProject(
communityUuid,
spaceUuid,
projectUuid,
spaceUuid,
);
// Find the existing association

View File

@ -1,29 +1,23 @@
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
import { DeviceRepository } from '@app/common/modules/device/repositories';
import {
SpaceRepository,
SubspaceRepository,
} from '@app/common/modules/space/repositories';
import { SubspaceRepository } from '@app/common/modules/space/repositories';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { DeviceSubSpaceParam, GetSubSpaceParam } from '../../dtos';
import { CommunityRepository } from '@app/common/modules/community/repositories';
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';
import { ValidationService } from '../space-validation.service';
@Injectable()
export class SubspaceDeviceService {
constructor(
private readonly spaceRepository: SpaceRepository,
private readonly communityRepository: CommunityRepository,
private readonly subspaceRepository: SubspaceRepository,
private readonly deviceRepository: DeviceRepository,
private readonly tuyaService: TuyaService,
private readonly productRepository: ProductRepository,
private readonly spaceService: SpaceService,
private readonly validationService: ValidationService,
) {}
async listDevicesInSubspace(
@ -31,10 +25,10 @@ export class SubspaceDeviceService {
): Promise<BaseResponseDto> {
const { subSpaceUuid, spaceUuid, communityUuid, projectUuid } = params;
await this.spaceService.validateCommunityAndSpace(
await this.validationService.validateSpaceWithinCommunityAndProject(
communityUuid,
spaceUuid,
projectUuid,
spaceUuid,
);
const subspace = await this.findSubspaceWithDevices(subSpaceUuid);
@ -76,10 +70,10 @@ export class SubspaceDeviceService {
const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid, projectUuid } =
params;
try {
await this.spaceService.validateCommunityAndSpace(
await this.validationService.validateSpaceWithinCommunityAndProject(
communityUuid,
spaceUuid,
projectUuid,
spaceUuid,
);
const subspace = await this.findSubspace(subSpaceUuid);
@ -111,10 +105,10 @@ export class SubspaceDeviceService {
const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid, projectUuid } =
params;
try {
await this.spaceService.validateCommunityAndSpace(
await this.validationService.validateSpaceWithinCommunityAndProject(
communityUuid,
spaceUuid,
projectUuid,
spaceUuid,
);
const subspace = await this.findSubspace(subSpaceUuid);