How to use the @mojaloop/central-services-database.Db function in @mojaloop/central-services-database

To help you get started, we’ve selected a few @mojaloop/central-services-database examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mojaloop / central-ledger / test / util / randomTransfers.js View on Github external
that actually holds the copyright for their contributions (see the
 Gates Foundation organization for an example). Those individuals should have
 their names indented and be marked with a '-'. Email address can be added
 optionally within square brackets .
 * Gates Foundation
 - Name Surname 

 * Georgi Georgiev 
 --------------
 ******/

'use strict'

const Uuid = require('uuid4')
const Config = require('../../src/lib/config')
const Db = require('@mojaloop/central-services-database').Db
const Enum = require('../../src/lib/enum')
const TS = Enum.TransferState

const randExpirationDate = (maxHoursDiff) => {
  let ms = Math.floor(Math.random() * maxHoursDiff * 3600 * 1000)
  if (ms > 0) {
    ms += 3600 * 1000 // make sure no future transfer expires within 1 hour
  }
  return new Date(new Date().getTime() + ms)
}

const randTransfer = (amount, currency, maxHoursDiff) => {
  const expirationDate = randExpirationDate(maxHoursDiff)
  let createdDate
  if (maxHoursDiff > 0) {
    createdDate = new Date() // all transfer that expire in the future are created at time of generation