import { Question } from "@/models/Questionnaire"; import Toast from "@/utils/Toast"; import { defineComponent } from "vue"; const API_URL = process.env.VUE_APP_API_URL; export default defineComponent({ data() { return { introduction: "", questions: [] as Array, opened: false }; }, methods: { getQuestionnaire(uuid: string) { // Get previously saved introduction fetch(`${API_URL}api/questionnaire/${uuid}`, { method: "GET", }) .then((res) => { if (res.status == 200) { return res.json(); } if (res.status == 404) { Toast({ html: "Pas de donnée existante pour l'introduction du questionnaire", classes: "error", }); } throw new Error("Failed"); }) .then((t) => { this.introduction = t.introduction ?? ""; this.opened = t.opened ?? false; }); // Get previously saved questions fetch(`${API_URL}api/questionnaire/${uuid}/questions`, { method: "GET", }) .then((res) => { if (res.status == 200) { return res.json(); } if (res.status == 404) { Toast({ html: "Pas de question associeé à ce questionnaire", classes: "error", }); } throw new Error("Failed"); }) .then((data: Array) => (this.questions = data.sort((a, b) => a.order - b.order))); }, }, });