1 import * as express from 'express'
3 import { pseudoRandomBytes } from 'crypto'
4 import { join } from 'path'
6 import { logger } from './logger'
8 function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) {
9 res.type('json').status(400).end()
12 function generateRandomString (size: number, callback: (err: Error, randomString?: string) => void) {
13 pseudoRandomBytes(size, function (err, raw) {
14 if (err) return callback(err)
16 callback(null, raw.toString('hex'))
20 function createEmptyCallback () {
21 return function (err) {
22 if (err) logger.error('Error in empty callback.', { error: err })
26 function isTestInstance () {
27 return process.env.NODE_ENV === 'test'
30 function getFormatedObjects (objects: any[], objectsTotal: number) {
31 const formatedObjects = []
33 objects.forEach(function (object) {
34 formatedObjects.push(object.toFormatedJSON())
44 // We are in /dist/helpers/utils.js
45 return join(__dirname, '..', '..', '..')
48 // ---------------------------------------------------------------------------