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

65 lines
1.2 KiB
JavaScript
Raw Permalink 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);
await profile.init(user_id);
return profile;
}
async block(user_id) {
// blocker & blocked
2023-12-20 17:48:52 -05:00
let response = await this.client._post("/api/profiles/block", {
users_id:[this.client.me.user_id, user_id],
});
let data = await response.json();
2023-12-20 17:48:52 -05:00
console.log(response.status);
console.log(data);
return data;
}
async deblock(user_id) {
2023-12-20 17:48:52 -05:00
// blocker & blocked
let response = await this.client._delete("/api/profiles/block", {
users_id:[this.client.me.user_id, user_id],
});
let data = await response.json();
console.log(response.status);
console.log(data);
return data;
}
2023-12-08 11:36:41 -05:00
}
export {Profiles}