propro-utils 1.5.36 → 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.
@@ -85,7 +85,10 @@ const checkIfUserExists = async accountId => {
85
85
  try {
86
86
  const userSchema = await ServiceManager.getService('UserSchema');
87
87
  const userStyleSchema = await ServiceManager.getService('UserStyleSchema');
88
- let user = await userSchema.findOne({ accountId });
88
+
89
+ let user = await userSchema
90
+ .findOne({ accountId })
91
+ .populate('userGlobalStyles');
89
92
 
90
93
  if (user) {
91
94
  if (!user.userGlobalStyles) {
@@ -94,6 +97,9 @@ const checkIfUserExists = async accountId => {
94
97
  accountId
95
98
  );
96
99
  await user.save();
100
+ user = await userSchema
101
+ .findOne({ accountId })
102
+ .populate('userGlobalStyles');
97
103
  }
98
104
  return user;
99
105
  }
@@ -102,16 +108,17 @@ const checkIfUserExists = async accountId => {
102
108
  userStyleSchema,
103
109
  accountId
104
110
  );
111
+
105
112
  user = await userSchema.create({
106
113
  accountId,
107
114
  id: uuidv4(),
108
115
  verified: false,
109
- userGlobalStyles,
116
+ userGlobalStyles: userGlobalStyles._id,
110
117
  });
111
118
 
112
- return user;
119
+ return await user.populate('userGlobalStyles');
113
120
  } catch (error) {
114
- console.error('Error in getOrCreateUser:', error);
121
+ console.error('Error in checkIfUserExists:', error);
115
122
  throw new Error('Failed to get or create user');
116
123
  }
117
124
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.5.36",
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;