abmp-npm 2.0.27 → 2.0.28
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.
|
@@ -124,15 +124,10 @@ async function ensureUniqueUrlsInBatch(memberDataList) {
|
|
|
124
124
|
* @param {Object} options - The options object
|
|
125
125
|
* @param {Array} options.memberDataList - Array of member data from API
|
|
126
126
|
* @param {number} options.currentPageNumber - Current page number being processed
|
|
127
|
-
* @param {boolean} [options.addInterests=true] - Whether to add interests to the member data
|
|
128
127
|
* @param {Array} memberDataList - Array of member data from API
|
|
129
128
|
* @returns {Promise<Object>} - Bulk save operation result with statistics
|
|
130
129
|
*/
|
|
131
|
-
const bulkProcessAndSaveMemberData = async ({
|
|
132
|
-
memberDataList,
|
|
133
|
-
currentPageNumber,
|
|
134
|
-
addInterests = true,
|
|
135
|
-
}) => {
|
|
130
|
+
const bulkProcessAndSaveMemberData = async ({ memberDataList, currentPageNumber }) => {
|
|
136
131
|
if (!Array.isArray(memberDataList) || memberDataList.length === 0) {
|
|
137
132
|
throw new Error('Invalid member data list provided');
|
|
138
133
|
}
|
|
@@ -144,7 +139,6 @@ const bulkProcessAndSaveMemberData = async ({
|
|
|
144
139
|
generateUpdatedMemberData({
|
|
145
140
|
inputMemberData: memberData,
|
|
146
141
|
currentPageNumber,
|
|
147
|
-
addInterests,
|
|
148
142
|
})
|
|
149
143
|
);
|
|
150
144
|
|
|
@@ -31,12 +31,9 @@ const PAC_ASSOCIATIONS = {
|
|
|
31
31
|
AHP: 'AHP',
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const SITES_WITH_INTERESTS_TO_MIGRATE = [PAC_ASSOCIATIONS.ABMP];
|
|
35
|
-
|
|
36
34
|
module.exports = {
|
|
37
35
|
MEMBER_ACTIONS,
|
|
38
36
|
ADDRESS_VISIBILITY_OPTIONS,
|
|
39
37
|
DEFAULT_MEMBER_DISPLAY_SETTINGS,
|
|
40
38
|
PAC_ASSOCIATIONS,
|
|
41
|
-
SITES_WITH_INTERESTS_TO_MIGRATE,
|
|
42
39
|
};
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
const { ADDRESS_STATUS_TYPES } = require('../../public/consts');
|
|
2
1
|
const { findMemberById, getMemberBySlug } = require('../members-data-methods');
|
|
3
2
|
const { isValidArray, generateGeoHash } = require('../utils');
|
|
4
3
|
|
|
5
|
-
const {
|
|
6
|
-
MEMBER_ACTIONS,
|
|
7
|
-
ADDRESS_VISIBILITY_OPTIONS,
|
|
8
|
-
DEFAULT_MEMBER_DISPLAY_SETTINGS,
|
|
9
|
-
} = require('./consts');
|
|
4
|
+
const { MEMBER_ACTIONS, DEFAULT_MEMBER_DISPLAY_SETTINGS } = require('./consts');
|
|
10
5
|
const { validateCoreMemberData, containsNonEnglish, createFullName } = require('./utils');
|
|
11
6
|
|
|
12
7
|
/**
|
|
@@ -62,15 +57,10 @@ const ensureUniqueUrl = async ({ url, memberId, fullName }) => {
|
|
|
62
57
|
* Generates complete updated member data by combining existing and migration data
|
|
63
58
|
* @param {Object} options - The options object
|
|
64
59
|
* @param {Object} options.inputMemberData - Raw member data from API
|
|
65
|
-
* @param {string} options.addInterests - Site association of the member
|
|
66
60
|
* @param {number} options.currentPageNumber - Current page number being processed
|
|
67
61
|
* @returns {Promise<Object|null>} - Complete updated member data or null if validation fails
|
|
68
62
|
*/
|
|
69
|
-
async function generateUpdatedMemberData({
|
|
70
|
-
inputMemberData,
|
|
71
|
-
addInterests = true,
|
|
72
|
-
currentPageNumber,
|
|
73
|
-
}) {
|
|
63
|
+
async function generateUpdatedMemberData({ inputMemberData, currentPageNumber }) {
|
|
74
64
|
if (!validateCoreMemberData(inputMemberData)) {
|
|
75
65
|
throw new Error(
|
|
76
66
|
'Invalid member data: memberid, email (valid string), and memberships (array) are required'
|
|
@@ -90,80 +80,13 @@ async function generateUpdatedMemberData({
|
|
|
90
80
|
return null;
|
|
91
81
|
}
|
|
92
82
|
|
|
93
|
-
// Only
|
|
94
|
-
if (!existingDbMember) {
|
|
95
|
-
|
|
96
|
-
memberDataToUpdate: updatedMemberData,
|
|
97
|
-
migrationData: inputMemberData.migrationData,
|
|
98
|
-
addInterests,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
enrichWithAddressData(
|
|
102
|
-
updatedMemberData,
|
|
103
|
-
inputMemberData.addresses,
|
|
104
|
-
inputMemberData.migrationData?.addressinfo
|
|
105
|
-
);
|
|
83
|
+
// Only add address data for new members
|
|
84
|
+
if (!existingDbMember && isValidArray(inputMemberData.addresses)) {
|
|
85
|
+
updatedMemberData.addresses = inputMemberData.addresses;
|
|
106
86
|
}
|
|
107
87
|
|
|
108
88
|
return { ...updatedMemberData, isNewToDb: !existingDbMember };
|
|
109
89
|
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Processes and adds address data with proper status
|
|
113
|
-
* @param {Object} memberDataToUpdate - Member data object to enhance
|
|
114
|
-
* @param {Array} addressesList - Array of address objects
|
|
115
|
-
* @param {Object} addressDisplayInfo - Address visibility configuration
|
|
116
|
-
*/
|
|
117
|
-
function enrichWithAddressData(memberDataToUpdate, addressesList, addressDisplayInfo) {
|
|
118
|
-
if (isValidArray(addressesList)) {
|
|
119
|
-
memberDataToUpdate.addresses = processAddressesWithStatus(addressesList, addressDisplayInfo);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Processes multiple addresses with their display statuses
|
|
125
|
-
* @param {Array} addressesList - Array of address objects
|
|
126
|
-
* @param {Object} displayConfiguration - Address display configuration
|
|
127
|
-
* @returns {Array} - Processed addresses with status information
|
|
128
|
-
*/
|
|
129
|
-
function processAddressesWithStatus(addressesList, displayConfiguration = {}) {
|
|
130
|
-
if (!isValidArray(addressesList)) {
|
|
131
|
-
return [];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return addressesList.map(address => {
|
|
135
|
-
const displayStatus = displayConfiguration[address.key]
|
|
136
|
-
? determineAddressDisplayStatus(displayConfiguration[address.key])
|
|
137
|
-
: ADDRESS_STATUS_TYPES.STATE_CITY_ZIP;
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
...address,
|
|
141
|
-
addressStatus: displayStatus,
|
|
142
|
-
};
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Determines address display status based on visibility settings
|
|
148
|
-
* @param {string} visibilityValue - The address visibility value from migration data
|
|
149
|
-
* @returns {string} - The corresponding address status
|
|
150
|
-
*/
|
|
151
|
-
function determineAddressDisplayStatus(visibilityValue) {
|
|
152
|
-
if (!visibilityValue) {
|
|
153
|
-
return ADDRESS_STATUS_TYPES.STATE_CITY_ZIP;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const normalizedValue = visibilityValue.trim().toLowerCase();
|
|
157
|
-
|
|
158
|
-
switch (normalizedValue) {
|
|
159
|
-
case ADDRESS_VISIBILITY_OPTIONS.ALL:
|
|
160
|
-
return ADDRESS_STATUS_TYPES.FULL_ADDRESS;
|
|
161
|
-
case ADDRESS_VISIBILITY_OPTIONS.NONE:
|
|
162
|
-
return ADDRESS_STATUS_TYPES.DONT_SHOW;
|
|
163
|
-
default:
|
|
164
|
-
return ADDRESS_STATUS_TYPES.STATE_CITY_ZIP;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
90
|
/**
|
|
168
91
|
* Helper function to get fields that should only be set for new members
|
|
169
92
|
* @param {Object} inputMemberData - Raw member data from API
|
|
@@ -191,54 +114,14 @@ async function getNewMemberOnlyFields(inputMemberData, existingDbMember) {
|
|
|
191
114
|
lastName: sanitizedLastName,
|
|
192
115
|
fullName,
|
|
193
116
|
phones: inputMemberData.phones || [],
|
|
194
|
-
|
|
195
|
-
optOut: inputMemberData.migrationData?.opted_out || false,
|
|
117
|
+
optOut: false,
|
|
196
118
|
url: uniqueUrl,
|
|
197
119
|
showContactForm: true,
|
|
198
|
-
|
|
199
|
-
? inputMemberData.migrationData?.schedule_code
|
|
200
|
-
: '',
|
|
201
|
-
APIBookingUrl: inputMemberData.migrationData?.schedule_code,
|
|
202
|
-
showABMP: inputMemberData.migrationData?.show_member_since || false,
|
|
120
|
+
showABMP: false,
|
|
203
121
|
locHash: generateGeoHash(inputMemberData.addresses || []),
|
|
204
122
|
...DEFAULT_MEMBER_DISPLAY_SETTINGS,
|
|
205
123
|
};
|
|
206
124
|
}
|
|
207
|
-
/**
|
|
208
|
-
* Enriches member data with optional migration properties
|
|
209
|
-
* @param {Object} options - The options object
|
|
210
|
-
* @param {Object} options.memberDataToUpdate - Member data object to enhance
|
|
211
|
-
* @param {Object} options.migrationData - Migration data containing optional properties
|
|
212
|
-
* @param {boolean} [options.addInterests=true] - Whether to add interests to the member data
|
|
213
|
-
* @param {Object} migrationData - Migration data containing optional properties
|
|
214
|
-
*/
|
|
215
|
-
function enrichWithMigrationData({ memberDataToUpdate, migrationData, addInterests = true }) {
|
|
216
|
-
if (!migrationData) return;
|
|
217
|
-
|
|
218
|
-
memberDataToUpdate.addressInfo = migrationData.addressinfo;
|
|
219
|
-
|
|
220
|
-
if (migrationData.website) {
|
|
221
|
-
memberDataToUpdate.website = migrationData.website;
|
|
222
|
-
memberDataToUpdate.showWebsite = true;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (addInterests && migrationData.interests) {
|
|
226
|
-
memberDataToUpdate.areasOfPractices = processInterests(migrationData.interests);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Processes interests string into clean array
|
|
231
|
-
* @param {string} interestsString - Comma-separated interests string
|
|
232
|
-
* @returns {Array} - Array of trimmed, non-empty interests
|
|
233
|
-
*/
|
|
234
|
-
function processInterests(interestsString) {
|
|
235
|
-
if (!interestsString) return [];
|
|
236
|
-
|
|
237
|
-
return interestsString
|
|
238
|
-
.split(',')
|
|
239
|
-
.map(interest => interest.trim())
|
|
240
|
-
.filter(interest => interest.length > 0);
|
|
241
|
-
}
|
|
242
125
|
/**
|
|
243
126
|
* Creates base member data structure with core properties
|
|
244
127
|
* @param {Object} inputMemberData - Raw member data from API
|
|
@@ -6,7 +6,7 @@ const { TASKS_NAMES } = require('../tasks/consts');
|
|
|
6
6
|
const { getSiteConfigs } = require('../utils');
|
|
7
7
|
|
|
8
8
|
const { bulkProcessAndSaveMemberData } = require('./bulk-process-methods');
|
|
9
|
-
const { MEMBER_ACTIONS
|
|
9
|
+
const { MEMBER_ACTIONS } = require('./consts');
|
|
10
10
|
const { isUpdatedMember, isSiteAssociatedMember } = require('./utils');
|
|
11
11
|
|
|
12
12
|
async function syncMembersDataPerAction(taskData) {
|
|
@@ -94,7 +94,6 @@ async function synchronizeSinglePage(taskObject) {
|
|
|
94
94
|
isTestEnvironment,
|
|
95
95
|
}),
|
|
96
96
|
]);
|
|
97
|
-
const addInterests = SITES_WITH_INTERESTS_TO_MIGRATE.includes(siteAssociation);
|
|
98
97
|
if (
|
|
99
98
|
!memberDataResponse ||
|
|
100
99
|
!memberDataResponse.results ||
|
|
@@ -123,7 +122,6 @@ async function synchronizeSinglePage(taskObject) {
|
|
|
123
122
|
const result = await bulkProcessAndSaveMemberData({
|
|
124
123
|
memberDataList: toSyncMembers,
|
|
125
124
|
currentPageNumber: pageNumber,
|
|
126
|
-
addInterests,
|
|
127
125
|
});
|
|
128
126
|
|
|
129
127
|
return {
|