Skip to content

Commit 034b2a5

Browse files
committed
get post counts
1 parent 56b0cca commit 034b2a5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

model/User.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,18 @@ const UserSchema = new mongoose.Schema(
9292
{ timestamps: true }
9393
);
9494

95+
// Get Full Name
9596
UserSchema.virtual("fullname").get(function () {
9697
return `${this.firstname} ${this.lastname}`;
9798
});
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+
});
98107

99108
// Hash Password
100109
UserSchema.pre("save", async function (next) {

0 commit comments

Comments
 (0)