crazy-odds-bet-shared 1.0.30 → 1.0.32

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.
@@ -39,6 +39,7 @@ const betTrackerSchema = new Schema(
39
39
  baseSchemaOptions
40
40
  );
41
41
 
42
+ betTrackerSchema.index({ userId: 1 });
42
43
  betTrackerSchema.index({ groupId: 1 });
43
44
  betTrackerSchema.index({ type: 1 });
44
45
  betTrackerSchema.index({ status: 1 });
package/models/user.js CHANGED
@@ -1,10 +1,14 @@
1
- const bcrypt = require('bcrypt');
2
1
  const { Schema, model } = require('mongoose');
3
2
  const { createBaseSchema, baseSchemaOptions } = require('./base');
4
3
 
5
4
  const BCRYPT_ROUNDS = 10;
6
5
  const BCRYPT_PREFIX = '$2';
7
6
 
7
+ /** Lazy-load bcrypt so Lambdas that only load shared/models (e.g. for Bookmaker/Fixture) don't trigger node-pre-gyp/package.json lookup. */
8
+ function getBcrypt() {
9
+ return require('bcrypt');
10
+ }
11
+
8
12
  /**
9
13
  * User schema
10
14
  */
@@ -28,7 +32,7 @@ userSchema.pre('save', async function (next) {
28
32
  if (typeof this.password !== 'string') return next();
29
33
  if (this.password.startsWith(BCRYPT_PREFIX)) return next();
30
34
  try {
31
- this.password = await bcrypt.hash(this.password, BCRYPT_ROUNDS);
35
+ this.password = await getBcrypt().hash(this.password, BCRYPT_ROUNDS);
32
36
  next();
33
37
  } catch (err) {
34
38
  next(err);
@@ -40,6 +44,14 @@ userSchema.index({ isActive: 1 });
40
44
  userSchema.index({ roleId: 1 });
41
45
  userSchema.index({ email: 1, isActive: 1 });
42
46
 
47
+ // Virtuals
48
+ userSchema.virtual('role', {
49
+ ref: 'UserRole',
50
+ localField: 'roleId',
51
+ foreignField: '_id',
52
+ justOne: true
53
+ });
54
+
43
55
  // Static methods
44
56
  userSchema.static('findByEmail', function (email) {
45
57
  return this.findOne({ email: email.toLowerCase() });
@@ -69,6 +81,7 @@ userSchema.method('deactivate', async function () {
69
81
 
70
82
  userSchema.method('comparePassword', async function (password) {
71
83
  if (!this.password) return false;
84
+ const bcrypt = getBcrypt();
72
85
  if (this.password.startsWith(BCRYPT_PREFIX)) {
73
86
  const match = await bcrypt.compare(password, this.password);
74
87
  if (match) return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crazy-odds-bet-shared",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "Shared MongoDB models and utilities for odds project",
5
5
  "main": "index.js",
6
6
  "exports": {