Website/db/app/item-prefabs/queries/getItemPrefab.ts
Mangiang 4b26395870
Some checks failed
continuous-integration/drone/push Build is failing
chore: work in progress
2022-05-06 21:05:02 -04:00

18 lines
572 B
TypeScript

import { resolver, NotFoundError } from "blitz"
import db from "db"
import { z } from "zod"
const GetItemPrefab = z.object({
// This accepts type of undefined, but is required at runtime
id: z.number().optional().refine(Boolean, "Required"),
})
export default resolver.pipe(resolver.zod(GetItemPrefab), resolver.authorize(), async ({ id }) => {
// TODO: in multi-tenant app, you must add validation to ensure correct tenant
const itemPrefab = await db.itemPrefab.findFirst({ where: { id } })
if (!itemPrefab) throw new NotFoundError()
return itemPrefab
})