add rts routes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { buildJsonSchemas } from "fastify-zod";
|
||||
import mongoose from "mongoose";
|
||||
import { z } from "zod";
|
||||
import { roles } from "../utils/roles";
|
||||
|
||||
export const userModel = mongoose.model(
|
||||
"user",
|
||||
@@ -14,6 +15,7 @@ export const userModel = mongoose.model(
|
||||
unique: true,
|
||||
required: true,
|
||||
},
|
||||
orgId: mongoose.Types.ObjectId,
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
name: String,
|
||||
@@ -24,7 +26,7 @@ export const userModel = mongoose.model(
|
||||
},
|
||||
avatar: String,
|
||||
status: String,
|
||||
claims: [String],
|
||||
role: String,
|
||||
createdAt: Date,
|
||||
createdBy: mongoose.Types.ObjectId,
|
||||
lastLogin: Date,
|
||||
@@ -41,12 +43,23 @@ const userCore = {
|
||||
})
|
||||
.email(),
|
||||
avatar: z.string().url().optional(),
|
||||
claims: z.array(z.string()).optional(),
|
||||
role: z.enum(roles),
|
||||
orgId: z.string().optional(),
|
||||
};
|
||||
|
||||
const createUserInput = z.object({
|
||||
...userCore,
|
||||
});
|
||||
const createUserInput = z
|
||||
.object({
|
||||
...userCore,
|
||||
})
|
||||
.superRefine((data, ctx) => {
|
||||
if (data.role == "builder" && !data.orgId) {
|
||||
ctx.addIssue({
|
||||
path: ["orgId"],
|
||||
message: 'orgId is required when role is "builder"',
|
||||
code: z.ZodIssueCode.custom,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const createUserResponse = z.object({
|
||||
pid: z.string().cuid2(),
|
||||
|
||||
Reference in New Issue
Block a user