Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 74b69c8

Browse files
committed
ii
1 parent 6f24e5f commit 74b69c8

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

server/model/User.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import mongoose from "mongoose";
22

3+
4+
35
const userSchema = new mongoose.Schema(
46
{
57
githubId: String,
@@ -104,7 +106,11 @@ const userSchema = new mongoose.Schema(
104106
firstName: String,
105107
lastName: String,
106108
middleName: String,
107-
109+
position: {
110+
type: String,
111+
required: true,
112+
lowercase: true,
113+
},
108114
employmentStatus: String,
109115
dateHired: Date,
110116
address: String,
@@ -115,7 +121,12 @@ const userSchema = new mongoose.Schema(
115121
{ timestamps: true }
116122
);
117123

124+
userSchema.pre('save', function (next) {
125+
if (this.position && this.isModified('position')) {
126+
this.role = this.position.toLowerCase();
127+
}
128+
next();
129+
});
118130

119-
120-
const User = mongoose.models.User || mongoose.model("User", userSchema);
131+
const User = mongoose.model("User", userSchema);
121132
export default User;

0 commit comments

Comments
 (0)