Add pagination, complete organization routes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { buildJsonSchemas } from "fastify-zod";
|
||||
import mongoose from "mongoose";
|
||||
import { z } from "zod";
|
||||
import { pageMetadata, pageQueryParams } from "../pagination";
|
||||
|
||||
export const orgModel = mongoose.model(
|
||||
"organization",
|
||||
@@ -19,10 +20,12 @@ export const orgModel = mongoose.model(
|
||||
},
|
||||
avatar: String,
|
||||
type: String,
|
||||
isClient: Boolean,
|
||||
status: String,
|
||||
createdAt: Date,
|
||||
createdBy: mongoose.Types.ObjectId,
|
||||
})
|
||||
updatedAt: Date,
|
||||
}).index({ tenantId: 1, domain: 1 }, { unique: true })
|
||||
);
|
||||
|
||||
const orgCore = {
|
||||
@@ -32,6 +35,7 @@ const orgCore = {
|
||||
type: z.enum(["county", "builder"], {
|
||||
message: "Must be county or builder",
|
||||
}),
|
||||
isClient: z.boolean().optional(),
|
||||
};
|
||||
|
||||
const createOrgInput = z.object({
|
||||
@@ -43,12 +47,33 @@ const createOrgResponse = z.object({
|
||||
...orgCore,
|
||||
});
|
||||
|
||||
const listOrgResponse = z.object({
|
||||
orgs: z.array(createOrgResponse),
|
||||
metadata: pageMetadata,
|
||||
});
|
||||
|
||||
const updateOrgInput = z.object({
|
||||
name: z.string().max(30).optional(),
|
||||
domain: z.string().max(30).optional(),
|
||||
avatar: z.string().url().optional(),
|
||||
type: z
|
||||
.enum(["county", "builder"], {
|
||||
message: "Must be county or builder",
|
||||
})
|
||||
.optional(),
|
||||
isClient: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export type CreateOrgInput = z.infer<typeof createOrgInput>;
|
||||
export type UpdateOrgInput = z.infer<typeof updateOrgInput>;
|
||||
|
||||
export const { schemas: orgSchemas, $ref: $org } = buildJsonSchemas(
|
||||
{
|
||||
createOrgInput,
|
||||
createOrgResponse,
|
||||
listOrgResponse,
|
||||
updateOrgInput,
|
||||
pageQueryParams,
|
||||
},
|
||||
{ $id: "org" }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user