lib/helpers/ApiResponseHanlder.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 67
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 22
mnd 0
bc 0
fnc 5
dl 0
loc 67
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A ApiResponseHanlder.js ➔ success 0 3 1
A ApiResponseHanlder.js ➔ authenticationError 0 3 1
A ApiResponseHanlder.js ➔ validationError 0 3 1
A ApiResponseHanlder.js ➔ send 0 14 1
A ApiResponseHanlder.js ➔ failure 0 3 1
1
'use strict';
2
const Http = require('./Http');
3
const CONSTANT = require('../utils/lang');
4
5
/**
6
 * @param array $body
7
 * @param string $message
8
 * @return \Http\JsonResponse
9
 */
10
function success(body = [], message = CONSTANT.GENERAL.SUCCESS) {
11
  return send(Http.Codes[Http.SUCCESS], message, body, null);
12
}
13
14
/**
15
 * @return \Http\JsonResponse
16
 */
17
function authenticationError() {
18
  return send(Http.Codes[Http.UNAUTHORISED], CONSTANT.GENERAL.UNAUTHENTICATED, {}, null);
19
}
20
21
/**
22
 * @param string $message
23
 * @param null $exception
24
 * @param array $body
25
 * @return \Http\JsonResponse
26
 */
27
function failure(message = CONSTANT.GENERAL.FAILURE, exception = null, body = []) {
28
  return send(Http.Codes[Http.BAD_REQUEST], message, body, exception);
29
}
30
31
/**
32
 * @param string $message
33
 * @param null $exception
34
 * @param array $body
35
 * @return \Http\JsonResponse
36
 */
37
function validationError(message = CONSTANT.GENERAL.FAILURE, exception = null, body = []) {
38
  return send(Http.Codes[Http.VALIDATION_ERROR], message, body, exception);
39
}
40
/**
41
 * @param status
42
 * @param message
43
 * @param body
44
 * @param exception
45
 * @return \Http\JsonResponse
46
 */
47
function send(status, message, body, exception) {
48
  return {
49
    status: status,
50
    message: message,
51
    body: body,
52
    exception: exception,
53
  };
54
  //     return response()->json({
55
  //         'status'    :  $status,
56
  //         'message'   :  $message,
57
  //         'body'      :  $body,
58
  //         'exception' :  $exception
59
  // }, $status, [], JSON_UNESCAPED_UNICODE );
60
}
61
62
module.exports = {
63
  success: success,
64
  authenticationError: authenticationError,
65
  failure: failure,
66
  validationError: validationError,
67
};
68