All files / src/deposits depositUtils.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 2/2
100% Lines 14/14

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    9x 9x   9x         9x             9x   9x   6x           9x     1x 1x 1x 1x 1x 1x    
import { DocumentClient } from 'aws-sdk/clients/dynamodb';
import { Deposit } from '../types.d';
import { DynamodbUtils } from '../common_services/dynamodb/dynamodbUtils';
import { unmarshallDeposit } from './schema/tableSchema';
 
const dynamodbUtils = new DynamodbUtils();
/**
 * map the attributes name different between database and Transaction interface
 */
 
const dbToDepositNameMapping: { [key: string]: string } = {
  depositUuid: 'id',
};
 
/**
 * The attributes in database which don't exit in Deposit
 */
const attributesToDelete = ['type', 'depositUuid'];
 
export const convertDbItemToDeposit = (
  item: DocumentClient.AttributeMap,
): Deposit => dynamodbUtils.convertDbItemToDto<Deposit>(
  item,
  dbToDepositNameMapping,
  attributesToDelete,
);
 
export const convertDbStreamToDeposit = (record: {
  dynamodb: { NewImage: DocumentClient.AttributeMap };
}): Deposit => {
  const { dynamodb } = record;
  const { NewImage: newImage } = dynamodb;
  console.log('new Image ', newImage);
  console.log('new Image string', JSON.stringify(newImage));
  const deposit: any = unmarshallDeposit(newImage);
  return convertDbItemToDeposit(deposit)
};