1 import * as express from 'express'
3 import { pseudoRandomBytes } from 'crypto'
5 import { logger } from './logger'
7 function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) {
8 res.type('json').status(400).end()
11 function generateRandomString (size: number, callback: (err: Error, randomString?: string) => void) {
12 pseudoRandomBytes(size, function (err, raw) {
13 if (err) return callback(err)
15 callback(null, raw.toString('hex'))
19 function createEmptyCallback () {
20 return function (err) {
21 if (err) logger.error('Error in empty callback.', { error: err })
25 interface FormatableToJSON {
29 function getFormatedObjects<U, T extends FormatableToJSON> (objects: T[], objectsTotal: number) {
30 const formatedObjects: U[] = []
32 objects.forEach(function (object) {
33 formatedObjects.push(object.toFormatedJSON())
42 // ---------------------------------------------------------------------------