mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 10:46:17 +00:00
Add CommunityService implementation
This commit is contained in:
35
src/community/services/community.service.ts
Normal file
35
src/community/services/community.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
1
src/community/services/index.ts
Normal file
1
src/community/services/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './community.service';
|
Reference in New Issue
Block a user