mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
fix: Date format in sales/purchases APIs.
fix: Algorithm FIFO cost calculate method.
This commit is contained in:
35
server/src/http/middleware/prettierMiddleware.ts
Normal file
35
server/src/http/middleware/prettierMiddleware.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user