@plusscommunities/pluss-core-aws 1.5.17-beta.0 → 1.5.18-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.
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const AWS = require("aws-sdk");
|
|
2
|
+
const dynamoDb = new AWS.DynamoDB.DocumentClient({ convertEmptyValues: true });
|
|
3
|
+
const { log, generateLogId } = require("../../helper");
|
|
4
|
+
|
|
5
|
+
module.exports = (table) => {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const logId = generateLogId();
|
|
8
|
+
const query = {
|
|
9
|
+
TableName: `${process.env.tablePrefix}${table}`,
|
|
10
|
+
Select: "COUNT",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
dynamoDb.scan(query, (error, result) => {
|
|
14
|
+
// handle potential errors
|
|
15
|
+
if (error) {
|
|
16
|
+
log("getTableCount", "Error", error, logId);
|
|
17
|
+
reject();
|
|
18
|
+
return;
|
|
19
|
+
} else {
|
|
20
|
+
resolve(result);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
};
|
|
@@ -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(
|
|
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/helper/sendEmail.js
CHANGED
|
@@ -36,9 +36,7 @@ module.exports = async (
|
|
|
36
36
|
bcc = null,
|
|
37
37
|
} = {}
|
|
38
38
|
) => {
|
|
39
|
-
console.log("sendEmail", { toEmail, subject, content, useTemplate });
|
|
40
39
|
const { communityConfig, serverlessConfig, emailConfig } = getConfig();
|
|
41
|
-
console.log("emailConfig", emailConfig);
|
|
42
40
|
|
|
43
41
|
if (useTemplate) {
|
|
44
42
|
content = `<div style="padding: 24px; padding-top: 0px; background-color: #f2f4f8;margin: 0px;">
|
|
@@ -59,10 +57,10 @@ module.exports = async (
|
|
|
59
57
|
</div>
|
|
60
58
|
<div style='margin-top: 30px;'>
|
|
61
59
|
<div style='margin: 0 auto; width: fit-content;'>
|
|
62
|
-
<div style='vertical-align: top; height:
|
|
63
|
-
<span style=' font-size: 13px; line-height:
|
|
60
|
+
<div style='vertical-align: top; height: 20px; margin-right: 10px; color: #828282; display: inline-block;'>
|
|
61
|
+
<span style=' font-size: 13px; line-height: 20px;'>powered by</span>
|
|
64
62
|
</div>
|
|
65
|
-
<img src="https://pluss-prd-uploads.s3.ap-southeast-2.amazonaws.com/uploads/users/ap-southeast-2:80aecdcb-9955-493e-a341-2f2263f64777/public/
|
|
63
|
+
<img src="https://pluss-prd-uploads.s3.ap-southeast-2.amazonaws.com/uploads/users/ap-southeast-2:80aecdcb-9955-493e-a341-2f2263f64777/public/d99198114e20a1245693e48790/plusslogo.png" style="display: inline-block; height: 20px; width: 237px; background-repeat: no-repeat; background-size:contain;"></img>
|
|
66
64
|
</div>
|
|
67
65
|
</div>
|
|
68
66
|
</div>`;
|
|
@@ -79,12 +77,10 @@ module.exports = async (
|
|
|
79
77
|
html: content,
|
|
80
78
|
};
|
|
81
79
|
|
|
82
|
-
console.log("checking email service", serverlessConfig);
|
|
83
80
|
const sesInfo = await getEmailServiceInfo(
|
|
84
81
|
serverlessConfig.key,
|
|
85
82
|
serverlessConfig.secret
|
|
86
83
|
);
|
|
87
|
-
console.log("sesInfo", sesInfo);
|
|
88
84
|
|
|
89
85
|
if (sesInfo.enabled) {
|
|
90
86
|
try {
|
package/package.json
CHANGED