@plusscommunities/pluss-core-aws 2.0.11 → 2.0.13-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.
|
@@ -2,7 +2,15 @@ const _ = require("lodash");
|
|
|
2
2
|
const { getMultiRowId } = require("../../helper");
|
|
3
3
|
const indexQuery = require("../common/indexQuery");
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Check if the activity exists
|
|
7
|
+
* @param {*} entityId Id of the entity
|
|
8
|
+
* @param {*} entityType Type of the entity
|
|
9
|
+
* @param {*} actionType Type of the analytics action
|
|
10
|
+
* @param {*} userId Id of user to check against (optional)
|
|
11
|
+
* @returns Whether there is any matching analytics activity
|
|
12
|
+
*/
|
|
13
|
+
module.exports = async (entityId, entityType, actionType, userId) => {
|
|
6
14
|
const result = await indexQuery("analytics", {
|
|
7
15
|
IndexName: "AnalyticsActivityIndex",
|
|
8
16
|
KeyConditionExpression: "ActivityId = :activityId",
|
|
@@ -11,6 +19,10 @@ module.exports = async (entityId, entityType, actionType) => {
|
|
|
11
19
|
},
|
|
12
20
|
});
|
|
13
21
|
if (result && !_.isEmpty(result.Items)) {
|
|
22
|
+
if (userId) {
|
|
23
|
+
// check if there is matching analytics activity for that user
|
|
24
|
+
return result.Items.some((item) => item.UserId === userId);
|
|
25
|
+
}
|
|
14
26
|
return true;
|
|
15
27
|
}
|
|
16
28
|
return false;
|
|
@@ -4,6 +4,19 @@ const checkActivityExists = require("./checkActivityExists");
|
|
|
4
4
|
const updateRef = require("../common/updateRef");
|
|
5
5
|
const { getMultiRowId, getRowId } = require("../../helper");
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Creates an analytics entry
|
|
9
|
+
* @param {*} actionType Type of action to log
|
|
10
|
+
* @param {*} entityType Type of entity the action is against
|
|
11
|
+
* @param {*} site Site to log with
|
|
12
|
+
* @param {*} user User performing the action
|
|
13
|
+
* @param {*} entityId Id of the entity the action is against
|
|
14
|
+
* @param {*} data Other data to log
|
|
15
|
+
* @param {*} timestamp Timestamp of the activity
|
|
16
|
+
* @param {*} uniqueActivity If true, will only log if the activity doesn't already exist
|
|
17
|
+
* @param {*} uniqueToUser If true, will only log if the activity doesn't already exist for the user
|
|
18
|
+
* @returns Whether the activity was logged
|
|
19
|
+
*/
|
|
7
20
|
module.exports = async (
|
|
8
21
|
actionType,
|
|
9
22
|
entityType,
|
|
@@ -12,11 +25,17 @@ module.exports = async (
|
|
|
12
25
|
entityId,
|
|
13
26
|
data,
|
|
14
27
|
timestamp,
|
|
15
|
-
uniqueActivity
|
|
28
|
+
uniqueActivity,
|
|
29
|
+
uniqueToUser
|
|
16
30
|
) => {
|
|
17
31
|
// Check if the activity already exists
|
|
18
32
|
if (uniqueActivity) {
|
|
19
|
-
const exists = await checkActivityExists(
|
|
33
|
+
const exists = await checkActivityExists(
|
|
34
|
+
entityId,
|
|
35
|
+
entityType,
|
|
36
|
+
actionType,
|
|
37
|
+
uniqueToUser ? user.id : null
|
|
38
|
+
);
|
|
20
39
|
if (exists) {
|
|
21
40
|
return false;
|
|
22
41
|
}
|
package/package.json
CHANGED