Complete Throwing Responses

This commit is contained in:
2025-04-15 22:09:22 +02:00
parent 07c29d65b7
commit e91dd6ac8d
2 changed files with 11 additions and 12 deletions

View File

@@ -1,15 +1,9 @@
<script setup lang="ts">
// const route = useRoute();
// route.params.contactId
const { $trpc } = useNuxtApp();
const route = useRoute();
const contact = ref({
first: "Your",
last: "Name",
avatar: "https://placecats.com/200/200",
twitter: "your_handle",
notes: "Some notes",
favorite: true,
});
const { data: contact } = await $trpc.contactGet.useQuery({ contactId: `${route.params.contactId}` });
if (contact.value === null) throw createError({ statusCode: 404, statusMessage: 'Not Found' });
function deleteSubmit(event: Event) {
const response = window.confirm(

View File

@@ -1,6 +1,6 @@
import { publicProcedure, router } from '~/server/trpc/init';
import { z } from 'zod';
import { getContacts } from "~/server/utils/data";
import { getContact, getContacts } from "~/server/utils/data";
export const appRouter = router({
hello: publicProcedure.input(
@@ -14,7 +14,12 @@ export const appRouter = router({
}),
contactList: publicProcedure.query(async () => {
return await getContacts();
})
}),
contactGet: publicProcedure.input(
z.object({ contactId: z.string() })
).query(async (opts) => {
return await getContact(opts.input.contactId);
}),
});
// export type definition of API