22 lines
608 B
TypeScript
22 lines
608 B
TypeScript
![]() |
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
|
||
|
}
|
||
|
)
|