Completed
Push — master ( b6e14c...5630cf )
by
unknown
53s
created

src/middleware/transformer.js   A

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 35
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 6
c 1
b 0
f 0
nc 1
mnd 1
bc 6
fnc 3
dl 0
loc 35
ccs 16
cts 17
cp 0.9412
crap 0
rs 10
bpm 2
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A transformer.js ➔ ??? 0 22 1
1
/**
2
 * Hapi middleware for transforming contents of request and response
3
 *
4
 * @since 1.0.0
5
 */
6
7 1
const util = require('../common/common-util');
8
9 1
const defaultOptions = Object.freeze({
10
  apiPrefix: '/api',
11
});
12
13 1
const register = (server, opts, next) => {
14 1
  const options = Object.assign({}, defaultOptions, opts);
15
  /* eslint no-param-reassign: ["error", { "props": false }] */
16 1
  server.ext('onPostAuth', (request, reply) => {
17 13
    if (request.query) {
18 13
      request.query = util.snake2camelObject(request.query);
19
    }
20 13
    if (request.payload) {
21 6
      request.payload = util.snake2camelObject(request.payload);
22
    }
23 13
    return reply.continue();
24
  });
25
26 1
  server.ext('onPreResponse', (request, reply) => {
27 10
    if (request.path.includes(options.apiPrefix)) {
28 10
      return reply(util.camel2snakeObject(request.response.source));
29
    }
30
    return reply.continue();
31
  });
32
33 1
  next();
34
};
35
36 1
register.attributes = {
37
  name: 'hapi-transform',
38
  version: '1.0.0',
39
};
40
41
module.exports = register;
42