Add delete message feature

Remove deleted property from Message

Add dedicated route for delete_message

Pre-commit

Revert change to promp_repository fetch_message

Remove blank line
This commit is contained in:
rjmacarthy
2023-02-02 13:33:22 +00:00
parent fa53505369
commit e9add425e6
5 changed files with 49 additions and 5 deletions
+2
View File
@@ -17,6 +17,8 @@ export const get = (url: string) => api.get(url).then((res) => res.data);
export const post = (url: string, { arg: data }) => api.post(url, data).then((res) => res.data);
export const del = (url: string) => api.delete(url).then((res) => res.data);
api.interceptors.response.use(
(response) => response,
(error) => {
+16 -1
View File
@@ -89,6 +89,13 @@ export class OasstApiClient {
return this.get<Message>(`/api/v1/messages/${message_id}?username=${user.id}&auth_method=${user.auth_method}`);
}
/**
* Delete a message by its id
*/
async delete_message(message_id: string): Promise<void> {
return this.delete<void>(`/api/v1/messages/${message_id}`);
}
/**
* Send a report about a message
*/
@@ -202,6 +209,10 @@ export class OasstApiClient {
return this.request<T>("PUT", path);
}
private async delete<T>(path: string) {
return this.request<T>("DELETE", path);
}
private async get<T>(path: string, query?: Record<string, string | number | boolean | undefined>) {
if (!query) {
return this.request<T>("GET", path);
@@ -216,7 +227,11 @@ export class OasstApiClient {
return this.request<T>("GET", `${path}?${params}`);
}
private async request<T>(method: "GET" | "POST" | "PUT", path: string, init?: RequestInit): Promise<T | null> {
private async request<T>(
method: "GET" | "POST" | "PUT" | "DELETE",
path: string,
init?: RequestInit
): Promise<T | null> {
const resp = await fetch(`${this.oasstApiUrl}${path}`, {
method,
...init,