There was an error while loading. Please reload this page.
1 parent 56b0cca commit 034b2a5Copy full SHA for 034b2a5
model/User.js
@@ -92,9 +92,18 @@ const UserSchema = new mongoose.Schema(
92
{ timestamps: true }
93
);
94
95
+// Get Full Name
96
UserSchema.virtual("fullname").get(function () {
97
return `${this.firstname} ${this.lastname}`;
98
});
99
+// Get intials
100
+UserSchema.virtual("intials").get(function () {
101
+ return `${this.firstname[0]}${this.lastname[0]}`;
102
+});
103
+// Get post counts
104
+UserSchema.virtual("postCounts").get(function () {
105
+ return this.posts.length;
106
107
108
// Hash Password
109
UserSchema.pre("save", async function (next) {
0 commit comments