replace all $fetch with useRequestFetch

This commit is contained in:
Wroclaw 2023-12-20 05:45:29 +01:00
parent 015b66706f
commit eabb7b89c7
5 changed files with 22 additions and 22 deletions

View file

@ -1,6 +1,4 @@
<script setup lang="ts">
/* global $fetch */
import { useRoute, useFetch, createError } from "nuxt/app";
import { ref, type Ref } from "vue";
import { VBtn, VForm } from "vuetify/components";
@ -9,7 +7,10 @@ import Snowflake from "~/utils/snowflake";
import OrderView from "~/components/orderView.vue";
import EntryEditor, { type fieldDefinition } from "~/components/entryEditor.vue";
import { useRoute, useFetch, createError, useRequestFetch } from "#imports";
const route = useRoute();
const fetch = useRequestFetch();
const id = route.params.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}`);
entry.loading = true;
// @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",
}) as Order;
entry.loading = false;
@ -77,7 +78,7 @@ async function handleSubmit() {
submitting.value = true;
normalizeForm();
try {
const result = await $fetch(
const result = await fetch(
`/api/clients/${client.value.id}` as "/api/clients/:id", {
method: "PATCH",
body: formData.value,

View file

@ -1,5 +1,4 @@
<script setup lang="ts">
/* global $fetch */
import { type NuxtError } from "nuxt/app";
import { ref, type Ref, reactive } from "vue";
import { VBtn } from "vuetify/components";
@ -8,10 +7,11 @@ import pagedTable from "~/components/pagedTable.vue";
import Alerts, { type AlertData } from "~/components/alerts.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"] });
const route = useRoute();
const fetch = useRequestFetch();
const alerts = ref<Array<AlertData>>([]);
@ -32,7 +32,7 @@ async function rowClicked(client: string, edit = false) {
async function rowDelete(client: string) {
try {
await $fetch(`/api/clients/${client}` as "/api/clients/:id", {
await fetch(`/api/clients/${client}` as "/api/clients/:id", {
method: "DELETE",
});
clients.value = clients.value.filter(e => e.id !== client);
@ -48,7 +48,7 @@ async function loadBefore() {
loadingMore.value = true;
try {
clients.value.push(...await $fetch("/api/clients", {
clients.value.push(...await fetch("/api/clients", {
query: {
before: clients.value[clients.value.length - 1].id,
},
@ -91,7 +91,7 @@ async function handleSubmit() {
submitting.value = true;
normalizeForm();
try {
const result = await $fetch(
const result = await fetch(
"/api/clients", {
method: "POST",
body: formData.value,

View file

@ -1,8 +1,7 @@
<script setup lang="ts">
/* global $fetch */
import { ref } from 'vue';
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 Alerts, { type AlertData } from '~/components/alerts.vue';
@ -22,7 +21,7 @@ definePageMeta({
async function submit() {
try {
await $fetch("/api/firstRun", {
await useRequestFetch()("/api/firstRun", {
body: formValue.value,
method: "POST",
});

View file

@ -1,11 +1,11 @@
<script setup lang="ts">
/* global $fetch */
import { ref, watch } from "vue";
import { VForm } from "vuetify/components";
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 fetch = useRequestFetch();
const login = ref("");
const password = ref("");
@ -24,7 +24,7 @@ definePageMeta({
async function submit() {
loading.value = true;
try {
const result = await $fetch("/api/login", {
const result = await fetch("/api/login", {
body: { login: login.value, password: password.value },
method: "POST",
});
@ -44,7 +44,7 @@ async function submit() {
async function logout() {
try {
await $fetch("/api/logout");
await fetch("/api/logout");
loggedIn.value = false;
} catch (e) {
console.error(e);
@ -56,7 +56,7 @@ watch(loggedIn, updateUserInfo);
async function updateUserInfo() {
if (loggedIn.value) {
try {
userInfo.value = JSON.stringify(await $fetch("/api/users/me"));
userInfo.value = JSON.stringify(await fetch("/api/users/me"));
} catch (e) {
// expected if the user is not logged in
userInfo.value = "";

View file

@ -1,5 +1,4 @@
<script setup lang="ts">
/* global $fetch */
import { ref, type Ref } from "vue";
import { VBtn } from "vuetify/components";
import type { NuxtError } from "#app";
@ -7,10 +6,11 @@ import type { NuxtError } from "#app";
import Alerts, { type AlertData } from "~/components/alerts.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"] });
const route = useRoute();
const fetch = useRequestFetch();
const alerts = ref<Array<AlertData>>([]);
@ -33,7 +33,7 @@ async function rowClicked(client: string, edit = false) {
async function rowDelete(client: string) {
try {
await $fetch(`/api/orders/${client}` as "/api/orders/:id", {
await fetch(`/api/orders/${client}` as "/api/orders/:id", {
method: "DELETE",
});
orders.value = orders.value.filter(e => e.id !== client);
@ -49,7 +49,7 @@ async function loadBefore() {
loadingMore.value = true;
try {
orders.value.push(...await $fetch("/api/orders", {
orders.value.push(...await fetch("/api/orders", {
query: {
before: orders.value[orders.value.length - 1].id,
},
@ -87,7 +87,7 @@ async function handleSubmit() {
submitting.value = true;
normalizeForm();
try {
const result = await $fetch(
const result = await fetch(
"/api/orders", {
method: "POST",
body: formData.value,