Files
NSG_PORTAL_V2/stores/poll.ts
T

29 lines
788 B
TypeScript
Raw Normal View History

import type { Poll } from "~/server/models/poll"
export const usePollStore = defineStore('usePollStore', () => {
const currentPoll = shallowReactive<Poll>({})
2024-07-17 10:35:35 +07:00
const url : any = useRequestURL();
const host = url.hostname.split('.')[0];
2024-06-06 13:29:22 +07:00
async function fetchById(id: string) {
try {
const { data } = await useFetch<any>(`/api/services/poll-by-id`, {
query: {
2024-07-17 10:35:35 +07:00
pollId: id,
site: host
}
})
data.value && (Object.assign(currentPoll, data.value))
return currentPoll
} catch(error) {
2024-06-06 13:29:22 +07:00
}
}
2024-07-17 10:35:35 +07:00
return { fetchById, currentPoll }
2024-06-06 13:29:22 +07:00
})
if(import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(usePollStore, import.meta.hot))
2024-06-06 13:29:22 +07:00
}