All files / src/common_services/dynamodb dynamodbService.ts

100% Statements 18/18
100% Branches 2/2
100% Functions 2/2
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 4413x 13x 13x 13x 13x     13x       179x 179x   179x       179x   179x 1x       179x             1x             1x 1x      
import { Injectable } from '@nestjs/common';
import AWSXray from 'aws-xray-sdk';
import DynamoDB, { DocumentClient } from 'aws-sdk/clients/dynamodb';
import { EnvironmentService } from '../config';
import { DynamodbUtils } from './dynamodbUtils';
 
@Injectable()
export class DynamodbService {
  documentClient: DocumentClient;
 
  constructor(
    private readonly envService: EnvironmentService,
    public utils: DynamodbUtils,
  ) {
    this.documentClient = new DocumentClient({
      service: new DynamoDB(),
    });
 
    this.utils = new DynamodbUtils();
 
    if (envService.isInLambda) {
      AWSXray.captureAWSClient((this.documentClient as any).service);
    }
  }
 
  getQueryOutput = (
    queryInput: DocumentClient.QueryInput,
    type: string,
    timestampFilter: string,
    filter?: string,
    nextToken?: DocumentClient.Key,
  ): Promise<DocumentClient.QueryOutput> => {
    const params = this.utils.prepareMultiQueryParams(
      queryInput,
      type,
      timestampFilter,
      nextToken,
      filter,
    );
    console.log('query parameter:', params);
    return this.documentClient.query(params).promise();
  };
}