(`/api/v2/articles-paging?categoryId=${categoryId}&page=${pagination.value.page}&limit=${limit ? limit : pagination.value.limit}&sort=createdon desc`)
+
+ if (error.value) {
+ pagination.value.total = 0;
+ return [] as Article[]
+ }
+
+ data.value.items.forEach((item: Article) => {
+ item.title = item.title.replace(/|<\/p>/g, '')
+ })
+
+ pagination.value.total = data.value.total;
+
+ return data.value.items
+ }
+
+ // async function fetchByTagId(tagId: number, limit?: number, page?: number) {
+ // if(limit) {
+ // pagination.value.limit = limit;
+ // }
+ // if(page) {
+ // pagination.value.page = page;
+ // }
+ // const { data, error } = await useFetch(`/api/v2/articles-tag`, {
+ // query: {
+ // tagId: tagId,
+ // limit: pagination.value.limit,
+ // page: pagination.value.page,
+ // sort: 'createdon desc'
+ // }
+ // })
+ // if(error.value) {
+ // return null
+ // }
+
+ // pagination.value.total = data.value.total
+ // return data.value.items
+ // }
+
+ // async function fetchByTagId(tagId: number, limit?: number) {
+ // const { data, error } = await useFetch(`/api/v2/articles-tag`, {
+ // query: {
+ // tagId: tagId,
+ // limit: limit ? limit : pagination.value.limit,
+ // page: pagination.value.page,
+ // sort: 'createdon desc'
+ // }
+ // })
+
+ // if(error.value) {
+ // return null;
+ // }
+
+ // pagination.value.total = data.value.total
+
+ // return data.value.items
+ // }
+
+ async function fetchByCategorySectionArticle(layout: number) {
+ const { data, error } = await useFetch(`/api/v2/articles-category-section?layout=${layout}`)
+ // if (error.value) {
+ // return {} as Article{}
+ // }
+ // data.value.items.forEach((item: Article) => {
+ // item.title = item.title.replace(/|<\/p>/g, '')
+ // })
+ if(error.value) {
+ return {}
+ }
+ return data.value
+ }
+
+ async function fetchByEventId(eventId: number, limit?: number) {
+ if(limit) {
+ pagination.value.limit = limit
+ }
+ const { data, error } = await useFetch(`/api/v2/articles-paging`, {
+ query: {
+ eventId: eventId,
+ page: pagination.value.page,
+ limit: pagination.value.limit,
+ sort: 'createdon desc'
+ }
+ })
+
+ if(error.value) {
+ return null
+ }
+
+ pagination.value.total = data.value.total
+ return data.value.items
+ }
+
+ async function fetchByAuthorId(authorId: number, limit?:number) {
+ if(limit) {
+ pagination.value.limit = limit
+ }
+ const { data, error } = await useFetch(`/api/v2/articles-paging`, {
+ query: {
+ authorId: authorId,
+ page: pagination.value.page,
+ limit: pagination.value.limit,
+ sort: 'createdon desc'
+ }
+ })
+
+ if(error.value) {
+ return null
+ }
+
+ pagination.value.total = data.value.total
+ return data.value.items
+ }
+
+ async function fetchByTopicId(topicId: number, limit?: number) {
+ if(limit) {
+ pagination.value.limit = limit
+ }
+ const { data, error } = await useFetch(`/api/v2/articles-paging`, {
+ query: {
+ topicId: topicId,
+ page: pagination.value.page,
+ limit: pagination.value.limit,
+ sort: 'createdon desc'
+ }
+ })
+
+ if(error.value) {
+ return null
+ }
+ pagination.value.total = data.value.total
+ return data.value.items
+ }
+
+ async function fetchByTagId(tagId: number, limit?: number) {
+ if(limit) {
+ pagination.value.limit = limit
+ }
+ const { data, error } = await useFetch(`/api/v2/articles-paging`, {
+ query: {
+ tagId: tagId,
+ page: pagination.value.page,
+ limit: pagination.value.limit,
+ sort: 'createdon desc'
+ }
+ })
+
+ if(error.value) {
+ return null
+ }
+
+ pagination.value.total = data.value.total
+ return data.value.items
+ }
+
+ async function fetchById(id: string) {
+ const { data, error } = await useFetch(`/api/v2/articles`, { query: { articleId: id } })
+
+ if (error.value) {
+ return null
+ }
+
+ if (data.value) {
+ data.value.title = data.value.title.replace(/|<\/p>/g, '')
+ data.value.detail = utils.domainImage(data.value.detail, serverResourceUrl)
+ }
+
+ return data.value
+ }
+
+ function setStateFromRoute(query: LocationQuery) {
+ if (query.page) pagination.value.page = utils.toNumber(query.page);
+ else
+ pagination.value.page = utils.toNumber(
+ useRuntimeConfig().public.pagingDefault
+ );
+ if (query.limit) pagination.value.limit = utils.toNumber(query.limit);
+ else
+ pagination.value.limit = utils.toNumber(
+ useRuntimeConfig().public.pagingLimit
+ );
+ }
+
+ return { pagination, fetchByTagId, fetchByCategoryIdWithPaging, fetchById, setStateFromRoute, fetchByCategorySectionArticle, fetchByEventId, fetchByTopicId, fetchByAuthorId }
+})
+
+if (import.meta.hot) {
+ import.meta.hot.accept(acceptHMRUpdate(useArticleStoreV2, import.meta.hot))
+}