62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { utils } from "~/utils/utilities";
|
|
import { Author } from "./author";
|
|
import Base from "./base";
|
|
import { ref } from "vue"
|
|
import { H3Event } from "h3";
|
|
|
|
export const listPaging = async (event: H3Event) => {
|
|
try {
|
|
const { apiUrl } = useRuntimeConfig().public
|
|
const { categoryId, page, limit, sort } = getQuery(event)
|
|
const query = ref({})
|
|
if(categoryId) {
|
|
query.value = { categoryId }
|
|
}
|
|
const gQuery = getQuery(event)
|
|
const { items, total }: any = await $fetch(`${apiUrl}/cms/topic/condition/paging:${page}-${limit}/sorting:${sort}`,{
|
|
method: 'POST',
|
|
headers: {site: getSite(gQuery.site).toString()},
|
|
body:{ ...query.value }
|
|
})
|
|
|
|
return { items, total };
|
|
} catch (error) {
|
|
handleError(error)
|
|
}
|
|
}
|
|
|
|
export const fetchByCode = async(event: H3Event) => {
|
|
try {
|
|
const { apiUrl } = useRuntimeConfig().public
|
|
const { topicCode }: any = getQuery(event)
|
|
const query = getQuery(event)
|
|
const { item }: any = await $fetch(`${apiUrl}/cms/topic/code:${topicCode}`, {
|
|
method: 'GET',
|
|
headers: {
|
|
site: getSite(query.site).toString()
|
|
}
|
|
})
|
|
|
|
return item
|
|
} catch (error) {
|
|
handleError(error)
|
|
}
|
|
}
|
|
|
|
export const fetchById = async(event: H3Event) => {
|
|
try {
|
|
const { apiUrl } = useRuntimeConfig().public
|
|
const { topicId }: any = getQuery(event)
|
|
const query = getQuery(event)
|
|
const { item }: any = await $fetch(`${apiUrl}/cms/topic/${topicId}`, {
|
|
method: 'GET',
|
|
headers: {
|
|
site: getSite(query.site).toString()
|
|
}
|
|
})
|
|
|
|
return item
|
|
} catch (error) {
|
|
handleError(error)
|
|
}
|
|
} |