Initial Commit

This commit is contained in:
2024-12-19 13:54:15 +05:30
commit 970a972b11
17 changed files with 1487 additions and 0 deletions

56
src/user/user.schema.ts Normal file
View 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" }
);