abmp-npm 1.10.11 → 1.10.13

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.
@@ -1,7 +1,7 @@
1
1
  const { getMainAddress } = require('../../public/Utils/sharedUtils');
2
2
  const { getMemberBySlug } = require('../members-data-methods');
3
3
  const {
4
- getAddressesByStatus,
4
+ getMoreAddressesToDisplay,
5
5
  formatDateToMonthYear,
6
6
  hasStudentMembership,
7
7
  isPAC_STAFF,
@@ -48,7 +48,10 @@ function transformMemberToProfileData(member, siteAssociation) {
48
48
  ?.map(val => val.license)
49
49
  .filter(Boolean)
50
50
  .join(', ');
51
- const processedAddresses = getAddressesByStatus(member.addresses, member.addressDisplayOption);
51
+ const moreAddressesToDisplay = getMoreAddressesToDisplay(
52
+ member.addresses,
53
+ member.addressDisplayOption
54
+ );
52
55
 
53
56
  const memberships = member.memberships || [];
54
57
  const siteAssociationMembership = memberships.find(m => m.association === siteAssociation);
@@ -67,7 +70,7 @@ function transformMemberToProfileData(member, siteAssociation) {
67
70
  mainAddress,
68
71
  testimonials: member.testimonial || [],
69
72
  licenceNo,
70
- processedAddresses,
73
+ moreAddressesToDisplay,
71
74
  memberSince:
72
75
  (member.showABMP &&
73
76
  siteAssociationMembership &&
@@ -3,13 +3,14 @@ const { taskManager } = require('psdev-task-manager');
3
3
  const { COLLECTIONS } = require('../../public/consts');
4
4
  const { ensureUniqueUrl } = require('../daily-pull/process-member-methods');
5
5
  const { wixData } = require('../elevated-modules');
6
- // const { bulkSaveMembers } = require('../members-data-methods');
6
+ const { bulkSaveMembers } = require('../members-data-methods');
7
7
  const { queryAllItems, chunkArray } = require('../utils');
8
8
 
9
9
  const { TASKS_NAMES } = require('./consts');
10
10
 
11
11
  const COLLECTION_WITH_URLS = 'MembersDataWithUrls';
12
- const CHUNK_SIZE = 5000; // 5k members per task
12
+ const CHUNK_SIZE = 5000; // 5k members per task for migration
13
+ const GENERATION_CHUNK_SIZE = 1000; // 1k members per task for URL generation
13
14
 
14
15
  /**
15
16
  * Step 1: Migrate existing URLs from backup collection
@@ -83,10 +84,9 @@ async function scheduleMigrateExistingUrls() {
83
84
  */
84
85
  async function migrateUrlsChunk(data) {
85
86
  const { urlData, chunkIndex, totalChunks } = data;
86
- console.log('migrateUrlsChunk data', data);
87
- // console.log(
88
- // `Processing migration chunk ${chunkIndex + 1}/${totalChunks} (${urlData.length} members)`
89
- // );
87
+ console.log(
88
+ `Processing migration chunk ${chunkIndex + 1}/${totalChunks} (${urlData.length} members)`
89
+ );
90
90
 
91
91
  const result = {
92
92
  successful: 0,
@@ -146,8 +146,7 @@ async function migrateUrlsChunk(data) {
146
146
  );
147
147
 
148
148
  try {
149
- // keep bulk save as comment for now, since we are just testing the query and update logic
150
- // await bulkSaveMembers(membersToUpdate);
149
+ await bulkSaveMembers(membersToUpdate);
151
150
  result.successful += membersToUpdate.length;
152
151
  console.log(`✅ Successfully updated ${membersToUpdate.length} members`);
153
152
  } catch (error) {
@@ -203,7 +202,7 @@ async function scheduleGenerateMissingUrls() {
203
202
  };
204
203
  }
205
204
 
206
- const chunks = chunkArray(membersToUpdate, CHUNK_SIZE);
205
+ const chunks = chunkArray(membersToUpdate, GENERATION_CHUNK_SIZE);
207
206
 
208
207
  for (let i = 0; i < chunks.length; i++) {
209
208
  const chunk = chunks[i];
@@ -257,11 +256,25 @@ async function generateUrlsChunk(data) {
257
256
  };
258
257
 
259
258
  try {
260
- // Fetch all members at once using hasSome
261
- console.log(`Fetching ${memberIds.length} members from database...`);
262
- const members = await queryAllItems(
263
- wixData.query(COLLECTIONS.MEMBERS_DATA).hasSome('_id', memberIds)
259
+ // Fetch members in smaller batches to avoid cursor size limits
260
+ // hasSome with too many IDs creates cursors that exceed Wix's 150KB limit
261
+ const FETCH_BATCH_SIZE = 200;
262
+ console.log(
263
+ `Fetching ${memberIds.length} members from database in batches of ${FETCH_BATCH_SIZE}...`
264
264
  );
265
+
266
+ const members = [];
267
+ const idBatches = chunkArray(memberIds, FETCH_BATCH_SIZE);
268
+
269
+ for (let i = 0; i < idBatches.length; i++) {
270
+ const idBatch = idBatches[i];
271
+ const batchMembers = await queryAllItems(
272
+ wixData.query(COLLECTIONS.MEMBERS_DATA).hasSome('_id', idBatch)
273
+ );
274
+ members.push(...batchMembers);
275
+ console.log(`Fetched batch ${i + 1}/${idBatches.length}: ${batchMembers.length} members`);
276
+ }
277
+
265
278
  console.log(`Found ${members.length} members in database`);
266
279
 
267
280
  // Create a map of _id -> member for quick lookup
@@ -291,22 +304,11 @@ async function generateUrlsChunk(data) {
291
304
 
292
305
  const name = member.fullName || `${member.firstName || ''} ${member.lastName || ''}`.trim();
293
306
 
294
- if (!name) {
295
- console.error(`Member ${memberId} has no name data - skipping`);
296
- result.failed++;
297
- result.failedIds.push(memberId);
298
- result.errors.push({
299
- memberId,
300
- error: 'No name data available',
301
- });
302
- continue;
303
- }
304
-
305
307
  try {
306
308
  const uniqueUrl = await ensureUniqueUrl({
307
309
  url: '',
308
310
  memberId: member._id,
309
- fullName: name,
311
+ fullName: name || '', // Let ensureUniqueUrl handle fallback for empty names
310
312
  });
311
313
 
312
314
  console.log(`✅ Generated URL for member ${memberId}: ${uniqueUrl}`);
@@ -335,8 +337,7 @@ async function generateUrlsChunk(data) {
335
337
  );
336
338
 
337
339
  try {
338
- // keep bulk save as comment for now, since we are just testing the query and update logic
339
- // await bulkSaveMembers(membersToUpdate);
340
+ await bulkSaveMembers(membersToUpdate);
340
341
  result.successful += membersToUpdate.length;
341
342
  console.log(`✅ Successfully updated ${membersToUpdate.length} members`);
342
343
  } catch (error) {
package/backend/utils.js CHANGED
@@ -4,7 +4,7 @@ const { site } = require('@wix/urls');
4
4
  const { encode } = require('ngeohash');
5
5
 
6
6
  const { COLLECTIONS, ADDRESS_STATUS_TYPES } = require('../public/consts');
7
- const { formatAddress, generateId } = require('../public/Utils/sharedUtils');
7
+ const { formatAddress, generateId, findMainAddress } = require('../public/Utils/sharedUtils');
8
8
 
9
9
  const { CONFIG_KEYS, GEO_HASH_PRECISION, MEMBERSHIPS_TYPES } = require('./consts');
10
10
  const { wixData } = require('./elevated-modules');
@@ -91,16 +91,17 @@ function getAddressDisplayOptions(member) {
91
91
  }
92
92
  return displayOptions;
93
93
  }
94
- function getAddressesByStatus(addresses = [], addressDisplayOption = []) {
94
+ function getMoreAddressesToDisplay(addresses = [], addressDisplayOption = []) {
95
95
  const visible = addresses.filter(addr => addr.addressStatus !== ADDRESS_STATUS_TYPES.DONT_SHOW);
96
96
  if (visible.length < 2) {
97
97
  return [];
98
98
  }
99
- const opts = Array.isArray(addressDisplayOption) ? addressDisplayOption : [];
100
- const mainOpt = opts.find(o => o.isMain);
101
- const mainKey = mainOpt ? mainOpt.key : visible[0].key; // fallback to the first visible if none marked
102
- return visible
103
- .filter(addr => addr?.key !== mainKey)
99
+ const mainAddress = findMainAddress(addressDisplayOption, addresses);
100
+ const remainingAddressesToFormat = mainAddress
101
+ ? visible.filter(addr => addr?.key !== mainAddress.key)
102
+ : visible;
103
+
104
+ return remainingAddressesToFormat
104
105
  .map(addr => {
105
106
  const addressString = formatAddress(addr);
106
107
  return addressString ? { _id: generateId(), address: addressString } : null;
@@ -111,10 +112,8 @@ const getAllItems = async querySearchResult => {
111
112
  let oldResults = querySearchResult;
112
113
  console.log(`found items: ${oldResults.items.length}`);
113
114
  const allItems = oldResults.items;
114
- console.log(`total pages: ${oldResults.totalPages}`);
115
115
  while (oldResults.hasNext()) {
116
116
  oldResults = await oldResults.next();
117
- console.log(`next page: ${oldResults.currentPage}`);
118
117
  allItems.push(...oldResults.items);
119
118
  }
120
119
  console.log(`all items count : ${allItems.length}`);
@@ -216,7 +215,7 @@ module.exports = {
216
215
  getSiteBaseUrl,
217
216
  encodeXml,
218
217
  formatDateOnly,
219
- getAddressesByStatus,
218
+ getMoreAddressesToDisplay,
220
219
  isPAC_STAFF,
221
220
  searchAllItems,
222
221
  };
@@ -1,7 +1,6 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
- // eslint-disable-next-line import/no-unresolved
5
4
  const csv = require('csv-parser');
6
5
 
7
6
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abmp-npm",
3
- "version": "1.10.11",
3
+ "version": "1.10.13",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "check-cycles": "madge --circular .",
package/pages/Profile.js CHANGED
@@ -59,9 +59,9 @@ async function profileOnReady({ $w: _$w }) {
59
59
  }
60
60
 
61
61
  function setupAdditionalAddresses() {
62
- _$w('#moreAdressesRepeater').data = profileData.processedAddresses;
62
+ _$w('#moreAdressesRepeater').data = profileData.moreAddressesToDisplay;
63
63
 
64
- if (profileData.processedAddresses.length > 0) {
64
+ if (profileData.moreAddressesToDisplay.length > 0) {
65
65
  _$w('#moreLocationButton').expand();
66
66
  _$w('#addressTitle').collapse();
67
67
  }