propro-utils 1.5.94 → 1.5.95
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.
|
@@ -77,7 +77,7 @@ const authValidation = (requiredPermissions = []) => {
|
|
|
77
77
|
req.user = user.id;
|
|
78
78
|
next();
|
|
79
79
|
} catch (error) {
|
|
80
|
-
console.log(error);
|
|
80
|
+
console.log(error.message);
|
|
81
81
|
if (error.response && error.response.status) {
|
|
82
82
|
next(new Error(error.response.data.message));
|
|
83
83
|
}
|
|
@@ -100,7 +100,7 @@ async function createDefaultFolders(folderSchema, accountId) {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
const DEFAULT_THEME = {
|
|
103
|
-
canvasBackground: '#
|
|
103
|
+
canvasBackground: '#1E1D1D',
|
|
104
104
|
defaultItemWidth: 200,
|
|
105
105
|
defaultColor: '#ffffff',
|
|
106
106
|
fontSize: '16px',
|
|
@@ -117,8 +117,6 @@ 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
|
-
|
|
122
120
|
// Input validation
|
|
123
121
|
if (!accountId || typeof accountId !== 'string') {
|
|
124
122
|
console.warn('Invalid accountId provided:', accountId);
|
|
@@ -126,8 +124,6 @@ const checkIfUserExists = async accountId => {
|
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
try {
|
|
129
|
-
console.log('Loading schemas...');
|
|
130
|
-
// Load all required schemas in parallel
|
|
131
127
|
const schemaResults = await Promise.all([
|
|
132
128
|
ServiceManager.getService('UserSchema'),
|
|
133
129
|
ServiceManager.getService('UserStyleSchema'),
|
|
@@ -138,14 +134,6 @@ const checkIfUserExists = async accountId => {
|
|
|
138
134
|
const [userSchema, userStyleSchema, folderSchema, themeSchema] =
|
|
139
135
|
schemaResults;
|
|
140
136
|
|
|
141
|
-
// Log the status of each schema
|
|
142
|
-
console.log('Schema loading results:', {
|
|
143
|
-
userSchema: userSchema ? 'Loaded' : 'Not available',
|
|
144
|
-
userStyleSchema: userStyleSchema ? 'Loaded' : 'Not available',
|
|
145
|
-
folderSchema: folderSchema ? 'Loaded' : 'Not available',
|
|
146
|
-
themeSchema: themeSchema ? 'Loaded' : 'Not available',
|
|
147
|
-
});
|
|
148
|
-
|
|
149
137
|
if (!userSchema) {
|
|
150
138
|
throw new Error('UserSchema service not available');
|
|
151
139
|
}
|
|
@@ -167,28 +155,21 @@ const checkIfUserExists = async accountId => {
|
|
|
167
155
|
);
|
|
168
156
|
}
|
|
169
157
|
|
|
170
|
-
console.log('Schema loading and validation complete');
|
|
171
|
-
|
|
172
158
|
// Find existing user with populated fields
|
|
173
159
|
const user = await userSchema
|
|
174
160
|
.findOne({ accountId })
|
|
175
161
|
.select('-theme -folderList -userGlobalStyles -mapList')
|
|
176
162
|
.lean();
|
|
177
163
|
|
|
178
|
-
console.log('User lookup result:', user ? 'User found' : 'User not found');
|
|
179
|
-
|
|
180
164
|
if (user) {
|
|
181
|
-
console.log('Updating existing user data...');
|
|
182
165
|
const updates = [];
|
|
183
166
|
|
|
184
167
|
// Handle userGlobalStyles
|
|
185
168
|
if (userStyleSchema) {
|
|
186
169
|
if (!user.userGlobalStyles) {
|
|
187
|
-
console.log('Creating missing userGlobalStyles...');
|
|
188
170
|
updates.push(
|
|
189
171
|
createUserGlobalStyles(userStyleSchema, accountId).then(
|
|
190
172
|
async styles => {
|
|
191
|
-
console.log('UserGlobalStyles created successfully');
|
|
192
173
|
await userSchema.updateOne(
|
|
193
174
|
{ _id: user._id },
|
|
194
175
|
{ userGlobalStyles: styles._id }
|
|
@@ -209,7 +190,6 @@ const checkIfUserExists = async accountId => {
|
|
|
209
190
|
|
|
210
191
|
// Handle folders
|
|
211
192
|
if (folderSchema) {
|
|
212
|
-
console.log('Checking folders...');
|
|
213
193
|
updates.push(
|
|
214
194
|
(async () => {
|
|
215
195
|
const existingFolders = await folderSchema
|
|
@@ -217,7 +197,6 @@ const checkIfUserExists = async accountId => {
|
|
|
217
197
|
.select('name')
|
|
218
198
|
.lean();
|
|
219
199
|
|
|
220
|
-
console.log('Existing folders count:', existingFolders.length);
|
|
221
200
|
const existingFolderNames = new Set(
|
|
222
201
|
existingFolders.map(f => f.name)
|
|
223
202
|
);
|
|
@@ -239,7 +218,6 @@ const checkIfUserExists = async accountId => {
|
|
|
239
218
|
|
|
240
219
|
// Handle themes
|
|
241
220
|
if (themeSchema) {
|
|
242
|
-
console.log('Checking themes...');
|
|
243
221
|
updates.push(
|
|
244
222
|
(async () => {
|
|
245
223
|
const defaultThemeExists = await themeSchema.exists({
|
|
@@ -247,7 +225,6 @@ const checkIfUserExists = async accountId => {
|
|
|
247
225
|
accountId,
|
|
248
226
|
});
|
|
249
227
|
|
|
250
|
-
console.log('Default theme exists:', defaultThemeExists);
|
|
251
228
|
if (!defaultThemeExists) {
|
|
252
229
|
const defaultTheme = await themeSchema.create({
|
|
253
230
|
...DEFAULT_THEME,
|
|
@@ -267,9 +244,7 @@ const checkIfUserExists = async accountId => {
|
|
|
267
244
|
}
|
|
268
245
|
|
|
269
246
|
// Wait for all updates to complete
|
|
270
|
-
console.log('Waiting for all updates to complete...');
|
|
271
247
|
await Promise.all(updates);
|
|
272
|
-
console.log('All updates completed successfully');
|
|
273
248
|
|
|
274
249
|
// Return fresh user data after updates, excluding specified fields
|
|
275
250
|
return userSchema
|
|
@@ -329,7 +304,6 @@ const checkIfUserExists = async accountId => {
|
|
|
329
304
|
await createDefaultFolders(folderSchema, newUser.id);
|
|
330
305
|
}
|
|
331
306
|
|
|
332
|
-
console.log('Operation completed successfully');
|
|
333
307
|
return userSchema
|
|
334
308
|
.findById(newUser._id)
|
|
335
309
|
.select('-theme -folderList -userGlobalStyles -mapList')
|