@plusscommunities/pluss-core-aws 2.0.24 → 2.0.25-beta.0
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/aws/getDefaultEmailAddress.js +21 -21
- package/aws/getEmailService.js +16 -16
- package/aws/getEmailServiceInfo.js +26 -26
- package/aws/sendEmail.js +31 -31
- package/config.js +1 -1
- package/db/activity/publishActivity.js +22 -22
- package/db/analytics/checkActivityExists.js +15 -15
- package/db/analytics/logAnalyticsActivity.js +69 -37
- package/db/analytics/scheduleOldAggregation.js +14 -14
- package/db/auth/getSiteSetting.js +12 -12
- package/db/auth/getSiteUserTypes.js +16 -16
- package/db/auth/getUserAuth.js +13 -13
- package/db/automatedactions/getActionBySiteTrigger.js +9 -9
- package/db/common/deleteRef.js +21 -21
- package/db/common/editRef.js +36 -36
- package/db/common/getRef.js +23 -23
- package/db/common/getTableCount.js +18 -18
- package/db/common/indexQuery.js +17 -17
- package/db/common/indexQueryRecursive.js +20 -20
- package/db/common/scanRef.js +18 -18
- package/db/common/scanRefRecursive.js +20 -20
- package/db/common/updateAttribute.js +27 -27
- package/db/common/updateRef.js +20 -20
- package/db/linkedUsers/getLinkedBy.js +21 -21
- package/db/linkedUsers/getLinkedTo.js +21 -21
- package/db/notifications/deleteNotificationsByEntity.js +21 -21
- package/db/notifications/getNotificationSetting.js +14 -14
- package/db/notifications/publishNotifications.js +39 -39
- package/db/scheduledActions/deleteActionQueue.js +1 -1
- package/db/scheduledActions/getActionQueueByEntityId.js +10 -10
- package/db/scheduledActions/getActionQueueByEntityKey.js +9 -9
- package/db/scheduledActions/getActionQueueById.js +9 -9
- package/db/scheduledActions/getActionQueueByTriggerAt.js +14 -14
- package/db/scheduledActions/updateActionQueue.js +29 -29
- package/db/strings/getString.js +20 -20
- package/db/strings/logUpdate.js +18 -18
- package/db/templates/getTemplateById.js +1 -1
- package/db/templates/getTemplatesList.js +10 -10
- package/db/templates/updateTemplate.js +9 -9
- package/db/users/getRole.js +1 -1
- package/db/users/getUser.js +9 -9
- package/db/users/getUserByEmail.js +17 -17
- package/helper/audience/filterByAudienceType.js +27 -27
- package/helper/audience/filterOnAudienceType.js +26 -26
- package/helper/audience/getAudience.js +187 -187
- package/helper/audience/getMatchingAudienceTypes.js +21 -21
- package/helper/audience/getMatchingAudienceTypesFromPreview.js +60 -60
- package/helper/audience/getMatchingTags.js +15 -15
- package/helper/audience/isValidAudience.js +20 -20
- package/helper/auth/checkTokenBlacklist.js +17 -17
- package/helper/auth/getApiKeyFromReq.js +2 -2
- package/helper/auth/getSessionUser.js +66 -66
- package/helper/auth/getSessionUserFromReq.js +2 -2
- package/helper/auth/getSessionUserFromReqAuthKey.js +11 -11
- package/helper/auth/validateApiKey.js +32 -32
- package/helper/auth/validateMasterAuth.js +174 -174
- package/helper/auth/validateSiteAccess.js +12 -12
- package/helper/auth/validateSiteSetting.js +7 -7
- package/helper/auth/validateUserLoggedIn.js +19 -19
- package/helper/createGuid.js +5 -5
- package/helper/generateJsonResponse.js +27 -27
- package/helper/getUserPreview.js +57 -57
- package/helper/getUserPreviewFromHeader.js +17 -17
- package/helper/getUserPreviewFromReq.js +17 -17
- package/helper/hqPublishing.js +45 -0
- package/helper/index.js +28 -28
- package/helper/notifySiteConfigs.js +67 -52
- package/helper/opengraph/getOpenGraph.js +12 -12
- package/helper/rates/checkRateLimit.js +38 -38
- package/helper/requestToSource.js +10 -10
- package/helper/sendEmail.js +120 -120
- package/helper/templates/replacePlaceHolders.js +29 -29
- package/helper/time/getLocalTimestamp.js +18 -18
- package/helper/time/getSiteTimezone.js +11 -11
- package/helper/triggerAutomatedAction.js +25 -25
- package/helper/userToUserPreview.js +23 -23
- package/helper/users/getUserTypesByPermission.js +24 -24
- package/helper/users/getUsersByPermission.js +20 -20
- package/notification/prepNotification.js +144 -144
- package/notification/sendNotifications.js +166 -166
- package/package.json +35 -35
- package/templates/supportTicketEmails.js +8 -8
|
@@ -6,146 +6,146 @@ const userToUserPreview = require("../userToUserPreview");
|
|
|
6
6
|
const { getRowId, log } = require("..");
|
|
7
7
|
|
|
8
8
|
const getUsers = async (site) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
if (site === "all") {
|
|
10
|
+
return await scanRefRecursive("roles");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const query = {
|
|
14
|
+
IndexName: "RoleSiteTypeIndex",
|
|
15
|
+
KeyConditionExpression: "site = :site",
|
|
16
|
+
ExpressionAttributeValues: {
|
|
17
|
+
":site": site,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const { Items } = await indexQuery("roles", query);
|
|
22
|
+
return Items;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const getTypes = async (site) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
if (site === "all") {
|
|
27
|
+
return await scanRefRecursive("usertypes");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const query = {
|
|
31
|
+
IndexName: "UserTypesSiteIndex",
|
|
32
|
+
KeyConditionExpression: "site = :site",
|
|
33
|
+
ExpressionAttributeValues: {
|
|
34
|
+
":site": site,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const { Items } = await indexQuery("usertypes", query);
|
|
39
|
+
return Items;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
const getUserTags = async (site) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
const query = {
|
|
44
|
+
IndexName: "SiteIndex",
|
|
45
|
+
KeyConditionExpression: "Site = :site",
|
|
46
|
+
ExpressionAttributeValues: {
|
|
47
|
+
":site": site,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const { Items } = await indexQuery("usertagusers", query);
|
|
52
|
+
return Items;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
const getCategoryMatches = async (users, audienceTypeSelection, site) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
56
|
+
const allTypes = await getTypes(site);
|
|
57
|
+
let validCategoryTypes;
|
|
58
|
+
if (Array.isArray(audienceTypeSelection)) {
|
|
59
|
+
validCategoryTypes = _.filter(allTypes, (t) =>
|
|
60
|
+
_.some(
|
|
61
|
+
audienceTypeSelection,
|
|
62
|
+
(at) =>
|
|
63
|
+
at.AudienceType === "Category" &&
|
|
64
|
+
at.AudienceTypeSelection === t.category,
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
} else {
|
|
68
|
+
validCategoryTypes = _.filter(
|
|
69
|
+
allTypes,
|
|
70
|
+
(t) => t.category === audienceTypeSelection,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return _.filter(users, (u) =>
|
|
75
|
+
_.some(
|
|
76
|
+
validCategoryTypes,
|
|
77
|
+
(t) => t.site === u.site && t.typeName === u.type,
|
|
78
|
+
),
|
|
79
|
+
);
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
const getTypeMatches = (users, audienceTypeSelection) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
if (Array.isArray(audienceTypeSelection)) {
|
|
84
|
+
return _.filter(users, (u) =>
|
|
85
|
+
_.some(
|
|
86
|
+
audienceTypeSelection,
|
|
87
|
+
(at) =>
|
|
88
|
+
at.AudienceType === "UserType" && at.AudienceTypeSelection === u.type,
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return _.filter(users, (u) => u.type === audienceTypeSelection);
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
const getTagMatches = async (users, audienceTypeSelection, site) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
96
|
+
const allTags = await getUserTags(site);
|
|
97
|
+
const validTags = _.filter(allTags, (t) =>
|
|
98
|
+
_.some(
|
|
99
|
+
audienceTypeSelection,
|
|
100
|
+
(at) =>
|
|
101
|
+
at.AudienceType === "UserTags" && at.AudienceTypeSelection === t.TagId,
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
return _.filter(users, (u) =>
|
|
106
|
+
_.some(validTags, (t) => t.Site === u.site && t.UserId === u.id),
|
|
107
|
+
);
|
|
108
108
|
};
|
|
109
109
|
|
|
110
110
|
const getEventMatches = async (users, audienceTypeSelection) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
111
|
+
const logId = log("getEventMatches", "input", {
|
|
112
|
+
usersLength: users.length,
|
|
113
|
+
audienceTypeSelection,
|
|
114
|
+
});
|
|
115
|
+
let eventAudiences = [];
|
|
116
|
+
if (Array.isArray(audienceTypeSelection)) {
|
|
117
|
+
eventAudiences = _.filter(
|
|
118
|
+
audienceTypeSelection,
|
|
119
|
+
(at) => at.AudienceType === "EventAudience",
|
|
120
|
+
);
|
|
121
|
+
} else {
|
|
122
|
+
eventAudiences.push({ AudienceTypeSelection: audienceTypeSelection });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let userIds = [];
|
|
126
|
+
|
|
127
|
+
for (let i = 0; i < eventAudiences.length; i++) {
|
|
128
|
+
log("getEventMatches", "MatchingEventAudience", eventAudiences[i], logId);
|
|
129
|
+
const eventRep = await getRef(
|
|
130
|
+
"eventreps",
|
|
131
|
+
"RowId",
|
|
132
|
+
getRowId(
|
|
133
|
+
eventAudiences[i].AudienceTypeSelection.RowId,
|
|
134
|
+
eventAudiences[i].AudienceTypeSelection.RepId,
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
if (eventRep && eventRep.Attendees) {
|
|
138
|
+
userIds = _.concat(userIds, Object.keys(eventRep.Attendees));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
log("getEventMatches", "userIdsLength", userIds.length, logId);
|
|
142
|
+
}
|
|
143
|
+
return _.filter(users, (u) => {
|
|
144
|
+
log("getEventMatches", "userId", u.id, logId);
|
|
145
|
+
log("getEventMatches", "containsUserId", _.includes(userIds, u.id), logId);
|
|
146
|
+
|
|
147
|
+
return _.includes(userIds, u.id);
|
|
148
|
+
});
|
|
149
149
|
};
|
|
150
150
|
|
|
151
151
|
/**
|
|
@@ -160,70 +160,70 @@ const getEventMatches = async (users, audienceTypeSelection) => {
|
|
|
160
160
|
* @returns {Array} - The audience that matches the specified criteria.
|
|
161
161
|
*/
|
|
162
162
|
module.exports = async (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
site,
|
|
164
|
+
audienceType,
|
|
165
|
+
audienceTypeSelection,
|
|
166
|
+
preview = true,
|
|
167
|
+
includeType = true,
|
|
168
|
+
includeSite = true,
|
|
169
169
|
) => {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
170
|
+
//TODO handle includes and excludes
|
|
171
|
+
const userData = await getUsers(site);
|
|
172
|
+
const users = _.map(
|
|
173
|
+
_.filter(userData, (u) => !u.Deleted),
|
|
174
|
+
(u) => {
|
|
175
|
+
return preview
|
|
176
|
+
? userToUserPreview(u, true, true)
|
|
177
|
+
: { id: u.Id || u.userId, ...u };
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
let result = users;
|
|
181
|
+
if (audienceType) {
|
|
182
|
+
switch (audienceType) {
|
|
183
|
+
case "All":
|
|
184
|
+
break;
|
|
185
|
+
case "Custom":
|
|
186
|
+
const categoryMatches = await getCategoryMatches(
|
|
187
|
+
users,
|
|
188
|
+
audienceTypeSelection,
|
|
189
|
+
site,
|
|
190
|
+
);
|
|
191
|
+
const typeMatches = getTypeMatches(users, audienceTypeSelection);
|
|
192
|
+
const tagMatches = await getTagMatches(
|
|
193
|
+
users,
|
|
194
|
+
audienceTypeSelection,
|
|
195
|
+
site,
|
|
196
|
+
);
|
|
197
|
+
const eventMatches = await getEventMatches(
|
|
198
|
+
users,
|
|
199
|
+
audienceTypeSelection,
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
// console.log("categoryMatches", categoryMatches);
|
|
203
|
+
// console.log("typeMatches", typeMatches);
|
|
204
|
+
// console.log("tagMatches", tagMatches);
|
|
205
|
+
result = _.unionBy(
|
|
206
|
+
categoryMatches,
|
|
207
|
+
typeMatches,
|
|
208
|
+
tagMatches,
|
|
209
|
+
eventMatches,
|
|
210
|
+
"id",
|
|
211
|
+
);
|
|
212
|
+
break;
|
|
213
|
+
case "EventAudience":
|
|
214
|
+
result = await getEventMatches(users, audienceTypeSelection);
|
|
215
|
+
break;
|
|
216
|
+
case "Category":
|
|
217
|
+
result = await getCategoryMatches(users, audienceTypeSelection, site);
|
|
218
|
+
break;
|
|
219
|
+
case "UserType":
|
|
220
|
+
result = getTypeMatches(users, audienceTypeSelection);
|
|
221
|
+
break;
|
|
222
|
+
default:
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return result.map((user) => {
|
|
227
|
+
return userToUserPreview(user, includeType, includeSite);
|
|
228
|
+
});
|
|
229
229
|
};
|
|
@@ -3,25 +3,25 @@ const getSessionUser = require("../auth/getSessionUser");
|
|
|
3
3
|
const getMatchingAudienceTypesFromPreview = require("./getMatchingAudienceTypesFromPreview");
|
|
4
4
|
|
|
5
5
|
module.exports = (authkey) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
getSessionUser(authkey)
|
|
8
|
+
.then((uid) => {
|
|
9
|
+
getUserPreview(uid, true, true)
|
|
10
|
+
.then((user) => {
|
|
11
|
+
getMatchingAudienceTypesFromPreview(user)
|
|
12
|
+
.then((result) => {
|
|
13
|
+
resolve(result);
|
|
14
|
+
})
|
|
15
|
+
.catch((err) => {
|
|
16
|
+
reject(err);
|
|
17
|
+
});
|
|
18
|
+
})
|
|
19
|
+
.catch((err) => {
|
|
20
|
+
reject(err);
|
|
21
|
+
});
|
|
22
|
+
})
|
|
23
|
+
.catch((err) => {
|
|
24
|
+
reject(err);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
27
|
};
|
|
@@ -2,67 +2,67 @@ const _ = require("lodash");
|
|
|
2
2
|
const indexQuery = require("../../db/common/indexQuery");
|
|
3
3
|
|
|
4
4
|
const handleRole = (results, role) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
results.push({
|
|
7
|
+
type: "All",
|
|
8
|
+
site: role.site,
|
|
9
|
+
});
|
|
10
|
+
const typeQuery = {
|
|
11
|
+
IndexName: "UserTypesSiteIndex",
|
|
12
|
+
KeyConditionExpression: "site = :site",
|
|
13
|
+
ExpressionAttributeValues: {
|
|
14
|
+
":site": role.site,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
indexQuery("usertypes", typeQuery)
|
|
18
|
+
.then((typeRes) => {
|
|
19
|
+
const type = _.find(typeRes.Items, (type) => {
|
|
20
|
+
return type.typeName === role.type;
|
|
21
|
+
});
|
|
22
|
+
results.push({
|
|
23
|
+
type: "UserType",
|
|
24
|
+
selection: role.type,
|
|
25
|
+
site: role.site,
|
|
26
|
+
});
|
|
27
|
+
if (type) {
|
|
28
|
+
results.push({
|
|
29
|
+
type: "Category",
|
|
30
|
+
selection: type.category,
|
|
31
|
+
site: role.site,
|
|
32
|
+
});
|
|
33
|
+
results.push({
|
|
34
|
+
type: "Category",
|
|
35
|
+
selection: type.category,
|
|
36
|
+
site: "hq",
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
resolve(results);
|
|
40
|
+
})
|
|
41
|
+
.catch(() => {
|
|
42
|
+
resolve(results);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
module.exports = (user) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
48
|
+
return new Promise((resolve) => {
|
|
49
|
+
const results = [
|
|
50
|
+
{
|
|
51
|
+
type: "All",
|
|
52
|
+
site: "hq",
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
const promises = [];
|
|
56
|
+
user.Roles.forEach((role) => {
|
|
57
|
+
promises.push(handleRole(results, role));
|
|
58
|
+
});
|
|
59
|
+
Promise.all(promises).then(() => {
|
|
60
|
+
const filteredResults = _.uniqBy(results, (role) => {
|
|
61
|
+
return `${role.site}_${role.type}_${role.selection}`; // avoid duplicate matches
|
|
62
|
+
});
|
|
63
|
+
console.log("matching types are");
|
|
64
|
+
console.log(filteredResults);
|
|
65
|
+
return resolve(filteredResults);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
68
|
};
|
|
@@ -2,19 +2,19 @@ const indexQuery = require("../../db/common/indexQuery");
|
|
|
2
2
|
const { log } = require("../");
|
|
3
3
|
|
|
4
4
|
module.exports = async (userId, site) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
return new Promise(async (resolve) => {
|
|
6
|
+
const query = {
|
|
7
|
+
IndexName: "UserIndex",
|
|
8
|
+
KeyConditionExpression: `UserId = :userId${
|
|
9
|
+
!site ? "" : " AND Site = :site"
|
|
10
|
+
}`,
|
|
11
|
+
ExpressionAttributeValues: {
|
|
12
|
+
":userId": userId,
|
|
13
|
+
":site": site,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const result = await indexQuery("usertagusers", query);
|
|
17
|
+
log("getMatchingTags", "ResultLength", result.Items.length);
|
|
18
|
+
return resolve(result.Items);
|
|
19
|
+
});
|
|
20
20
|
};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
const _ = require("lodash");
|
|
2
2
|
|
|
3
3
|
module.exports = (site, type, selection, validTypes, validTags) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
// console.log("isValidAudience - site", site);
|
|
5
|
+
// console.log("isValidAudience - type", type);
|
|
6
|
+
// console.log("isValidAudience - selection", selection);
|
|
7
|
+
// console.log("isValidAudience - validTypes", validTypes);
|
|
8
|
+
// console.log("isValidAudience - validTags", validTags);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
switch (type) {
|
|
11
|
+
case "Category":
|
|
12
|
+
case "UserType":
|
|
13
|
+
return _.some(
|
|
14
|
+
validTypes,
|
|
15
|
+
(t) =>
|
|
16
|
+
t.site === site &&
|
|
17
|
+
t.type === type &&
|
|
18
|
+
(_.isEmpty(selection) || t.selection === selection),
|
|
19
|
+
);
|
|
20
|
+
case "UserTags":
|
|
21
|
+
return _.some(validTags, (t) => t.Site === site && t.TagId === selection);
|
|
22
|
+
default:
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
25
|
};
|