Website/db/app/item-use-prefabs/queries/getItemUsePrefab.ts

22 lines
608 B
TypeScript
Raw Normal View History

2022-05-06 21:05:02 -04:00
import { resolver, NotFoundError } from "blitz"
import db from "db"
import { z } from "zod"
const GetItemUsePrefab = 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(GetItemUsePrefab),
resolver.authorize(),
async ({ id }) => {
// TODO: in multi-tenant app, you must add validation to ensure correct tenant
const itemUsePrefab = await db.itemUsePrefab.findFirst({ where: { id } })
if (!itemUsePrefab) throw new NotFoundError()
return itemUsePrefab
}
)