Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions BACKEND/models/user.model.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import mongoose from "mongoose";

const addressSchema = new mongoose.Schema({
label: { type: String, trim: true, default: 'Home' },
fullName: { type: String, trim: true, required: true },
phone: { type: String, trim: true, default: '' },
line1: { type: String, trim: true, required: true },
line2: { type: String, trim: true, default: '' },
city: { type: String, trim: true, required: true },
state: { type: String, trim: true, default: '' },
postalCode: { type: String, trim: true, required: true },
country: { type: String, trim: true, required: true },
isDefault: { type: Boolean, default: false },
}, { _id: true });
const addressSchema = new mongoose.Schema(
{
label: { type: String, trim: true, default: "Home" },
fullName: { type: String, trim: true, required: true },
phone: { type: String, trim: true, default: "" },
line1: { type: String, trim: true, required: true },
line2: { type: String, trim: true, default: "" },
city: { type: String, trim: true, required: true },
state: { type: String, trim: true, default: "" },
postalCode: { type: String, trim: true, required: true },
country: { type: String, trim: true, required: true },
isDefault: { type: Boolean, default: false },
},
{ _id: true }
);

const userSchema = new mongoose.Schema(
{
name: {
type: String,
required: [true, "Name is required"],
trim: true,
maxlength: [50, "Name cannot exceed 50 characters"],
},

email: {
Expand All @@ -27,31 +31,39 @@ const userSchema = new mongoose.Schema(
unique: true,
lowercase: true,
trim: true,
match: [
/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/,
"Please enter a valid email address",
],
},

password: {
type: String,
minlength: 6,
// Not required because OAuth users won't have a password initially
// Keeping it visible to avoid breaking login flow
},

googleId: {
type: String,
unique: true,
sparse: true,
},

githubId: {
type: String,
unique: true,
sparse: true,
},

phone: {
type: String,
trim: true,
default: '',
default: "",
},

avatar: {
type: String,
default: '',
default: "",
},

addresses: {
Expand All @@ -61,8 +73,8 @@ const userSchema = new mongoose.Schema(

provider: {
type: String,
enum: ['local', 'google', 'github'],
default: 'local',
enum: ["local", "google", "github"],
default: "local",
},

resetPasswordToken: {
Expand All @@ -77,9 +89,18 @@ const userSchema = new mongoose.Schema(
},
{
timestamps: true,
toJSON: {
transform: function (doc, ret) {
delete ret.password;
delete ret.resetPasswordToken;
delete ret.resetPasswordExpires;
delete ret.__v;
return ret;
},
},
}
);

const User = mongoose.model("User", userSchema);

export default User;
export default User;
34 changes: 14 additions & 20 deletions FRONTEND/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading