Website/db/app/item-props/queries/getItemProp.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
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
})