diff --git a/web/admin-gui/src/utils/database.ts b/web/admin-gui/src/utils/database.ts index 7c9bd85..8bb3693 100644 --- a/web/admin-gui/src/utils/database.ts +++ b/web/admin-gui/src/utils/database.ts @@ -24,35 +24,39 @@ export interface GetArticle { } } -export async function getArticles(id: string): Promise { - return await fetch(`${baseApiUrl}/articles/${id}`, { - credentials: 'include', - method: 'GET', +export function fetchArticle(id: string): Promise { + return new Promise((resolve, reject) => { + fetch(`${baseApiUrl}/articles/${id}`, { + credentials: 'include', + method: 'GET', + }) + .then(response => response.json()) + .then(article => resolve(article)) + .catch(error => reject(error)) }) - .then(result => result.json()) } -export async function deleteArticle(id: string) { - return await fetch(`${baseApiUrl}/articles/${id}`, { - credentials: 'include', - method: 'DELETE', +export function deleteArticle(id: string): Promise { + return new Promise((resolve, reject) => { + fetch(`${baseApiUrl}/articles/${id}`, { + credentials: 'include', + method: 'DELETE' + }) + .then(result => result.json()) + .then(article => resolve(article)) + .catch(error => reject(error)) }) - .then(result => result.json()) } -async function sendArticle(article: Article, method: 'POST' | 'PUT'): Promise { - return await fetch(`${baseApiUrl}/articles/${article.titleID}`, { - credentials: 'include', - method, - body: JSON.stringify(article) +export function sendArticleWithMethod(article: Article, method: 'POST' | 'PUT'): Promise { + return new Promise((resolve, reject) => { + fetch(`${baseApiUrl}/articles/${article.titleID}`, { + credentials: 'include', + method, + body: JSON.stringify(article) + }) + .then(result => result.json()) + .then(article => resolve(article)) + .catch(error => reject(error)) }) - .then(result => result.json()) } - -export async function postArticle(article: Article): Promise { - return await sendArticle(article, 'POST') -} - -export async function editArticle(article: Article): Promise { - return await sendArticle(article, 'PUT') -} \ No newline at end of file diff --git a/web/admin-gui/src/views/ArticlesEdit.vue b/web/admin-gui/src/views/ArticlesEdit.vue index 4448a40..e3f7860 100644 --- a/web/admin-gui/src/views/ArticlesEdit.vue +++ b/web/admin-gui/src/views/ArticlesEdit.vue @@ -1,6 +1,6 @@ - +