Add CommunityService implementation

This commit is contained in:
faris Aljohari
2024-03-31 22:30:51 +03:00
parent 9654d58ea0
commit 85f6dce85f
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,35 @@
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
import { ConfigService } from '@nestjs/config';
import { SpaceRepository } from '@app/common/modules/space/repositories';
import { AddCommunityDto } from '../dtos';
@Injectable()
export class CommunityService {
private tuya: TuyaContext;
constructor(
private readonly configService: ConfigService,
private readonly spaceRepository: SpaceRepository,
) {
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
const secretKey = this.configService.get<string>('auth-config.SECRET_KEY');
// const clientId = this.configService.get<string>('auth-config.CLIENT_ID');
this.tuya = new TuyaContext({
baseUrl: 'https://openapi.tuyaeu.com',
accessKey,
secretKey,
});
}
async addCommunity(addCommunityDto: AddCommunityDto) {
try {
await this.spaceRepository.save({
spaceName: addCommunityDto.spaceName,
parent: { uuid: addCommunityDto.parentUuid },
spaceType: { uuid: addCommunityDto.spaceTypeUuid },
});
} catch (err) {
throw new HttpException(err.message, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -0,0 +1 @@
export * from './community.service';