ft_transcendence/frontend/static/js/api/profiles.js

49 lines
849 B
JavaScript
Raw Normal View History

2023-12-08 11:36:41 -05:00
import { Profile } from "./profile.js";
class Profiles
{
2023-12-16 12:00:38 -05:00
/**
* @param {Client} client
*/
2023-12-08 11:36:41 -05:00
constructor (client)
{
2023-12-16 12:00:38 -05:00
/**
* @type {Client} client
*/
2023-12-08 11:36:41 -05:00
this.client = client
}
async all()
{
let response = await this.client._get("/api/profiles/");
let response_data = await response.json();
let profiles = []
response_data.forEach((profile) => {
profiles.push(new Profile(this.client, profile.username, profile.avatar_url, profile.user_id))
});
2023-12-09 09:13:40 -05:00
return profiles;
2023-12-08 11:36:41 -05:00
}
2023-12-09 15:51:32 -05:00
async getProfile(user_id)
{
let profile = new Profile(this.client);
if (await profile.init(user_id))
return null;
2023-12-09 15:51:32 -05:00
return profile;
}
async block(user_id) {
// blocker & blocked
let response = await this.client._post("/api/block/",
[this.client.me.user_id, user_id],
);
let data = await response.json();
}
2023-12-08 11:36:41 -05:00
}
export {Profiles}