import { buildJsonSchemas } from "fastify-zod"; import mongoose from "mongoose"; import { z } from "zod"; export const orgModel = mongoose.model( "organization", new mongoose.Schema({ tenantId: { type: String, required: true, }, pid: { type: String, unique: true, }, name: String, domain: { type: String, }, avatar: String, type: String, status: String, createdAt: Date, createdBy: mongoose.Types.ObjectId, }) ); const orgCore = { name: z.string().max(30), domain: z.string().max(30), avatar: z.string().url().optional(), type: z.enum(["county", "builder"], { message: "Must be county or builder", }), }; const createOrgInput = z.object({ ...orgCore, }); const createOrgResponse = z.object({ pid: z.string(), ...orgCore, }); export type CreateOrgInput = z.infer; export const { schemas: orgSchemas, $ref: $org } = buildJsonSchemas( { createOrgInput, createOrgResponse, }, { $id: "org" } );