@plusscommunities/pluss-core-aws 1.6.7 → 1.6.9

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,17 @@
1
+ const _ = require("lodash");
2
+ const { getMultiRowId } = require("../../helper");
3
+ const indexQuery = require("../common/indexQuery");
4
+
5
+ module.exports = async (entityId, entityType, actionType) => {
6
+ const result = await indexQuery("analytics", {
7
+ IndexName: "AnalyticsActivityIndex",
8
+ KeyConditionExpression: "ActivityId = :activityId",
9
+ ExpressionAttributeValues: {
10
+ ":activityId": getMultiRowId([entityId, entityType, actionType]),
11
+ },
12
+ });
13
+ if (result && !_.isEmpty(result.Items)) {
14
+ return true;
15
+ }
16
+ return false;
17
+ };
@@ -3,12 +3,20 @@ const moment = require("moment");
3
3
  const updateRef = require("../common/updateRef");
4
4
  const { getMultiRowId, getRowId } = require("../../helper");
5
5
 
6
- module.exports = (actionType, entityType, site, user, entityId, data) => {
6
+ module.exports = (
7
+ actionType,
8
+ entityType,
9
+ site,
10
+ user,
11
+ entityId,
12
+ data,
13
+ timestamp
14
+ ) => {
7
15
  return new Promise((resolve, reject) => {
8
16
  const activity = {
9
17
  Id: uuid.v1(),
10
18
  Type: actionType,
11
- Timestamp: moment.utc().valueOf(),
19
+ Timestamp: timestamp || moment.utc().valueOf(),
12
20
  EntityType: entityType,
13
21
  SubjectId: entityId,
14
22
  UserId: user.id,
@@ -1,27 +1,30 @@
1
- const _ = require("lodash");
2
1
  const scanRef = require("./scanRef");
3
2
 
4
- const scanRefRecursive = (table, result, tempResult) => {
5
- return new Promise((resolve) => {
6
- if (!tempResult) {
7
- tempResult = [];
8
- }
9
- let lastKey;
10
- if (result) {
11
- tempResult = _.concat(tempResult, result.Items);
12
- if (!result.LastEvaluatedKey) {
13
- return resolve(tempResult);
14
- } else {
15
- lastKey = result.LastEvaluatedKey;
16
- }
17
- }
3
+ const scanRefRecursive = async (tableName, query, startKey) => {
4
+ if (!query) {
5
+ query = {};
6
+ }
7
+ // Set the ExclusiveStartKey in the params
8
+ query.ExclusiveStartKey = startKey;
18
9
 
19
- scanRef(table, lastKey).then((scanResult) => {
20
- scanRefRecursive(table, scanResult, tempResult).then((innerRes) => {
21
- resolve(innerRes);
22
- });
23
- });
24
- });
10
+ // Perform the scan and await the results
11
+ const data = await scanRef(tableName, query);
12
+
13
+ // Extract the Items from the results
14
+ let items = data.Items;
15
+
16
+ // If the LastEvaluatedKey is present, that means there are more items to fetch
17
+ if (data.LastEvaluatedKey) {
18
+ // Recursively call the function to fetch the next batch of items, and await the results
19
+ // Concatenate the new items with the ones we have already fetched
20
+ items = [
21
+ ...items,
22
+ ...(await scanRefRecursive(tableName, query, data.LastEvaluatedKey)),
23
+ ];
24
+ }
25
+
26
+ // Return the complete list of items
27
+ return items;
25
28
  };
26
29
 
27
30
  module.exports = scanRefRecursive;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-aws",
3
- "version": "1.6.7",
3
+ "version": "1.6.9",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "scripts": {
6
6
  "betapatch": "npm version prepatch --preid=beta",