propro-utils 1.5.50 → 1.5.52
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 +39 -11
- package/package.json +1 -1
|
@@ -84,14 +84,20 @@ async function createUserGlobalStyles(userStyleSchema, accountId) {
|
|
|
84
84
|
* @returns {Promise<Array>} A promise that resolves to an array of created folder objects.
|
|
85
85
|
*/
|
|
86
86
|
async function createDefaultFolders(folderSchema, accountId) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
try {
|
|
88
|
+
console.log('Creating default folders for user:', accountId);
|
|
89
|
+
const folderPromises = defaultFolders.map(folder =>
|
|
90
|
+
folderSchema.create({
|
|
91
|
+
...folder,
|
|
92
|
+
id: uuidv4(),
|
|
93
|
+
user_id: accountId,
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
return Promise.all(folderPromises);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error('Error in createDefaultFolders:', error);
|
|
99
|
+
throw new Error('Failed to create default folders');
|
|
100
|
+
}
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
/**
|
|
@@ -105,6 +111,13 @@ async function createDefaultFolders(folderSchema, accountId) {
|
|
|
105
111
|
*/
|
|
106
112
|
const checkIfUserExists = async accountId => {
|
|
107
113
|
try {
|
|
114
|
+
console.log('Checking if user exists:', accountId);
|
|
115
|
+
console.log('defaultFolders', defaultFolders);
|
|
116
|
+
console.log('defaultFolders.length', defaultFolders.length);
|
|
117
|
+
console.log(
|
|
118
|
+
'defaultUserGlobalStyleShortcuts.length',
|
|
119
|
+
defaultUserGlobalStyleShortcuts.length
|
|
120
|
+
);
|
|
108
121
|
const userSchema = await ServiceManager.getService('UserSchema');
|
|
109
122
|
const userStyleSchema = await ServiceManager.getService('UserStyleSchema');
|
|
110
123
|
const folderSchema = await ServiceManager.getService('FolderSchema');
|
|
@@ -125,9 +138,24 @@ const checkIfUserExists = async accountId => {
|
|
|
125
138
|
await user.userGlobalStyles.save();
|
|
126
139
|
}
|
|
127
140
|
// Check if user has any folders
|
|
128
|
-
const userFolders = await folderSchema.find({ accountId });
|
|
129
|
-
|
|
130
|
-
|
|
141
|
+
const userFolders = await folderSchema.find({ user_id: accountId });
|
|
142
|
+
const defaultFolderNames = defaultFolders.map(folder => folder.name);
|
|
143
|
+
const userFolderNames = userFolders.map(folder => folder.name);
|
|
144
|
+
|
|
145
|
+
const foldersToCreate = defaultFolders.filter(
|
|
146
|
+
folder => !userFolderNames.includes(folder.name)
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
if (foldersToCreate.length > 0) {
|
|
150
|
+
await Promise.all(
|
|
151
|
+
foldersToCreate.map(folder =>
|
|
152
|
+
folderSchema.create({
|
|
153
|
+
...folder,
|
|
154
|
+
id: uuidv4(),
|
|
155
|
+
user_id: accountId,
|
|
156
|
+
})
|
|
157
|
+
)
|
|
158
|
+
);
|
|
131
159
|
}
|
|
132
160
|
return user;
|
|
133
161
|
}
|