18 lines
560 B
TypeScript
18 lines
560 B
TypeScript
import { resolver, NotFoundError } from "blitz"
|
|
import db from "db"
|
|
import { z } from "zod"
|
|
|
|
const GetItemProp = 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(GetItemProp), resolver.authorize(), async ({ id }) => {
|
|
// TODO: in multi-tenant app, you must add validation to ensure correct tenant
|
|
const itemProp = await db.itemProp.findFirst({ where: { id } })
|
|
|
|
if (!itemProp) throw new NotFoundError()
|
|
|
|
return itemProp
|
|
})
|