| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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<Question>, 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<Question>) => (this.questions = data.sort((a, b) => a.order - b.order)));
- },
- },
- });
|