Initial Commit
This commit is contained in:
52
src/organization/organization.schema.ts
Normal file
52
src/organization/organization.schema.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { buildJsonSchemas } from "fastify-zod";
|
||||
import mongoose from "mongoose";
|
||||
import { z } from "zod";
|
||||
|
||||
export const orgModel = mongoose.model(
|
||||
"organization",
|
||||
new mongoose.Schema({
|
||||
tenantId: String,
|
||||
pid: {
|
||||
type: String,
|
||||
unique: true,
|
||||
},
|
||||
name: String,
|
||||
domain: {
|
||||
type: String,
|
||||
unique: true,
|
||||
},
|
||||
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" }
|
||||
);
|
||||
Reference in New Issue
Block a user