access profiles with username instead of id

This commit is contained in:
AdrienLSH
2024-01-18 10:31:56 +01:00
parent 1af55795d9
commit dee71c7c8d
7 changed files with 22 additions and 21 deletions

View File

@ -5,21 +5,21 @@ class Profile
/**
* @param {Client} client
*/
constructor (client, id, username = undefined, avatar_url = undefined)
constructor (client, username, id = undefined, avatar_url = undefined)
{
/**
* @type {Client} client
*/
this.client = client;
this.id = id;
this.username = username;
this.id = id;
this.avatar_url = avatar_url;
this.isBlocked = false;
}
async init()
{
let response = await this.client._get(`/api/profiles/${this.id}`);
let response = await this.client._get(`/api/profiles/${this.username}`);
if (response.status !== 200)
return response.status;

View File

@ -20,14 +20,14 @@ class Profiles
let profiles = []
response_data.forEach((profile) => {
profiles.push(new Profile(this.client, profile.user_id, profile.username, profile.avatar_url))
profiles.push(new Profile(this.client, profile.username, profile.user_id, profile.avatar_url))
});
return profiles;
}
async getProfile(user_id)
async getProfile(username)
{
let profile = new Profile(this.client, user_id);
let profile = new Profile(this.client, username);
if (await profile.init())
return null;
return profile;