Files
NSG_PORTAL_V2/server/models/topic.ts
T

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-06-03 12:27:22 +07:00
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 }
}
2024-07-17 10:35:35 +07:00
const gQuery = getQuery(event)
2024-06-03 12:27:22 +07:00
const { items, total }: any = await $fetch(`${apiUrl}/cms/topic/condition/paging:${page}-${limit}/sorting:${sort}`,{
method: 'POST',
2024-07-17 10:35:35 +07:00
headers: {site: getSite(gQuery.site).toString()},
2024-06-03 12:27:22 +07:00
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)
2024-07-17 10:35:35 +07:00
const query = getQuery(event)
2024-06-03 12:27:22 +07:00
const { item }: any = await $fetch(`${apiUrl}/cms/topic/code:${topicCode}`, {
method: 'GET',
headers: {
2024-07-17 10:35:35 +07:00
site: getSite(query.site).toString()
2024-06-03 12:27:22 +07:00
}
})
return item
} catch (error) {
handleError(error)
}
}
export const fetchById = async(event: H3Event) => {
try {
const { apiUrl } = useRuntimeConfig().public
const { topicId }: any = getQuery(event)
2024-07-17 10:35:35 +07:00
const query = getQuery(event)
2024-06-03 12:27:22 +07:00
const { item }: any = await $fetch(`${apiUrl}/cms/topic/${topicId}`, {
method: 'GET',
headers: {
2024-07-17 10:35:35 +07:00
site: getSite(query.site).toString()
2024-06-03 12:27:22 +07:00
}
})
return item
} catch (error) {
handleError(error)
}
}