Update settings

This commit is contained in:
Patrick Jentsch
2024-12-16 10:07:21 +01:00
parent 9a805b9d14
commit cda28910f5
21 changed files with 476 additions and 446 deletions

View File

@ -5,6 +5,7 @@ nopaque.app.Client = class Client {
// Endpoints
this.corpora = new nopaque.app.endpoints.Corpora(this);
this.jobs = new nopaque.app.endpoints.Jobs(this);
this.settings = new nopaque.app.endpoints.Settings(this);
this.users = new nopaque.app.endpoints.Users(this);
// Extensions

View File

@ -0,0 +1,77 @@
nopaque.app.endpoints.Settings = class Settings {
constructor(app) {
this.app = app;
}
async updateProfileIsPublic(newValue) {
const options = {
body: JSON.stringify(newValue),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
method: 'PUT',
};
const response = await fetch(`/settings/profile-is-public`, options);
const data = await response.json();
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
async updateProfileShowEmail(newValue) {
const options = {
body: JSON.stringify(newValue),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
method: 'PUT',
};
const response = await fetch(`/settings/profile-show-email`, options);
const data = await response.json();
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
async updateProfileShowLastSeen(newValue) {
const options = {
body: JSON.stringify(newValue),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
method: 'PUT',
};
const response = await fetch(`/settings/profile-show-last-seen`, options);
const data = await response.json();
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
async updateProfileShowMemberSince(newValue) {
const options = {
body: JSON.stringify(newValue),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
method: 'PUT',
};
const response = await fetch(`/settings/profile-show-member-since`, options);
const data = await response.json();
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
}

View File

@ -1,43 +1,52 @@
nopaque.app.endpoints.Users = class Users {
constructor(app) {
this.app = app;
this.socket = io('/users', {transports: ['websocket'], upgrade: false});
}
async get(id) {
const response = await this.socket.emitWithAck('get', id);
async get(userId) {
const options = {
headers: {
Accept: 'application/json'
}
};
if (response.status !== 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
const response = await fetch(`/users/${userId}`, options);
const data = await response.json();
return response.body;
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
async subscribe(id) {
const response = await this.socket.emitWithAck('subscribe', id);
async subscribe(userId) {
const response = await this.app.socket.emitWithAck('SUBSCRIBE User', userId);
if (response.status != 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
}
async unsubscribe(id) {
const response = await this.socket.emitWithAck('unsubscribe', id);
async unsubscribe(userId) {
const response = await this.app.socket.emitWithAck('UNSUBSCRIBE User', userId);
if (response.status != 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
}
async delete(id) {
const response = await this.socket.emitWithAck('delete', id);
async delete(userId) {
const options = {
headers: {
Accept: 'application/json'
},
method: 'DELETE'
};
if (response.status != 202) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
const response = await fetch(`/users/${userId}`, options);
const data = await response.json();
return response.body;
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
}

View File

@ -13,7 +13,7 @@ nopaque.app.extensions.UserHub = class UserHub extends EventTarget {
}
init() {
this.app.users.socket.on('patch', (patch) => {this.#onPatch(patch)});
this.app.socket.on('PATCH', (patch) => {this.#onPatch(patch)});
}
add(userId) {