Changed ways to access calendars
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { serverSupabaseClient } from "#supabase/server";
|
||||
import { z } from 'zod'
|
||||
import { serverSupabaseClient } from "#supabase/server";
|
||||
import type { Character } from "~/models/Characters";
|
||||
|
||||
const querySchema = z.object({
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { serverSupabaseClient } from "#supabase/server";
|
||||
import type { World } from "~/models/World";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const client = await serverSupabaseClient(event)
|
||||
|
||||
return client.from('worlds')
|
||||
.select(`id, name, description, color`)
|
||||
.returns<World[]>()
|
||||
})
|
||||
30
server/api/worlds/query.get.ts
Normal file
30
server/api/worlds/query.get.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { z } from 'zod'
|
||||
import { serverSupabaseClient } from "#supabase/server";
|
||||
import type { World } from "~/models/World";
|
||||
|
||||
const querySchema = z.object({
|
||||
id: z.number({ coerce: true }).positive().int().optional(),
|
||||
full: z.boolean({ coerce: true }).optional()
|
||||
})
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const client = await serverSupabaseClient(event)
|
||||
const query = await getValidatedQuery(event, querySchema.parse)
|
||||
|
||||
const fullFields = `id, name, description, color, calendars (id, name, color, today)`
|
||||
const partialFields = `id, name, description, color`
|
||||
|
||||
let output
|
||||
|
||||
if (query.full) {
|
||||
output = client.from('worlds').select(fullFields)
|
||||
} else {
|
||||
output = client.from('worlds').select(partialFields)
|
||||
}
|
||||
|
||||
if (query.id) {
|
||||
return output.eq('id', query.id).single<World>()
|
||||
}
|
||||
|
||||
return output.returns<World[]>()
|
||||
})
|
||||
Reference in New Issue
Block a user