inlaweb-lib-dynamodb 1.0.15 → 1.0.17

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.
Files changed (3) hide show
  1. package/index.d.ts +2 -0
  2. package/index.js +19 -8
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -12,6 +12,8 @@ export declare class DynamoLib {
12
12
  searchParameters: SearchParameters;
13
13
  permission?: string;
14
14
  username?: string;
15
+ fieldNamePermission?: string;
16
+ fieldValuePermission?: string;
15
17
  }): Promise<T[]>;
16
18
  deleteItem(tableName: string, key: KeyValue): Promise<void>;
17
19
  private buildQueryParams;
package/index.js CHANGED
@@ -81,10 +81,21 @@ class DynamoLib {
81
81
  async query(params) {
82
82
  try {
83
83
  const parameters = this.buildQueryParams(params);
84
- this.logger.debug(`Query: ${JSON.stringify(parameters)}`);
85
- const response = await this.docClient.send(new lib_dynamodb_1.QueryCommand(parameters));
86
- this.logger.debug(`Query Result: ${JSON.stringify(response)}`);
87
- return response.Items;
84
+ let allItems = [];
85
+ let lastEvaluatedKey;
86
+ do {
87
+ if (lastEvaluatedKey) {
88
+ parameters.ExclusiveStartKey = lastEvaluatedKey;
89
+ }
90
+ this.logger.debug(`Query: ${JSON.stringify(parameters)}`);
91
+ const response = await this.docClient.send(new lib_dynamodb_1.QueryCommand(parameters));
92
+ this.logger.debug(`Query Result: ${JSON.stringify(response)}`);
93
+ if (response.Items) {
94
+ allItems = allItems.concat(response.Items);
95
+ }
96
+ lastEvaluatedKey = response.LastEvaluatedKey;
97
+ } while (lastEvaluatedKey);
98
+ return allItems;
88
99
  }
89
100
  catch (error) {
90
101
  this.logger.error(error.message);
@@ -132,8 +143,8 @@ class DynamoLib {
132
143
  }
133
144
  if (params.permission && params.permission === "OWNS") {
134
145
  params.searchParameters.parameters.push({
135
- name: "creationUser",
136
- value: params.username,
146
+ name: params.fieldNamePermission || "createdBy",
147
+ value: params.fieldValuePermission || params.username,
137
148
  operator: "FILTER",
138
149
  filterOperator: "=",
139
150
  });
@@ -352,8 +363,8 @@ class DynamoLib {
352
363
  SK: entity,
353
364
  entity: "COUN",
354
365
  order: 0,
355
- creationUser: username,
356
- creationDate: moment_timezone_1.default
366
+ createdBy: username,
367
+ createdAt: moment_timezone_1.default
357
368
  .tz(new Date(), "America/Bogota")
358
369
  .format("YYYY-MM-DD"),
359
370
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inlaweb-lib-dynamodb",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/types/index.d.ts",
6
6
  "scripts": {