Removed global type declaration (use zod instead)

main
TZGyn 3 years ago
parent 08c52b0207
commit 9b0c19492c
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -1,8 +1,16 @@
const submitNote = async (
note: Note,
query: NoteQuery
): Promise<ApiResponse> => {
let response: ApiResponse = {
import { z } from 'zod'
const noteSchema = z.object({
title: z.string(),
description: z.string(),
})
const submitNote = async (note: unknown, noteId: string | string[]) => {
const parsedNote = noteSchema.safeParse(note)
if (!parsedNote.success) return
let response = {
status: 200,
message: 'Update',
error: null,
@ -10,8 +18,8 @@ const submitNote = async (
await useFetch('/api/note', {
method: 'POST',
query,
body: note,
query: { id: noteId },
body: parsedNote.data,
onResponse({ response }) {
console.log('POST:', response._data.message)
response = response._data
@ -21,6 +29,8 @@ const submitNote = async (
return response
}
type Note = z.infer<typeof noteSchema>
const useNote = () =>
useState<Note>('note', () => Object({ title: '', description: '' }))

@ -1,6 +1,6 @@
import { serverSupabaseUser, serverSupabaseClient } from '#supabase/server'
export default defineEventHandler(async (event): Promise<DeleteResponse> => {
export default defineEventHandler(async (event) => {
const user = await serverSupabaseUser(event)
const supabase = serverSupabaseClient(event)
const query = getQuery(event)

24
types/global.d.ts vendored

@ -1,24 +0,0 @@
import { PostgrestError } from '@supabase/postgrest-js'
export {}
declare global {
interface Note {
title: string
description: string
}
interface NoteQuery {
id: number | string | string[]
}
interface ApiResponse {
status: number
message: string
error: PostgrestError | null
}
interface DeleteResponse extends ApiResponse {
data: undefined[] | null
}
}
Loading…
Cancel
Save