@plusscommunities/pluss-core-aws 1.2.2 → 1.2.6

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,38 @@
1
+ const _ = require("lodash");
2
+ const getSessionUser = require("../auth/getSessionUser");
3
+ const getMatchingAudienceTypes = require("./getMatchingAudienceTypes");
4
+ const getMatchingTags = require("./getMatchingTags");
5
+ const isValidAudience = require("./isValidAudience");
6
+
7
+ module.exports = async (items, authkey, site) => {
8
+ const validTypes = await getMatchingAudienceTypes(authkey);
9
+ let validTags = [];
10
+ if (site) {
11
+ const userId = await getSessionUser(authkey);
12
+ validTags = await getMatchingTags(userId, site);
13
+ }
14
+
15
+ return _.filter(items, (item) => {
16
+ if (!item.AudienceType) return true;
17
+
18
+ if (item.AudienceType === "Custom") {
19
+ return _.some(item.AudienceTypeSelection, (at) =>
20
+ isValidAudience(
21
+ site,
22
+ at.AudienceType,
23
+ at.AudienceTypeSelection,
24
+ validTypes,
25
+ validTags
26
+ )
27
+ );
28
+ }
29
+
30
+ return isValidAudience(
31
+ site,
32
+ item.AudienceType,
33
+ item.AudienceTypeSelection,
34
+ validTypes,
35
+ validTags
36
+ );
37
+ });
38
+ };
@@ -1,25 +1,36 @@
1
1
  const _ = require("lodash");
2
- const getMatchingAudienceTags = require("./getMatchingAudienceTags");
2
+ const getSessionUser = require("../auth/getSessionUser");
3
+ const getMatchingTags = require("./getMatchingTags");
4
+ const isValidAudience = require("./isValidAudience");
3
5
 
4
- module.exports = async (items, types, authkey) => {
5
- const matchingTags = authkey ? await getMatchingAudienceTags(authkey) : [];
6
- console.log("items", items);
7
- console.log("types", types);
8
- console.log("matchingTags", matchingTags);
6
+ module.exports = async (items, validTypes, authkey, site) => {
7
+ let validTags = [];
8
+ if (authkey) {
9
+ const userId = await getSessionUser(authkey);
10
+ validTags = await getMatchingTags(userId, site);
11
+ }
9
12
 
10
13
  return _.filter(items, (item) => {
11
- if (!item.AudienceType) {
12
- return true;
13
- }
14
- const matchingType = _.find(types, (t) => {
15
- return t.type === item.AudienceType;
16
- });
17
- if (!matchingType) {
18
- return false;
19
- }
20
- if (!matchingType.selection && !item.AudienceTypeSelection) {
21
- return true;
14
+ if (!item.AudienceType) return true;
15
+
16
+ if (item.AudienceType === "Custom") {
17
+ return _.some(item.AudienceTypeSelection, (at) =>
18
+ isValidAudience(
19
+ site,
20
+ at.AudienceType,
21
+ at.AudienceTypeSelection,
22
+ validTypes,
23
+ validTags
24
+ )
25
+ );
22
26
  }
23
- return matchingType.selection === item.AudienceTypeSelection;
27
+
28
+ return isValidAudience(
29
+ site,
30
+ item.AudienceType,
31
+ item.AudienceTypeSelection,
32
+ validTypes,
33
+ validTags
34
+ );
24
35
  });
25
36
  };
@@ -132,6 +132,9 @@ module.exports = async (site, audienceType, audienceTypeSelection) => {
132
132
  site
133
133
  );
134
134
 
135
+ // console.log("categoryMatches", categoryMatches);
136
+ // console.log("typeMatches", typeMatches);
137
+ // console.log("tagMatches", tagMatches);
135
138
  return _.unionBy(categoryMatches, typeMatches, tagMatches, "id");
136
139
  case "Category":
137
140
  return await getCategoryMatches(users, audienceTypeSelection, site);
@@ -0,0 +1,20 @@
1
+ const indexQuery = require("../../db/common/indexQuery");
2
+ const { log } = require("../");
3
+
4
+ module.exports = async (userId, site) => {
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
+ };
@@ -0,0 +1,25 @@
1
+ const _ = require("lodash");
2
+
3
+ module.exports = (site, type, selection, validTypes, validTags) => {
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
+
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
+ };
@@ -14,6 +14,11 @@ module.exports = (noti) => {
14
14
  thisNoti.Subtext = noti.Data.title || noti.Data.description;
15
15
  thisNoti.Icon = "wrench";
16
16
  break;
17
+ case "EntityCommented":
18
+ thisNoti.Text = noti.Data.comment;
19
+ thisNoti.Subtext = noti.Data.title || noti.Data.description;
20
+ thisNoti.Icon = "commenting";
21
+ break;
17
22
  case "EventRepChange":
18
23
  let eventChangeText = "";
19
24
  if (noti.Data.LocationChanged && noti.Data.TimeChanged) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-aws",
3
- "version": "1.2.2",
3
+ "version": "1.2.6",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "scripts": {
6
6
  "patch": "npm version patch",
@@ -1,22 +0,0 @@
1
- const getUserPreview = require("../getUserPreview");
2
- const getSessionUser = require("../auth/getSessionUser");
3
-
4
- const getUserTags = async (userId) => {
5
- const query = {
6
- IndexName: "UserIndex",
7
- KeyConditionExpression: "UserId = :userId",
8
- ExpressionAttributeValues: {
9
- ":userId": userId,
10
- },
11
- };
12
-
13
- const { Items } = await indexQuery("usertagusers", query);
14
- return Items;
15
- };
16
-
17
- module.exports = async (authkey) => {
18
- const uid = await getSessionUser(authkey);
19
- // const user = await getUserPreview(uid, true, true);
20
-
21
- return await getUserTags(uid);
22
- };