add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import { snakeCase } from 'lodash';
import { mapKeysDeep } from 'utils';
/**
* Express middleware for intercepting and transforming json responses
*
* @param {function} [condition] - takes the req and res and returns a boolean indicating whether to run the transform on this response
* @param {function} transform - takes an object passed to res.json and returns a replacement object
* @return {function} the middleware
*/
export function JSONResponseTransformer(transform: Function) {
const replaceJson = (res) => {
var origJson = res.json;
res.json = function (val) {
const json = JSON.parse(JSON.stringify(val));
return origJson.call(res, transform(json));
};
};
return function (req, res, next) {
replaceJson(res);
next();
};
}
/**
* Transformes the given response keys to snake case.
* @param response
* @returns
*/
export const snakecaseResponseTransformer = (response) => {
return mapKeysDeep(response, (value, key) => {
return snakeCase(key);
});
};