forked from Wroclaw/WorkshopTasker
replace all $fetch with useRequestFetch
This commit is contained in:
parent
015b66706f
commit
eabb7b89c7
5 changed files with 22 additions and 22 deletions
|
@ -1,6 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/* global $fetch */
|
|
||||||
import { useRoute, useFetch, createError } from "nuxt/app";
|
|
||||||
import { ref, type Ref } from "vue";
|
import { ref, type Ref } from "vue";
|
||||||
|
|
||||||
import { VBtn, VForm } from "vuetify/components";
|
import { VBtn, VForm } from "vuetify/components";
|
||||||
|
@ -9,7 +7,10 @@ import Snowflake from "~/utils/snowflake";
|
||||||
import OrderView from "~/components/orderView.vue";
|
import OrderView from "~/components/orderView.vue";
|
||||||
import EntryEditor, { type fieldDefinition } from "~/components/entryEditor.vue";
|
import EntryEditor, { type fieldDefinition } from "~/components/entryEditor.vue";
|
||||||
|
|
||||||
|
import { useRoute, useFetch, createError, useRequestFetch } from "#imports";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const fetch = useRequestFetch();
|
||||||
const id = route.params.id;
|
const id = route.params.id;
|
||||||
|
|
||||||
const clientRequest = await useFetch(`/api/clients/${id}` as "/api/clients/:id");
|
const clientRequest = await useFetch(`/api/clients/${id}` as "/api/clients/:id");
|
||||||
|
@ -38,7 +39,7 @@ async function loadOrder(id: string) {
|
||||||
if (!entry) throw createError(`excepted order entry for ${id}`);
|
if (!entry) throw createError(`excepted order entry for ${id}`);
|
||||||
entry.loading = true;
|
entry.loading = true;
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
entry.value = await $fetch(`/api/orders/${id}` as "/api/order/:id", {
|
entry.value = await fetch(`/api/orders/${id}` as "/api/order/:id", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
}) as Order;
|
}) as Order;
|
||||||
entry.loading = false;
|
entry.loading = false;
|
||||||
|
@ -77,7 +78,7 @@ async function handleSubmit() {
|
||||||
submitting.value = true;
|
submitting.value = true;
|
||||||
normalizeForm();
|
normalizeForm();
|
||||||
try {
|
try {
|
||||||
const result = await $fetch(
|
const result = await fetch(
|
||||||
`/api/clients/${client.value.id}` as "/api/clients/:id", {
|
`/api/clients/${client.value.id}` as "/api/clients/:id", {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
body: formData.value,
|
body: formData.value,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/* global $fetch */
|
|
||||||
import { type NuxtError } from "nuxt/app";
|
import { type NuxtError } from "nuxt/app";
|
||||||
import { ref, type Ref, reactive } from "vue";
|
import { ref, type Ref, reactive } from "vue";
|
||||||
import { VBtn } from "vuetify/components";
|
import { VBtn } from "vuetify/components";
|
||||||
|
@ -8,10 +7,11 @@ import pagedTable from "~/components/pagedTable.vue";
|
||||||
import Alerts, { type AlertData } from "~/components/alerts.vue";
|
import Alerts, { type AlertData } from "~/components/alerts.vue";
|
||||||
import { type fieldDefinition } from "~/components/entryEditor.vue";
|
import { type fieldDefinition } from "~/components/entryEditor.vue";
|
||||||
|
|
||||||
import { useFetch, createError, navigateTo, useRoute, definePageMeta } from "#imports";
|
import { useFetch, createError, navigateTo, useRoute, definePageMeta, useRequestFetch } from "#imports";
|
||||||
|
|
||||||
definePageMeta({ middleware: ["auth"] });
|
definePageMeta({ middleware: ["auth"] });
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const fetch = useRequestFetch();
|
||||||
|
|
||||||
const alerts = ref<Array<AlertData>>([]);
|
const alerts = ref<Array<AlertData>>([]);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ async function rowClicked(client: string, edit = false) {
|
||||||
|
|
||||||
async function rowDelete(client: string) {
|
async function rowDelete(client: string) {
|
||||||
try {
|
try {
|
||||||
await $fetch(`/api/clients/${client}` as "/api/clients/:id", {
|
await fetch(`/api/clients/${client}` as "/api/clients/:id", {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
clients.value = clients.value.filter(e => e.id !== client);
|
clients.value = clients.value.filter(e => e.id !== client);
|
||||||
|
@ -48,7 +48,7 @@ async function loadBefore() {
|
||||||
loadingMore.value = true;
|
loadingMore.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
clients.value.push(...await $fetch("/api/clients", {
|
clients.value.push(...await fetch("/api/clients", {
|
||||||
query: {
|
query: {
|
||||||
before: clients.value[clients.value.length - 1].id,
|
before: clients.value[clients.value.length - 1].id,
|
||||||
},
|
},
|
||||||
|
@ -91,7 +91,7 @@ async function handleSubmit() {
|
||||||
submitting.value = true;
|
submitting.value = true;
|
||||||
normalizeForm();
|
normalizeForm();
|
||||||
try {
|
try {
|
||||||
const result = await $fetch(
|
const result = await fetch(
|
||||||
"/api/clients", {
|
"/api/clients", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData.value,
|
body: formData.value,
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/* global $fetch */
|
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { type NuxtError } from 'nuxt/app';
|
import { type NuxtError } from 'nuxt/app';
|
||||||
import { navigateTo, useFetch, definePageMeta } from '#imports';
|
import { navigateTo, useFetch, definePageMeta, useRequestFetch } from '#imports';
|
||||||
|
|
||||||
import EntryEditor, { type fieldDefinition } from '~/components/entryEditor.vue';
|
import EntryEditor, { type fieldDefinition } from '~/components/entryEditor.vue';
|
||||||
import Alerts, { type AlertData } from '~/components/alerts.vue';
|
import Alerts, { type AlertData } from '~/components/alerts.vue';
|
||||||
|
@ -22,7 +21,7 @@ definePageMeta({
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
try {
|
try {
|
||||||
await $fetch("/api/firstRun", {
|
await useRequestFetch()("/api/firstRun", {
|
||||||
body: formValue.value,
|
body: formValue.value,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/* global $fetch */
|
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { VForm } from "vuetify/components";
|
import { VForm } from "vuetify/components";
|
||||||
import { cookieSettings } from "~/utils/cookieSettings";
|
import { cookieSettings } from "~/utils/cookieSettings";
|
||||||
import { definePageMeta, navigateTo, useCookie, useFetch, useRoute } from "#imports";
|
import { definePageMeta, navigateTo, useCookie, useFetch, useRoute, useRequestFetch } from "#imports";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const fetch = useRequestFetch();
|
||||||
|
|
||||||
const login = ref("");
|
const login = ref("");
|
||||||
const password = ref("");
|
const password = ref("");
|
||||||
|
@ -24,7 +24,7 @@ definePageMeta({
|
||||||
async function submit() {
|
async function submit() {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
const result = await $fetch("/api/login", {
|
const result = await fetch("/api/login", {
|
||||||
body: { login: login.value, password: password.value },
|
body: { login: login.value, password: password.value },
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
|
@ -44,7 +44,7 @@ async function submit() {
|
||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
try {
|
try {
|
||||||
await $fetch("/api/logout");
|
await fetch("/api/logout");
|
||||||
loggedIn.value = false;
|
loggedIn.value = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -56,7 +56,7 @@ watch(loggedIn, updateUserInfo);
|
||||||
async function updateUserInfo() {
|
async function updateUserInfo() {
|
||||||
if (loggedIn.value) {
|
if (loggedIn.value) {
|
||||||
try {
|
try {
|
||||||
userInfo.value = JSON.stringify(await $fetch("/api/users/me"));
|
userInfo.value = JSON.stringify(await fetch("/api/users/me"));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// expected if the user is not logged in
|
// expected if the user is not logged in
|
||||||
userInfo.value = "";
|
userInfo.value = "";
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/* global $fetch */
|
|
||||||
import { ref, type Ref } from "vue";
|
import { ref, type Ref } from "vue";
|
||||||
import { VBtn } from "vuetify/components";
|
import { VBtn } from "vuetify/components";
|
||||||
import type { NuxtError } from "#app";
|
import type { NuxtError } from "#app";
|
||||||
|
@ -7,10 +6,11 @@ import type { NuxtError } from "#app";
|
||||||
import Alerts, { type AlertData } from "~/components/alerts.vue";
|
import Alerts, { type AlertData } from "~/components/alerts.vue";
|
||||||
import { type fieldDefinition } from "~/components/entryEditor.vue";
|
import { type fieldDefinition } from "~/components/entryEditor.vue";
|
||||||
|
|
||||||
import { definePageMeta, useFetch, createError, useRoute, navigateTo } from "#imports";
|
import { definePageMeta, useFetch, createError, useRoute, navigateTo, useRequestFetch } from "#imports";
|
||||||
|
|
||||||
definePageMeta({ middleware: ["auth"] });
|
definePageMeta({ middleware: ["auth"] });
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const fetch = useRequestFetch();
|
||||||
|
|
||||||
const alerts = ref<Array<AlertData>>([]);
|
const alerts = ref<Array<AlertData>>([]);
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ async function rowClicked(client: string, edit = false) {
|
||||||
|
|
||||||
async function rowDelete(client: string) {
|
async function rowDelete(client: string) {
|
||||||
try {
|
try {
|
||||||
await $fetch(`/api/orders/${client}` as "/api/orders/:id", {
|
await fetch(`/api/orders/${client}` as "/api/orders/:id", {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
orders.value = orders.value.filter(e => e.id !== client);
|
orders.value = orders.value.filter(e => e.id !== client);
|
||||||
|
@ -49,7 +49,7 @@ async function loadBefore() {
|
||||||
loadingMore.value = true;
|
loadingMore.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
orders.value.push(...await $fetch("/api/orders", {
|
orders.value.push(...await fetch("/api/orders", {
|
||||||
query: {
|
query: {
|
||||||
before: orders.value[orders.value.length - 1].id,
|
before: orders.value[orders.value.length - 1].id,
|
||||||
},
|
},
|
||||||
|
@ -87,7 +87,7 @@ async function handleSubmit() {
|
||||||
submitting.value = true;
|
submitting.value = true;
|
||||||
normalizeForm();
|
normalizeForm();
|
||||||
try {
|
try {
|
||||||
const result = await $fetch(
|
const result = await fetch(
|
||||||
"/api/orders", {
|
"/api/orders", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData.value,
|
body: formData.value,
|
||||||
|
|
Loading…
Reference in a new issue