propro-utils 1.5.53 → 1.5.54

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.
@@ -68,9 +68,8 @@ const getAccountProfile = async (redisClient, userSchema, accountId) => {
68
68
  * @param {string} accountId - The account ID of the user.
69
69
  * @returns {Promise<Object>} A promise that resolves to the created user global styles object.
70
70
  */
71
- async function createUserGlobalStyles(userStyleSchema, accountId) {
71
+ async function createUserGlobalStyles(userStyleSchema) {
72
72
  return await userStyleSchema.create({
73
- accountId,
74
73
  id: uuidv4(),
75
74
  styleShortcuts: defaultUserGlobalStyleShortcuts,
76
75
  });
@@ -110,13 +109,6 @@ async function createDefaultFolders(folderSchema, accountId) {
110
109
  */
111
110
  const checkIfUserExists = async accountId => {
112
111
  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
- );
120
112
  const userSchema = await ServiceManager.getService('UserSchema');
121
113
  const userStyleSchema = await ServiceManager.getService('UserStyleSchema');
122
114
  const folderSchema = await ServiceManager.getService('FolderSchema');
@@ -127,17 +119,14 @@ const checkIfUserExists = async accountId => {
127
119
 
128
120
  if (user) {
129
121
  if (!user.userGlobalStyles) {
130
- user.userGlobalStyles = await createUserGlobalStyles(
131
- userStyleSchema,
132
- accountId
133
- );
122
+ user.userGlobalStyles = await createUserGlobalStyles(userStyleSchema);
134
123
  await user.save();
135
124
  } else if (user.userGlobalStyles.styleShortcuts.length === 0) {
136
125
  user.userGlobalStyles.styleShortcuts = defaultUserGlobalStyleShortcuts;
137
126
  await user.userGlobalStyles.save();
138
127
  }
139
128
  // Check if user has any folders
140
- const userFolders = await folderSchema.find({ user_id: accountId });
129
+ const userFolders = await folderSchema.find({ user_id: user.id });
141
130
  const defaultFolderNames = defaultFolders.map(folder => folder.name);
142
131
  const userFolderNames = userFolders.map(folder => folder.name);
143
132
 
@@ -150,18 +139,16 @@ const checkIfUserExists = async accountId => {
150
139
  foldersToCreate.map(folder =>
151
140
  folderSchema.create({
152
141
  ...folder,
153
- user_id: accountId,
142
+ user_id: user.id,
154
143
  })
155
144
  )
156
145
  );
157
146
  }
147
+
158
148
  return user;
159
149
  }
160
150
 
161
- const userGlobalStyles = await createUserGlobalStyles(
162
- userStyleSchema,
163
- accountId
164
- );
151
+ const userGlobalStyles = await createUserGlobalStyles(userStyleSchema);
165
152
 
166
153
  user = await userSchema.create({
167
154
  accountId,
@@ -170,7 +157,7 @@ const checkIfUserExists = async accountId => {
170
157
  userGlobalStyles: userGlobalStyles._id,
171
158
  });
172
159
 
173
- const folders = await createDefaultFolders(folderSchema, accountId);
160
+ const folders = await createDefaultFolders(folderSchema, user.id);
174
161
  console.log('Folders created:', folders);
175
162
  user.folders = folders.map(folder => folder._id);
176
163
  await user.save();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.5.53",
3
+ "version": "1.5.54",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {