17 lines
533 B
TypeScript
17 lines
533 B
TypeScript
![]() |
import { resolver } from "blitz"
|
||
|
import db from "db"
|
||
|
import { z } from "zod"
|
||
|
|
||
|
const CreateItem = z.object({
|
||
|
id: z.number().optional().refine(Boolean, "Required"),
|
||
|
name: z.string().optional().refine(String, "Required"),
|
||
|
type: z.string().optional().refine(String, "Required"),
|
||
|
})
|
||
|
|
||
|
export default resolver.pipe(resolver.zod(CreateItem), resolver.authorize(), async (input) => {
|
||
|
// TODO: in multi-tenant app, you must add validation to ensure correct tenant
|
||
|
const item = await db.item.create({ data: input })
|
||
|
|
||
|
return item
|
||
|
})
|