import { defineStore } from "pinia"; import { WordResponseDTO } from "~/netcode/events/dto/wordresponse.dto"; export const useWordStore = defineStore("word", { state: () => ({ words: {} as Record, }), actions: { async fetchWordList() { const config = useRuntimeConfig(); const data = await useFetch(config.public.endpoint + `/words/all`, { credentials: "include", }) if (data.data.value && !data.error.value) { for (const word of data.data.value) { this.words[word.id] = word } } return data }, async enableWord(word: WordResponseDTO) { const config = useRuntimeConfig(); const data = await $fetch(config.public.endpoint + `/words/` + word.id + "/enable", { credentials: "include", method: "PUT" }) word.enabled = true return data }, async disableWord(word: WordResponseDTO) { const config = useRuntimeConfig(); const data = await $fetch(config.public.endpoint + `/words/` + word.id + "/disable", { credentials: "include", method: "PUT" }) word.enabled = false return data }, async createWord(value: string) { const config = useRuntimeConfig(); const data = await $fetch(config.public.endpoint + `/words/`, { credentials: "include", body: { value }, method: "POST" }) this.words[data.id] = data return data }, async deleteWord(word: WordResponseDTO){ const config = useRuntimeConfig(); const data = await $fetch(config.public.endpoint + `/words/`+word.id, { credentials: "include", method: "DELETE" }) delete this.words[word.id] } }, });