@positivegrid/pg-mongoose-schema 27.7.3 → 27.7.4-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/models/user.js +14 -1
  2. package/package.json +1 -1
package/models/user.js CHANGED
@@ -66,12 +66,25 @@ module.exports = function (mongoose) {
66
66
  selected_country: { type: String, default: null },
67
67
  date_joined: { type: Date, default: Date.now },
68
68
  search_mark: { type: Number, default: 0 } // control the order of search
69
- }, { collection: 'jamup_userprofile' })
69
+ }, { collection: 'jamup_userprofile', toJSON: { virtuals: true }, toObject: { virtuals: true } })
70
70
  UserProfileSchema
71
71
  .index({ user_id: 1 }, { unique: true })
72
72
  .index({ reset_password_token: 1 })
73
73
 
74
74
  UserProfileSchema.index({full_name: 'text', first_name: 'text', last_name: 'text'})
75
+ UserProfileSchema.virtual('full_name').get(function () {
76
+ if (this.full_name) {
77
+ return this.full_name
78
+ }
79
+
80
+ if (!this.first_name && !this.last_name) {
81
+ const timestamp = new Date(this.date_joined).getTime().toString().padStart(8, '0').toUpperCase()
82
+ const objectId = new this._id.toString().slice(-4).toUpperCase()
83
+ return `PG_${timestamp}${objectId}`
84
+ } else {
85
+ return `${this.first_name} ${this.last_name}`
86
+ }
87
+ });
75
88
 
76
89
  const UserAddressSchema = new Schema({
77
90
  user_id: { type: ObjectId, ref: 'User', required: true },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@positivegrid/pg-mongoose-schema",
3
- "version": "27.7.3",
3
+ "version": "27.7.4-beta.0",
4
4
  "description": "Positive Grid mongoose schema",
5
5
  "author": "Ferrari Lee <shiyung@positivegrid.com>",
6
6
  "homepage": "https://git.positivegrid.com:8443/backend/pg-mongoose-schema",