add: delete and edit accounts page

This commit is contained in:
2023-12-01 01:29:56 +01:00
parent c2b6dbb989
commit 25f315c24f
12 changed files with 232 additions and 23 deletions

View File

@ -1,11 +1,21 @@
import { Accounts } from "./accounts.js";
import { Account } from "./account.js";
function getCookie(name)
{
let cookie = {};
document.cookie.split(';').forEach(function(el) {
let split = el.split('=');
cookie[split[0].trim()] = split.slice(1).join("=");
})
return cookie[name];
}
class Client
{
constructor(url)
{
this._url = url;
this.accounts = new Accounts(this);
this.account = new Account(this);
this._logged = undefined;
}
@ -30,6 +40,33 @@ class Client
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRFToken": getCookie("csrftoken"),
},
body: JSON.stringify(data),
});
return response;
}
async _delete(uri, data)
{
let response = await fetch(this._url + uri, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
"X-CSRFToken": getCookie("csrftoken"),
},
body: JSON.stringify(data),
});
return response;
}
async _patch_json(uri, data)
{
let response = await fetch(this._url + uri, {
method: "PATCH",
headers: {
"X-CSRFToken": getCookie("csrftoken"),
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});