propro-utils 1.5.86 → 1.5.89
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.
- package/middlewares/account_info.js +21 -3
- package/package.json +1 -1
|
@@ -117,12 +117,16 @@ const DEFAULT_THEME = {
|
|
|
117
117
|
* @throws {Error} If there's an issue with database operations or invalid input
|
|
118
118
|
*/
|
|
119
119
|
const checkIfUserExists = async accountId => {
|
|
120
|
+
console.log('Starting checkIfUserExists for accountId:', accountId);
|
|
121
|
+
|
|
120
122
|
// Input validation
|
|
121
123
|
if (!accountId || typeof accountId !== 'string') {
|
|
124
|
+
console.warn('Invalid accountId provided:', accountId);
|
|
122
125
|
throw new Error('Invalid accountId provided');
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
try {
|
|
129
|
+
console.log('Loading schemas...');
|
|
126
130
|
// Load all required schemas in parallel
|
|
127
131
|
const [userSchema, userStyleSchema, folderSchema, themeSchema] =
|
|
128
132
|
await Promise.all([
|
|
@@ -131,6 +135,7 @@ const checkIfUserExists = async accountId => {
|
|
|
131
135
|
ServiceManager.getService('FolderSchema'),
|
|
132
136
|
ServiceManager.getService('ThemeSchema'),
|
|
133
137
|
]);
|
|
138
|
+
console.log('Schemas loaded successfully');
|
|
134
139
|
|
|
135
140
|
if (!userSchema) {
|
|
136
141
|
throw new Error('UserSchema service not available');
|
|
@@ -142,15 +147,20 @@ const checkIfUserExists = async accountId => {
|
|
|
142
147
|
.select('-theme -folderList -userGlobalStyles -mapList')
|
|
143
148
|
.lean();
|
|
144
149
|
|
|
150
|
+
console.log('User lookup result:', user ? 'User found' : 'User not found');
|
|
151
|
+
|
|
145
152
|
if (user) {
|
|
153
|
+
console.log('Updating existing user data...');
|
|
146
154
|
const updates = [];
|
|
147
155
|
|
|
148
156
|
// Handle userGlobalStyles
|
|
149
157
|
if (userStyleSchema) {
|
|
150
158
|
if (!user.userGlobalStyles) {
|
|
159
|
+
console.log('Creating missing userGlobalStyles...');
|
|
151
160
|
updates.push(
|
|
152
161
|
createUserGlobalStyles(userStyleSchema, accountId).then(
|
|
153
162
|
async styles => {
|
|
163
|
+
console.log('UserGlobalStyles created successfully');
|
|
154
164
|
await userSchema.updateOne(
|
|
155
165
|
{ _id: user._id },
|
|
156
166
|
{ userGlobalStyles: styles._id }
|
|
@@ -171,6 +181,7 @@ const checkIfUserExists = async accountId => {
|
|
|
171
181
|
|
|
172
182
|
// Handle folders
|
|
173
183
|
if (folderSchema) {
|
|
184
|
+
console.log('Checking folders...');
|
|
174
185
|
updates.push(
|
|
175
186
|
(async () => {
|
|
176
187
|
const existingFolders = await folderSchema
|
|
@@ -178,6 +189,7 @@ const checkIfUserExists = async accountId => {
|
|
|
178
189
|
.select('name')
|
|
179
190
|
.lean();
|
|
180
191
|
|
|
192
|
+
console.log('Existing folders count:', existingFolders.length);
|
|
181
193
|
const existingFolderNames = new Set(
|
|
182
194
|
existingFolders.map(f => f.name)
|
|
183
195
|
);
|
|
@@ -199,6 +211,7 @@ const checkIfUserExists = async accountId => {
|
|
|
199
211
|
|
|
200
212
|
// Handle themes
|
|
201
213
|
if (themeSchema) {
|
|
214
|
+
console.log('Checking themes...');
|
|
202
215
|
updates.push(
|
|
203
216
|
(async () => {
|
|
204
217
|
const defaultThemeExists = await themeSchema.exists({
|
|
@@ -206,6 +219,7 @@ const checkIfUserExists = async accountId => {
|
|
|
206
219
|
accountId,
|
|
207
220
|
});
|
|
208
221
|
|
|
222
|
+
console.log('Default theme exists:', defaultThemeExists);
|
|
209
223
|
if (!defaultThemeExists) {
|
|
210
224
|
const defaultTheme = await themeSchema.create({
|
|
211
225
|
...DEFAULT_THEME,
|
|
@@ -225,7 +239,9 @@ const checkIfUserExists = async accountId => {
|
|
|
225
239
|
}
|
|
226
240
|
|
|
227
241
|
// Wait for all updates to complete
|
|
242
|
+
console.log('Waiting for all updates to complete...');
|
|
228
243
|
await Promise.all(updates);
|
|
244
|
+
console.log('All updates completed successfully');
|
|
229
245
|
|
|
230
246
|
// Return fresh user data after updates, excluding specified fields
|
|
231
247
|
return userSchema
|
|
@@ -285,16 +301,18 @@ const checkIfUserExists = async accountId => {
|
|
|
285
301
|
await createDefaultFolders(folderSchema, newUser.id);
|
|
286
302
|
}
|
|
287
303
|
|
|
288
|
-
|
|
304
|
+
console.log('Operation completed successfully');
|
|
289
305
|
return userSchema
|
|
290
306
|
.findById(newUser._id)
|
|
291
307
|
.select('-theme -folderList -userGlobalStyles -mapList')
|
|
292
308
|
.lean();
|
|
293
309
|
} catch (error) {
|
|
294
|
-
console.error('
|
|
310
|
+
console.error('Detailed error in checkIfUserExists:', {
|
|
295
311
|
accountId,
|
|
296
|
-
|
|
312
|
+
errorName: error.name,
|
|
313
|
+
errorMessage: error.message,
|
|
297
314
|
stack: error.stack,
|
|
315
|
+
additionalInfo: error.response?.data, // For axios errors
|
|
298
316
|
});
|
|
299
317
|
throw new Error(`Failed to get or create user: ${error.message}`);
|
|
300
318
|
}
|