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

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