@plusscommunities/pluss-core-aws 1.5.15-beta.0 → 1.5.15

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.
@@ -0,0 +1,16 @@
1
+ const getRef = require("../common/getRef");
2
+
3
+ module.exports = async (site, key) => {
4
+ return new Promise((resolve, reject) => {
5
+ getRef("sites", "Id", site)
6
+ .then((item) => {
7
+ if (item && item.Settings) {
8
+ return resolve(item.Settings[key]);
9
+ }
10
+ return resolve(undefined);
11
+ })
12
+ .catch((error) => {
13
+ return resolve(undefined);
14
+ });
15
+ });
16
+ };
@@ -1,4 +1,4 @@
1
- const indexQueryRecursive = require("../common/indexQueryRecursive");
1
+ const indexQuery = require("../common/indexQuery");
2
2
 
3
3
  module.exports = async (site, entityKey) => {
4
4
  const query = {
@@ -10,5 +10,6 @@ module.exports = async (site, entityKey) => {
10
10
  },
11
11
  };
12
12
 
13
- return await indexQueryRecursive("actionqueue", query);
13
+ const { Items } = await indexQuery("actionqueue", query);
14
+ return Items;
14
15
  };
@@ -1,7 +1,9 @@
1
1
  const _ = require("lodash");
2
2
  const indexQuery = require("../../db/common/indexQuery");
3
+ const getRef = require("../../db/common/getRef");
3
4
  const scanRefRecursive = require("../../db/common/scanRefRecursive");
4
5
  const userToUserPreview = require("../userToUserPreview");
6
+ const { getRowId, log } = require("..");
5
7
 
6
8
  const getUsers = async (site) => {
7
9
  if (site === "all") {
@@ -105,6 +107,47 @@ const getTagMatches = async (users, audienceTypeSelection, site) => {
105
107
  );
106
108
  };
107
109
 
110
+ const getEventMatches = async (users, audienceTypeSelection) => {
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
+ };
150
+
108
151
  module.exports = async (
109
152
  site,
110
153
  audienceType,
@@ -138,11 +181,20 @@ module.exports = async (
138
181
  audienceTypeSelection,
139
182
  site
140
183
  );
184
+ const eventMatches = await getEventMatches(users, audienceTypeSelection);
141
185
 
142
186
  // console.log("categoryMatches", categoryMatches);
143
187
  // console.log("typeMatches", typeMatches);
144
188
  // console.log("tagMatches", tagMatches);
145
- return _.unionBy(categoryMatches, typeMatches, tagMatches, "id");
189
+ return _.unionBy(
190
+ categoryMatches,
191
+ typeMatches,
192
+ tagMatches,
193
+ eventMatches,
194
+ "id"
195
+ );
196
+ case "EventAudience":
197
+ return await getEventMatches(users, audienceTypeSelection);
146
198
  case "Category":
147
199
  return await getCategoryMatches(users, audienceTypeSelection, site);
148
200
  case "UserType":
@@ -0,0 +1,11 @@
1
+ const getSiteSetting = require("../../db/auth/getSiteSetting");
2
+
3
+ module.exports = async (site, key, expectedValue) => {
4
+ return new Promise(async (resolve) => {
5
+ if (!site) {
6
+ return resolve(false);
7
+ }
8
+ const siteSetting = await getSiteSetting(site, key);
9
+ return resolve(siteSetting === expectedValue);
10
+ });
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-aws",
3
- "version": "1.5.15-beta.0",
3
+ "version": "1.5.15",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "scripts": {
6
6
  "betapatch": "npm version prepatch --preid=beta",
@@ -1,20 +0,0 @@
1
- const indexQueryRecursive = require("../common/indexQueryRecursive");
2
-
3
- module.exports = async (
4
- site,
5
- minTime = 0,
6
- maxTime = Number.MAX_SAFE_INTEGER
7
- ) => {
8
- const query = {
9
- IndexName: "SiteTriggerAtIndex",
10
- KeyConditionExpression:
11
- "Site = :site AND TriggerAt BETWEEN :minTime and :maxTime",
12
- ExpressionAttributeValues: {
13
- ":site": site,
14
- ":minTime": minTime,
15
- ":maxTime": maxTime,
16
- },
17
- };
18
-
19
- return await indexQueryRecursive("actionqueue", query);
20
- };