fix: Date format in sales/purchases APIs.

fix: Algorithm FIFO cost calculate method.
This commit is contained in:
Ahmed Bouhuolia
2020-08-19 00:13:53 +02:00
parent a202a21df5
commit 52d01b4ed8
21 changed files with 291 additions and 133 deletions

View File

@@ -0,0 +1,35 @@
import { camelCase, snakeCase } from 'lodash';
/**
* create a middleware to change json format from snake case to camelcase in request
* then change back to snake case in response
*
*/
export default function createMiddleware() {
return function (req, res, next) {
/**
* camelize req.body
*/
if (req.body && typeof req.body === 'object') {
req.body = camelCase(req.body);
}
/**
* camelize req.query
*/
if (req.query && typeof req.query === 'object') {
req.query = camelCase(req.query);
}
/**
* wrap res.json()
*/
const sendJson = res.json;
res.json = (data) => {
return sendJson.call(res, snakeCase(data));
}
return next();
}
}