Initial Commit
This commit is contained in:
56
src/user/user.schema.ts
Normal file
56
src/user/user.schema.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { buildJsonSchemas } from "fastify-zod";
|
||||
import mongoose from "mongoose";
|
||||
import { z } from "zod";
|
||||
|
||||
export const userModel = mongoose.model(
|
||||
"user",
|
||||
new mongoose.Schema({
|
||||
tenantId: String,
|
||||
pid: {
|
||||
type: String,
|
||||
unique: true,
|
||||
},
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
email: {
|
||||
type: String,
|
||||
unique: true,
|
||||
},
|
||||
avatar: String,
|
||||
status: String,
|
||||
createdAt: Date,
|
||||
createdBy: mongoose.Types.ObjectId,
|
||||
lastLogin: Date,
|
||||
})
|
||||
);
|
||||
|
||||
const userCore = {
|
||||
firstName: z.string().max(30),
|
||||
lastName: z.string().max(30),
|
||||
email: z
|
||||
.string({
|
||||
required_error: "Email is required",
|
||||
invalid_type_error: "Email must be a valid string",
|
||||
})
|
||||
.email(),
|
||||
avatar: z.string().url().optional(),
|
||||
};
|
||||
|
||||
const createUserInput = z.object({
|
||||
...userCore,
|
||||
});
|
||||
|
||||
const createUserResponse = z.object({
|
||||
pid: z.string().cuid2(),
|
||||
...userCore,
|
||||
});
|
||||
|
||||
export type CreateUserInput = z.infer<typeof createUserInput>;
|
||||
|
||||
export const { schemas: userSchemas, $ref: $user } = buildJsonSchemas(
|
||||
{
|
||||
createUserInput,
|
||||
createUserResponse,
|
||||
},
|
||||
{ $id: "user" }
|
||||
);
|
||||
Reference in New Issue
Block a user