propro-utils 1.5.35 → 1.5.37

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.
@@ -2,6 +2,7 @@ require('dotenv').config();
2
2
  const axios = require('axios');
3
3
  const { getOrSetCache } = require('../utils/redis');
4
4
  const { checkIfUserExists } = require('./account_info');
5
+ const ServiceManager = require('../utils/serviceManager');
5
6
 
6
7
  /**
7
8
  * Middleware for authenticating and authorizing API requests.
@@ -2,6 +2,7 @@ require('dotenv').config();
2
2
  const axios = require('axios');
3
3
  const { getOrSetCache } = require('../utils/redis');
4
4
  const { v4: uuidv4 } = require('uuid');
5
+ const ServiceManager = require('../utils/serviceManager');
5
6
 
6
7
  /**
7
8
  * Retrieves the account profile data from the authentication server and caches it using Redis.
@@ -84,7 +85,10 @@ const checkIfUserExists = async accountId => {
84
85
  try {
85
86
  const userSchema = await ServiceManager.getService('UserSchema');
86
87
  const userStyleSchema = await ServiceManager.getService('UserStyleSchema');
87
- let user = await userSchema.findOne({ accountId });
88
+
89
+ let user = await userSchema
90
+ .findOne({ accountId })
91
+ .populate('userGlobalStyles');
88
92
 
89
93
  if (user) {
90
94
  if (!user.userGlobalStyles) {
@@ -93,6 +97,9 @@ const checkIfUserExists = async accountId => {
93
97
  accountId
94
98
  );
95
99
  await user.save();
100
+ user = await userSchema
101
+ .findOne({ accountId })
102
+ .populate('userGlobalStyles');
96
103
  }
97
104
  return user;
98
105
  }
@@ -101,16 +108,17 @@ const checkIfUserExists = async accountId => {
101
108
  userStyleSchema,
102
109
  accountId
103
110
  );
111
+
104
112
  user = await userSchema.create({
105
113
  accountId,
106
114
  id: uuidv4(),
107
115
  verified: false,
108
- userGlobalStyles,
116
+ userGlobalStyles: userGlobalStyles._id,
109
117
  });
110
118
 
111
- return user;
119
+ return await user.populate('userGlobalStyles');
112
120
  } catch (error) {
113
- console.error('Error in getOrCreateUser:', error);
121
+ console.error('Error in checkIfUserExists:', error);
114
122
  throw new Error('Failed to get or create user');
115
123
  }
116
124
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.5.35",
3
+ "version": "1.5.37",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -44,6 +44,7 @@ const sanitizeUser = user => {
44
44
  sanitized.accountId = sanitized._doc.accountId;
45
45
  sanitized.createdAt = sanitized._doc.createdAt;
46
46
  sanitized.updatedAt = sanitized._doc.updatedAt;
47
+ sanitized.userGlobalStyles = sanitized._doc.userGlobalStyles;
47
48
 
48
49
  delete sanitized._doc.mapList;
49
50
  delete sanitized._doc.folderList;