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 {
t,
path: url,
client_id: this.accessKey,
client_id: 'this.accessKey',
sign: await this.encryptStr(signStr, this.secretKey),
sign_method: 'HMAC-SHA256',
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 { UserListDto } from '../dtos/user.list.dto';

View File

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