55 lines
1.0 KiB
TypeScript
55 lines
1.0 KiB
TypeScript
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<typeof createOrgInput>;
|
|
|
|
export const { schemas: orgSchemas, $ref: $org } = buildJsonSchemas(
|
|
{
|
|
createOrgInput,
|
|
createOrgResponse,
|
|
},
|
|
{ $id: "org" }
|
|
);
|