functioning API Call

This commit is contained in:
Ammar Qaffaf
2024-02-18 17:01:43 +03:00
parent 37e0effb07
commit 4ffd94ec78
3 changed files with 14 additions and 19 deletions

View File

@ -112,7 +112,7 @@ export class AuthenticationService {
return { return {
t, t,
path: url, path: url,
client_id: this.accessKey, client_id: 'this.accessKey',
sign: await this.encryptStr(signStr, this.secretKey), sign: await this.encryptStr(signStr, this.secretKey),
sign_method: 'HMAC-SHA256', sign_method: 'HMAC-SHA256',
access_token: this.token, access_token: this.token,

View File

@ -1,4 +1,4 @@
import { Controller, Get, Query } from '@nestjs/common'; import { Controller, Get, Query } from '@nestjs/common';
import { UserService } from '../services/user.service'; import { UserService } from '../services/user.service';
import { UserListDto } from '../dtos/user.list.dto'; import { UserListDto } from '../dtos/user.list.dto';

View File

@ -5,29 +5,24 @@ import { ConfigService } from '@nestjs/config';
@Injectable() @Injectable()
export class UserService { export class UserService {
private accessKey: string; private tuya: TuyaContext;
private secretKey: string;
constructor(private readonly configService: ConfigService) { constructor(private readonly configService: ConfigService) {
(this.accessKey = this.configService.get<string>('auth-config.ACCESS_KEY')), const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
(this.secretKey = this.configService.get<string>( const secretKey = this.configService.get<string>('auth-config.SECRET_KEY');
'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 userDetails(userListDto: UserListDto) { async userDetails(userListDto: UserListDto) {
const url = `https://openapi.tuyaeu.com/v2.0/apps/${userListDto.schema}/users`; const path = `/v2.0/apps/${userListDto.schema}/users`;
const data = await this.tuya.request({
const tuya = new TuyaContext({
baseUrl: 'https://openapi.tuyacn.com',
accessKey:this.secretKey,
secretKey:this.accessKey,
});
const data = await tuya.request({
method: 'GET', method: 'GET',
path: url, path,
query: userListDto, query: userListDto,
}); });
return data; return data;
} }
} }