abmp-npm 1.8.32 → 1.8.34
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/backend/consts.js +0 -13
- package/backend/contacts-methods.js +5 -7
- package/backend/members-data-methods.js +38 -3
- package/backend/utils.js +1 -29
- package/package.json +1 -1
package/backend/consts.js
CHANGED
|
@@ -11,18 +11,6 @@ const CONFIG_KEYS = {
|
|
|
11
11
|
const MAX__MEMBERS_SEARCH_RESULTS = 120;
|
|
12
12
|
const WIX_QUERY_MAX_LIMIT = 1000;
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Member action types
|
|
16
|
-
* @readonly
|
|
17
|
-
* @enum {string}
|
|
18
|
-
*/
|
|
19
|
-
const MEMBER_ACTIONS = {
|
|
20
|
-
UPDATE: 'update',
|
|
21
|
-
NEW: 'new',
|
|
22
|
-
DROP: 'drop',
|
|
23
|
-
NONE: 'none',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
14
|
const TASKS_NAMES = {
|
|
27
15
|
ScheduleDailyMembersDataSync: 'ScheduleDailyMembersDataSync',
|
|
28
16
|
ScheduleMembersDataPerAction: 'ScheduleMembersDataPerAction',
|
|
@@ -35,7 +23,6 @@ module.exports = {
|
|
|
35
23
|
CONFIG_KEYS,
|
|
36
24
|
MAX__MEMBERS_SEARCH_RESULTS,
|
|
37
25
|
WIX_QUERY_MAX_LIMIT,
|
|
38
|
-
MEMBER_ACTIONS,
|
|
39
26
|
TASKS_NAMES,
|
|
40
27
|
GEO_HASH_PRECISION,
|
|
41
28
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const { contacts } = require('@wix/crm');
|
|
2
2
|
const { auth } = require('@wix/essentials');
|
|
3
|
+
|
|
3
4
|
const elevatedGetContact = auth.elevate(contacts.getContact);
|
|
4
5
|
const elevatedUpdateContact = auth.elevate(contacts.updateContact);
|
|
5
6
|
|
|
6
|
-
const { findMemberByWixDataId } = require('./members-data-methods');
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Generic contact update helper function
|
|
10
9
|
* @param {string} contactId - The contact ID in Wix CRM
|
|
@@ -94,12 +93,11 @@ const updateIfChanged = (existingValues, newValues, updater, argsBuilder) => {
|
|
|
94
93
|
|
|
95
94
|
/**
|
|
96
95
|
* Updates member contact information in CRM if fields have changed
|
|
97
|
-
* @param {string} id - Member ID
|
|
98
96
|
* @param {Object} data - New member data
|
|
97
|
+
* @param {Object} existingMemberData - Existing member data
|
|
99
98
|
*/
|
|
100
|
-
const updateMemberContactInfo = async (
|
|
101
|
-
const
|
|
102
|
-
const { contactId } = existing;
|
|
99
|
+
const updateMemberContactInfo = async (data, existingMemberData) => {
|
|
100
|
+
const { contactId } = existingMemberData;
|
|
103
101
|
|
|
104
102
|
const updateConfig = [
|
|
105
103
|
{
|
|
@@ -116,7 +114,7 @@ const updateMemberContactInfo = async (id, data) => {
|
|
|
116
114
|
|
|
117
115
|
const updatePromises = updateConfig
|
|
118
116
|
.map(({ fields, updater, args }) => {
|
|
119
|
-
const existingValues = fields.map(field =>
|
|
117
|
+
const existingValues = fields.map(field => existingMemberData[field]);
|
|
120
118
|
const newValues = fields.map(field => data[field]);
|
|
121
119
|
return updateIfChanged(existingValues, newValues, updater, args);
|
|
122
120
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { COLLECTIONS } = require('../public/consts');
|
|
2
2
|
|
|
3
|
-
const { MEMBER_ACTIONS } = require('./consts');
|
|
4
3
|
const { updateMemberContactInfo } = require('./contacts-methods');
|
|
4
|
+
const { MEMBER_ACTIONS } = require('./daily-pull');
|
|
5
5
|
const { wixData } = require('./elevated-modules');
|
|
6
6
|
const { createSiteMember, getCurrentMember } = require('./members-area-methods');
|
|
7
7
|
const {
|
|
@@ -11,9 +11,9 @@ const {
|
|
|
11
11
|
formatDateToMonthYear,
|
|
12
12
|
getAddressDisplayOptions,
|
|
13
13
|
isStudent,
|
|
14
|
-
urlExists,
|
|
15
14
|
generateGeoHash,
|
|
16
15
|
} = require('./utils');
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Retrieves member data by member ID
|
|
19
19
|
* @param {string} memberId - The member ID to search for
|
|
@@ -267,7 +267,9 @@ async function saveRegistrationData(data, id) {
|
|
|
267
267
|
data.locHash = generateGeoHash(data.addresses);
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
await
|
|
270
|
+
const existingMemberData = await findMemberByWixDataId(id);
|
|
271
|
+
|
|
272
|
+
await updateMemberContactInfo(data, existingMemberData);
|
|
271
273
|
|
|
272
274
|
const saveData = await wixData.update(COLLECTIONS.MEMBERS_DATA, data);
|
|
273
275
|
return {
|
|
@@ -283,6 +285,39 @@ async function saveRegistrationData(data, id) {
|
|
|
283
285
|
}
|
|
284
286
|
}
|
|
285
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Checks if a URL already exists in the database for a different member (case-insensitive)
|
|
290
|
+
* @param {string} url - The URL to check
|
|
291
|
+
* @param {string|number} excludeMemberId - Member ID to exclude from the check
|
|
292
|
+
* @returns {Promise<boolean>} - True if URL exists for another member
|
|
293
|
+
*/
|
|
294
|
+
async function urlExists(url, excludeMemberId) {
|
|
295
|
+
if (!url) return false;
|
|
296
|
+
|
|
297
|
+
try {
|
|
298
|
+
let query = wixData
|
|
299
|
+
.query(COLLECTIONS.MEMBERS_DATA)
|
|
300
|
+
.contains('url', url)
|
|
301
|
+
.ne('action', MEMBER_ACTIONS.DROP);
|
|
302
|
+
|
|
303
|
+
if (excludeMemberId) {
|
|
304
|
+
query = query.ne('memberId', excludeMemberId);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const { items } = await query.find();
|
|
308
|
+
|
|
309
|
+
// Case-insensitive comparison
|
|
310
|
+
const matchingMembers = items.filter(
|
|
311
|
+
item => item.url && item.url.toLowerCase() === url.toLowerCase()
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
return matchingMembers.length > 0;
|
|
315
|
+
} catch (error) {
|
|
316
|
+
console.error('Error checking URL existence:', error);
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
286
321
|
module.exports = {
|
|
287
322
|
findMemberByWixDataId,
|
|
288
323
|
createContactAndMemberIfNew,
|
package/backend/utils.js
CHANGED
|
@@ -4,6 +4,7 @@ const { COLLECTIONS } = require('../public/consts');
|
|
|
4
4
|
|
|
5
5
|
const { CONFIG_KEYS, GEO_HASH_PRECISION } = require('./consts');
|
|
6
6
|
const { wixData } = require('./elevated-modules');
|
|
7
|
+
const { urlExists } = require('./members-data-methods');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Retrieves site configuration values from the database
|
|
@@ -81,35 +82,6 @@ function getAddressDisplayOptions(member) {
|
|
|
81
82
|
return displayOptions;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
/**
|
|
85
|
-
* Checks if a URL already exists in the database for a different member (case-insensitive)
|
|
86
|
-
* @param {string} url - The URL to check
|
|
87
|
-
* @param {string|number} excludeMemberId - Member ID to exclude from the check
|
|
88
|
-
* @returns {Promise<boolean>} - True if URL exists for another member
|
|
89
|
-
*/
|
|
90
|
-
async function urlExists(url, excludeMemberId) {
|
|
91
|
-
if (!url) return false;
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
let query = wixData.query(COLLECTIONS.MEMBERS_DATA).contains('url', url).ne('action', 'drop');
|
|
95
|
-
|
|
96
|
-
if (excludeMemberId) {
|
|
97
|
-
query = query.ne('memberId', excludeMemberId);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const { items } = await query.find();
|
|
101
|
-
|
|
102
|
-
// Case-insensitive comparison
|
|
103
|
-
const matchingMembers = items.filter(
|
|
104
|
-
item => item.url && item.url.toLowerCase() === url.toLowerCase()
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
return matchingMembers.length > 0;
|
|
108
|
-
} catch (error) {
|
|
109
|
-
console.error('Error checking URL existence:', error);
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
85
|
const queryAllItems = async query => {
|
|
114
86
|
console.log('start query');
|
|
115
87
|
let oldResults = await query.find();
|