propro-utils 1.5.51 → 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.
@@ -111,6 +111,13 @@ async function createDefaultFolders(folderSchema, accountId) {
111
111
  */
112
112
  const checkIfUserExists = async accountId => {
113
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
+ );
114
121
  const userSchema = await ServiceManager.getService('UserSchema');
115
122
  const userStyleSchema = await ServiceManager.getService('UserStyleSchema');
116
123
  const folderSchema = await ServiceManager.getService('FolderSchema');
@@ -131,9 +138,24 @@ const checkIfUserExists = async accountId => {
131
138
  await user.userGlobalStyles.save();
132
139
  }
133
140
  // Check if user has any folders
134
- const userFolders = await folderSchema.find({ accountId });
135
- if (userFolders.length === 0) {
136
- await createDefaultFolders(folderSchema, accountId);
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
+ );
137
159
  }
138
160
  return user;
139
161
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.5.51",
3
+ "version": "1.5.52",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {