abmp-npm 1.1.107 → 1.1.109
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.
|
@@ -9,9 +9,10 @@ const { bulkProcessAndSaveMemberData } = require('./bulk-process-methods');
|
|
|
9
9
|
const { SITES_WITH_INTERESTS_TO_MIGRATE } = require('./consts');
|
|
10
10
|
const { isUpdatedMember, isSiteAssociatedMember } = require('./utils');
|
|
11
11
|
|
|
12
|
-
async function syncMembersDataPerAction(
|
|
12
|
+
async function syncMembersDataPerAction(taskData) {
|
|
13
|
+
const { action, backupDate } = taskData;
|
|
13
14
|
try {
|
|
14
|
-
const firstPageResponse = await fetchPACMembers(1, action);
|
|
15
|
+
const firstPageResponse = await fetchPACMembers({ page: 1, action, backupDate });
|
|
15
16
|
|
|
16
17
|
if (
|
|
17
18
|
!firstPageResponse ||
|
|
@@ -48,6 +49,7 @@ async function syncMembersDataPerAction(action) {
|
|
|
48
49
|
data: {
|
|
49
50
|
pageNumber,
|
|
50
51
|
action,
|
|
52
|
+
...(backupDate ? { backupDate } : {}),
|
|
51
53
|
},
|
|
52
54
|
type: 'scheduled',
|
|
53
55
|
}));
|
|
@@ -74,11 +76,11 @@ async function syncMembersDataPerAction(action) {
|
|
|
74
76
|
* @returns {Promise<Object>} - Page synchronization result
|
|
75
77
|
*/
|
|
76
78
|
async function synchronizeSinglePage(taskObject) {
|
|
77
|
-
const { pageNumber, action } = taskObject.data;
|
|
79
|
+
const { pageNumber, action, backupDate } = taskObject.data;
|
|
78
80
|
try {
|
|
79
81
|
const [siteAssociation, memberDataResponse] = await Promise.all([
|
|
80
82
|
getSiteConfigs(CONFIG_KEYS.SITE_ASSOCIATION),
|
|
81
|
-
fetchPACMembers(pageNumber, action),
|
|
83
|
+
fetchPACMembers({ page: pageNumber, action, backupDate }),
|
|
82
84
|
]);
|
|
83
85
|
const addInterests = SITES_WITH_INTERESTS_TO_MIGRATE.includes(siteAssociation);
|
|
84
86
|
if (
|
package/backend/jobs.js
CHANGED
|
@@ -13,12 +13,18 @@ async function runScheduledTasks() {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Schedule a daily pull task for the given backup date
|
|
18
|
+
* @param {string} backupDate - Optional. The date of the backup to pull in format YYYY-MM-DD
|
|
19
|
+
* @returns {Promise<void>}
|
|
20
|
+
*/
|
|
21
|
+
async function scheduleDailyPullTask(backupDate = null) {
|
|
17
22
|
try {
|
|
18
23
|
console.log('scheduleDailyPullTask started!');
|
|
24
|
+
console.log(`backupDate: ${backupDate}`);
|
|
19
25
|
return await taskManager().schedule({
|
|
20
26
|
name: TASKS_NAMES.ScheduleDailyMembersDataSync,
|
|
21
|
-
data: {},
|
|
27
|
+
data: backupDate ? { backupDate } : {}, // keeping it like this so it would be easier to understand which task was backed up which is not while looking into CMS.
|
|
22
28
|
type: 'scheduled',
|
|
23
29
|
});
|
|
24
30
|
} catch (error) {
|
|
@@ -133,15 +133,12 @@ async function getMemberBySlug({
|
|
|
133
133
|
}
|
|
134
134
|
query = query.limit(1000);
|
|
135
135
|
const searchResult = await searchAllItems(query);
|
|
136
|
-
console.log('searchResult v2', searchResult.length);
|
|
137
136
|
const membersList = searchResult.filter(
|
|
138
137
|
item => item.url && item.url.toLowerCase().includes(slug.toLowerCase())
|
|
139
138
|
); //replacement for contains - case insensitive
|
|
140
|
-
console.log('membersList v2', membersList.length);
|
|
141
139
|
let matchingMembers = membersList.filter(
|
|
142
140
|
item => item.url && item.url.toLowerCase() === slug.toLowerCase()
|
|
143
141
|
);
|
|
144
|
-
console.log('matchingMembers v2', matchingMembers.length);
|
|
145
142
|
if (normalizeSlugForComparison) {
|
|
146
143
|
matchingMembers = membersList
|
|
147
144
|
.filter(
|
|
@@ -160,7 +157,6 @@ async function getMemberBySlug({
|
|
|
160
157
|
console.log(queryResultMsg);
|
|
161
158
|
}
|
|
162
159
|
}
|
|
163
|
-
console.log('matchingMembers v2', matchingMembers[0]);
|
|
164
160
|
return matchingMembers[0] || null;
|
|
165
161
|
} catch (error) {
|
|
166
162
|
console.error('Error getting member by slug:', error);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { PAC_API_URL } = require('./consts');
|
|
1
|
+
const { PAC_API_URL, BACKUP_API_URL } = require('./consts');
|
|
2
2
|
const { getSecret } = require('./utils');
|
|
3
3
|
|
|
4
4
|
const getHeaders = async () => {
|
|
@@ -8,8 +8,22 @@ const getHeaders = async () => {
|
|
|
8
8
|
};
|
|
9
9
|
return headers;
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {*} params
|
|
14
|
+
* @param {number} params.page - The page number to fetch
|
|
15
|
+
* @param {string} params.action - The action to fetch
|
|
16
|
+
* @param {string} [params.backupDate] - Optional. The backup date to fetch in format YYYY-MM-DD, use only to fetch from backup endpoint not from PAC endpoint.
|
|
17
|
+
* @returns {Promise<Object>} - The response from the API
|
|
18
|
+
*/
|
|
19
|
+
const fetchPACMembers = async ({ page, action, backupDate }) => {
|
|
20
|
+
const baseUrl = backupDate ? BACKUP_API_URL : PAC_API_URL;
|
|
21
|
+
const queryParams = { page, actionFilter: action };
|
|
22
|
+
if (backupDate) {
|
|
23
|
+
queryParams.date = backupDate;
|
|
24
|
+
}
|
|
25
|
+
const url = `${baseUrl}/Members?${new URLSearchParams(queryParams).toString()}`;
|
|
26
|
+
console.log(`Fetching PAC members from: ${url}`);
|
|
13
27
|
const headers = await getHeaders();
|
|
14
28
|
const fetchOptions = {
|
|
15
29
|
method: 'get',
|
|
@@ -18,14 +32,14 @@ const fetchPACMembers = async (pageNum, actionFilter) => {
|
|
|
18
32
|
const response = await fetch(url, fetchOptions);
|
|
19
33
|
const responseType = response.headers.get('content-type');
|
|
20
34
|
if (!responseType.includes('application/json')) {
|
|
21
|
-
const errorMessage = `[fetchPACMembers] got invalid responseType: ${responseType} for page ${
|
|
35
|
+
const errorMessage = `[fetchPACMembers] got invalid responseType: ${responseType} for page ${page} and actionFilter ${action}`;
|
|
22
36
|
console.error(errorMessage);
|
|
23
37
|
throw new Error(errorMessage);
|
|
24
38
|
}
|
|
25
39
|
if (response.ok) {
|
|
26
40
|
return response.json();
|
|
27
41
|
} else {
|
|
28
|
-
const errorMessage = `[fetchPACMembers] failed with status ${response.status} for page ${
|
|
42
|
+
const errorMessage = `[fetchPACMembers] failed with status ${response.status} for page ${page} and actionFilter ${action}`;
|
|
29
43
|
console.error(errorMessage);
|
|
30
44
|
throw new Error(errorMessage);
|
|
31
45
|
}
|
|
@@ -43,7 +43,7 @@ const TASKS = {
|
|
|
43
43
|
},
|
|
44
44
|
[TASKS_NAMES.ScheduleMembersDataPerAction]: {
|
|
45
45
|
name: TASKS_NAMES.ScheduleMembersDataPerAction,
|
|
46
|
-
getIdentifier: task => task.data
|
|
46
|
+
getIdentifier: task => task.data,
|
|
47
47
|
process: syncMembersDataPerAction,
|
|
48
48
|
shouldSkipCheck: () => false,
|
|
49
49
|
estimatedDurationSec: 6,
|
package/backend/utils.js
CHANGED
|
@@ -110,17 +110,17 @@ function getMoreAddressesToDisplay(addresses = [], addressDisplayOption = []) {
|
|
|
110
110
|
}
|
|
111
111
|
const getAllItems = async querySearchResult => {
|
|
112
112
|
let oldResults = querySearchResult;
|
|
113
|
-
console.log(`found items
|
|
113
|
+
console.log(`found items: ${oldResults.items.length}`);
|
|
114
114
|
const allItems = oldResults.items;
|
|
115
115
|
while (oldResults.hasNext()) {
|
|
116
116
|
oldResults = await oldResults.next();
|
|
117
117
|
allItems.push(...oldResults.items);
|
|
118
118
|
}
|
|
119
|
-
console.log(`all items count
|
|
119
|
+
console.log(`all items count : ${allItems.length}`);
|
|
120
120
|
return allItems;
|
|
121
121
|
};
|
|
122
122
|
const searchAllItems = async searchQuery => {
|
|
123
|
-
console.log('start search
|
|
123
|
+
console.log('start search');
|
|
124
124
|
const searchResults = await searchQuery.run();
|
|
125
125
|
return getAllItems(searchResults);
|
|
126
126
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abmp-npm",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.109",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"check-cycles": "madge --circular .",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"csv-parser": "^3.0.0",
|
|
51
51
|
"ngeohash": "^0.6.3",
|
|
52
52
|
"phone": "^3.1.67",
|
|
53
|
-
"psdev-task-manager": "1.1.
|
|
53
|
+
"psdev-task-manager": "1.1.9",
|
|
54
54
|
"psdev-utils": "1.1.1"
|
|
55
55
|
}
|
|
56
56
|
}
|