propro-utils 1.5.51 → 1.5.53
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 +24 -4
- package/package.json +1 -1
|
@@ -89,7 +89,6 @@ async function createDefaultFolders(folderSchema, accountId) {
|
|
|
89
89
|
const folderPromises = defaultFolders.map(folder =>
|
|
90
90
|
folderSchema.create({
|
|
91
91
|
...folder,
|
|
92
|
-
id: uuidv4(),
|
|
93
92
|
user_id: accountId,
|
|
94
93
|
})
|
|
95
94
|
);
|
|
@@ -111,6 +110,13 @@ async function createDefaultFolders(folderSchema, accountId) {
|
|
|
111
110
|
*/
|
|
112
111
|
const checkIfUserExists = async accountId => {
|
|
113
112
|
try {
|
|
113
|
+
console.log('Checking if user exists:', accountId);
|
|
114
|
+
console.log('defaultFolders', defaultFolders);
|
|
115
|
+
console.log('defaultFolders.length', defaultFolders.length);
|
|
116
|
+
console.log(
|
|
117
|
+
'defaultUserGlobalStyleShortcuts.length',
|
|
118
|
+
defaultUserGlobalStyleShortcuts.length
|
|
119
|
+
);
|
|
114
120
|
const userSchema = await ServiceManager.getService('UserSchema');
|
|
115
121
|
const userStyleSchema = await ServiceManager.getService('UserStyleSchema');
|
|
116
122
|
const folderSchema = await ServiceManager.getService('FolderSchema');
|
|
@@ -131,9 +137,23 @@ const checkIfUserExists = async accountId => {
|
|
|
131
137
|
await user.userGlobalStyles.save();
|
|
132
138
|
}
|
|
133
139
|
// Check if user has any folders
|
|
134
|
-
const userFolders = await folderSchema.find({ accountId });
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
const userFolders = await folderSchema.find({ user_id: accountId });
|
|
141
|
+
const defaultFolderNames = defaultFolders.map(folder => folder.name);
|
|
142
|
+
const userFolderNames = userFolders.map(folder => folder.name);
|
|
143
|
+
|
|
144
|
+
const foldersToCreate = defaultFolders.filter(
|
|
145
|
+
folder => !userFolderNames.includes(folder.name)
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (foldersToCreate.length > 0) {
|
|
149
|
+
await Promise.all(
|
|
150
|
+
foldersToCreate.map(folder =>
|
|
151
|
+
folderSchema.create({
|
|
152
|
+
...folder,
|
|
153
|
+
user_id: accountId,
|
|
154
|
+
})
|
|
155
|
+
)
|
|
156
|
+
);
|
|
137
157
|
}
|
|
138
158
|
return user;
|
|
139
159
|
}
|