propro-utils 1.5.52 → 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.
- package/middlewares/account_info.js +7 -22
- package/package.json +1 -1
|
@@ -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
|
|
71
|
+
async function createUserGlobalStyles(userStyleSchema) {
|
|
72
72
|
return await userStyleSchema.create({
|
|
73
|
-
accountId,
|
|
74
73
|
id: uuidv4(),
|
|
75
74
|
styleShortcuts: defaultUserGlobalStyleShortcuts,
|
|
76
75
|
});
|
|
@@ -89,7 +88,6 @@ async function createDefaultFolders(folderSchema, accountId) {
|
|
|
89
88
|
const folderPromises = defaultFolders.map(folder =>
|
|
90
89
|
folderSchema.create({
|
|
91
90
|
...folder,
|
|
92
|
-
id: uuidv4(),
|
|
93
91
|
user_id: accountId,
|
|
94
92
|
})
|
|
95
93
|
);
|
|
@@ -111,13 +109,6 @@ async function createDefaultFolders(folderSchema, accountId) {
|
|
|
111
109
|
*/
|
|
112
110
|
const checkIfUserExists = async accountId => {
|
|
113
111
|
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
|
-
);
|
|
121
112
|
const userSchema = await ServiceManager.getService('UserSchema');
|
|
122
113
|
const userStyleSchema = await ServiceManager.getService('UserStyleSchema');
|
|
123
114
|
const folderSchema = await ServiceManager.getService('FolderSchema');
|
|
@@ -128,17 +119,14 @@ const checkIfUserExists = async accountId => {
|
|
|
128
119
|
|
|
129
120
|
if (user) {
|
|
130
121
|
if (!user.userGlobalStyles) {
|
|
131
|
-
user.userGlobalStyles = await createUserGlobalStyles(
|
|
132
|
-
userStyleSchema,
|
|
133
|
-
accountId
|
|
134
|
-
);
|
|
122
|
+
user.userGlobalStyles = await createUserGlobalStyles(userStyleSchema);
|
|
135
123
|
await user.save();
|
|
136
124
|
} else if (user.userGlobalStyles.styleShortcuts.length === 0) {
|
|
137
125
|
user.userGlobalStyles.styleShortcuts = defaultUserGlobalStyleShortcuts;
|
|
138
126
|
await user.userGlobalStyles.save();
|
|
139
127
|
}
|
|
140
128
|
// Check if user has any folders
|
|
141
|
-
const userFolders = await folderSchema.find({ user_id:
|
|
129
|
+
const userFolders = await folderSchema.find({ user_id: user.id });
|
|
142
130
|
const defaultFolderNames = defaultFolders.map(folder => folder.name);
|
|
143
131
|
const userFolderNames = userFolders.map(folder => folder.name);
|
|
144
132
|
|
|
@@ -151,19 +139,16 @@ const checkIfUserExists = async accountId => {
|
|
|
151
139
|
foldersToCreate.map(folder =>
|
|
152
140
|
folderSchema.create({
|
|
153
141
|
...folder,
|
|
154
|
-
|
|
155
|
-
user_id: accountId,
|
|
142
|
+
user_id: user.id,
|
|
156
143
|
})
|
|
157
144
|
)
|
|
158
145
|
);
|
|
159
146
|
}
|
|
147
|
+
|
|
160
148
|
return user;
|
|
161
149
|
}
|
|
162
150
|
|
|
163
|
-
const userGlobalStyles = await createUserGlobalStyles(
|
|
164
|
-
userStyleSchema,
|
|
165
|
-
accountId
|
|
166
|
-
);
|
|
151
|
+
const userGlobalStyles = await createUserGlobalStyles(userStyleSchema);
|
|
167
152
|
|
|
168
153
|
user = await userSchema.create({
|
|
169
154
|
accountId,
|
|
@@ -172,7 +157,7 @@ const checkIfUserExists = async accountId => {
|
|
|
172
157
|
userGlobalStyles: userGlobalStyles._id,
|
|
173
158
|
});
|
|
174
159
|
|
|
175
|
-
const folders = await createDefaultFolders(folderSchema,
|
|
160
|
+
const folders = await createDefaultFolders(folderSchema, user.id);
|
|
176
161
|
console.log('Folders created:', folders);
|
|
177
162
|
user.folders = folders.map(folder => folder._id);
|
|
178
163
|
await user.save();
|