ratemypackage
Version:
RateMyPackage is a shared library designed to streamline development for the RateMyCampus project. It provides a collection of reusable types, interfaces, and utility functions to support both frontend and backend operations. By centralizing common logic
114 lines (106 loc) • 3.57 kB
text/typescript
import { z } from "zod";
const fileValidation = z.custom<File>((val) => val instanceof File, {
message: "Invalid file",
});
export const userSchema = z.object({
email: z
.string({
required_error: "Email is required",
invalid_type_error: "Email must be a string",
})
.email({ message: "Invalid email address" }),
fullName: z.string({
required_error: "Fullname is required",
invalid_type_error: "Fullname must be a string",
}),
password: z
.string({
required_error: "Password is required",
invalid_type_error: "Password must be a string",
})
.min(8, { message: "Password must be 8 character long" }),
profilePhoto: fileValidation.optional().nullable(),
});
export type User = z.infer<typeof userSchema>;
export const uniSchema = z.object({
name: z.string({
required_error: "University name is required",
invalid_type_error: "University name must be a string",
}),
fee: z.string({
required_error: "University fee is required",
invalid_type_error: "University fee must be a string",
}),
topField: z.string({
required_error: "University's top field is required",
invalid_type_error: "University's top field must be a string",
}),
status: z.string({
required_error: "University status is required",
invalid_type_error: "University status must be a string",
}),
mainCampus: z.string({
required_error: "University main campus is required",
invalid_type_error: "Main Campus must be a string",
}),
campuses: z.string({
required_error: "How many campuses?",
invalid_type_error: "Campuses must be string",
}),
logo: fileValidation,
coverPhoto: fileValidation,
});
export type University = z.infer<typeof uniSchema>;
export const postSchema = z.object({
content: z
.string({ invalid_type_error: "Content must be string" })
.max(500, "Post cannot exceed 500 characters")
.optional()
.nullable(),
universityId: z.number({
required_error: "Univeristy ID is required",
invalid_type_error: "University ID must be a number!",
}),
userId: z.number({
required_error: "User ID is required",
invalid_type_error: "User ID must be a number!",
}),
photo: fileValidation.optional().nullable(),
});
export type Post = z.infer<typeof postSchema>;
export const commentSchema = z.object({
comment: z.string().max(150, "Comment cannot exceed 150 characters"),
userId: z.number({
required_error: "User ID is required",
invalid_type_error: "User ID must be a number!",
}),
postId: z.number({
required_error: "Post ID is required",
invalid_type_error: "Post ID must be a number!",
}),
});
export type Comment = z.infer<typeof commentSchema>;
export const passwordSchema = z
.string({
required_error: "Password is required",
invalid_type_error: "Password must be string",
})
.min(8, { message: "Password must be 8 character long" });
export type Password = z.infer<typeof passwordSchema>;
export const editProfileSchema = z.object({
fullName: z
.string({
invalid_type_error: "Fullname must be a string",
})
.optional()
.nullable(),
password: z
.string({
invalid_type_error: "Password must be a string",
})
.min(8, { message: "Password must be 8 character long" })
.optional()
.nullable(),
profilePhoto: fileValidation.optional().nullable(),
});
export type EditProfile = z.infer<typeof editProfileSchema>;