import { utils } from "~/utils/utilities";
import { Author } from "./author";
import Base from "./base";
import { H3Event } from "h3";

export const get = async(event: H3Event) => {
    try {
        const { apiUrl } = useRuntimeConfig().public
        const { code } = getQuery(event)

        const { items }: any = await $fetch(`${apiUrl}/cms/tag/code:${code}`, {
            headers: {
                site: 1
            }
        })
        return items
    } catch(error) {
        handleError(error);
    }
}

export const fetchById = async(event: H3Event) => {
    try {
        const { apiUrl } = useRuntimeConfig().public
        const { tagId }: any = getQuery(event)
        const { item }: any = await $fetch(`${apiUrl}/cms/tag/${tagId}`, {
            method: 'GET',
            headers: {
                Site: 1
            }
        })
        return item
    } catch (error) {
        handleError(error)
    }
}