mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
Refactor Article GET routes
This commit is contained in:
@@ -24,7 +24,7 @@ export interface GetArticle {
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchArticle(id: string): Promise<GetArticle> {
|
||||
function fetchArticle(id: string): Promise<Article | GetArticle> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(`${baseApiUrl}/articles/${id}`, {
|
||||
credentials: 'include',
|
||||
@@ -36,6 +36,15 @@ export function fetchArticle(id: string): Promise<GetArticle> {
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchUniqueArticle(id: string): Promise<Article> {
|
||||
return fetchArticle(id) as Promise<Article>
|
||||
|
||||
}
|
||||
|
||||
export function fetchAllArticle(): Promise<GetArticle> {
|
||||
return fetchArticle("") as Promise<GetArticle>
|
||||
}
|
||||
|
||||
export function deleteArticle(id: string): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(`${baseApiUrl}/articles/${id}`, {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import Modal from '@/components/ModalSuccessError.vue';
|
||||
import { fetchArticle, sendArticleWithMethod, type Article, type GetArticle } from '@/utils/database';
|
||||
import { fetchUniqueArticle, sendArticleWithMethod, type Article } from '@/utils/database';
|
||||
import Editor from '@tinymce/tinymce-vue';
|
||||
import { onMounted, ref, type Ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
@@ -19,9 +19,9 @@ function displayErrorMessage(message: string): void {
|
||||
errorModalShow.value = true
|
||||
}
|
||||
|
||||
async function getArticle(): Promise<GetArticle | undefined> {
|
||||
async function getArticle(): Promise<Article | undefined> {
|
||||
try {
|
||||
return await fetchArticle(route.params.articleID as string)
|
||||
return await fetchUniqueArticle(route.params.articleID as string)
|
||||
} catch {
|
||||
displayErrorMessage("Impossible de récupérer l'article. Vérifiez l'URL. Tentez-vous d'accéder au mode édition directement depuis un lien ?")
|
||||
return undefined
|
||||
@@ -29,7 +29,7 @@ async function getArticle(): Promise<GetArticle | undefined> {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
article.value = (await getArticle())?.content[0]
|
||||
article.value = await getArticle()
|
||||
editorData.value = article.value?.content.html ?? ""
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user