1 | const httpProcessor = require('../HttpProcessor'); |
||
2 | const services = require('../config/services'); |
||
3 | const constants = require('../config/constants'); |
||
4 | |||
5 | class VerifyMe |
||
6 | { |
||
7 | constructor() { |
||
8 | this.client = services.verifyMe.client; |
||
9 | this.apiKey = services.verifyMe.api_key; |
||
10 | this.baseUrl = services.verifyMe.api_url; |
||
11 | |||
12 | } |
||
13 | |||
14 | /** |
||
15 | * Process axios calls |
||
16 | * |
||
17 | * @param {string} method The call method get|post|put|delete|patch |
||
18 | * @param {string} url The url to call |
||
19 | * @param {object|formData} payload The payload data to send with the call |
||
20 | */ |
||
21 | process(method, url, payload) { |
||
22 | //HttpProcessor class to handle axios calls |
||
23 | let processor = new httpProcessor(this.baseUrl, this.apiKey, this.client); |
||
0 ignored issues
–
show
Coding Style
Best Practice
introduced
by
![]() |
|||
24 | |||
25 | return processor.process(method, url, payload) |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Handles the ID request |
||
30 | * |
||
31 | * @param {object} IdFilter |
||
32 | * @return {object} |
||
33 | */ |
||
34 | async handle(IdFilter) |
||
35 | { |
||
36 | if (!IdFilter.isSuccessful()) { |
||
0 ignored issues
–
show
There is no return statement if
!IdFilter.isSuccessful() is false . Are you sure this is correct? If so, consider adding return; explicitly.
This check looks for functions where a Consider this little piece of code function isBig(a) {
if (a > 5000) {
return "yes";
}
}
console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined
The function This behaviour may not be what you had intended. In any case, you can add a
![]() |
|||
37 | const idType = IdFilter.getIDType().toUpperCase(); |
||
38 | const type = this.getType(idType); |
||
39 | const idNumber = IdFilter.getIDNumber(); |
||
40 | |||
41 | const url = '/v1/verifications/identities/' + type + '/:' + idNumber; |
||
42 | |||
43 | const firstName = IdFilter.getFirstName(); |
||
44 | const lastName = IdFilter.getLastName(); |
||
45 | const dateOfBirth = IdFilter.getDOB(); |
||
46 | |||
47 | const body = { |
||
48 | 'id' : idNumber, |
||
49 | 'firstname' : firstName, |
||
50 | 'lastname' : lastName, |
||
51 | 'dob' : dateOfBirth, |
||
52 | }; |
||
53 | |||
54 | try { |
||
55 | const response = await this.process('POST', url, body); |
||
56 | |||
57 | IdFilter.confirmSuccess(); |
||
58 | |||
59 | IdFilter.setHandler(this.client); |
||
60 | |||
61 | IdFilter.setData({ |
||
62 | 'handler' : IdFilter.getHandler(), |
||
63 | 'country' : 'NG', |
||
64 | 'message' : idType + ' Verified' + ' Successfully', |
||
65 | 'data' : response |
||
66 | }); |
||
67 | |||
68 | return IdFilter.getData(); |
||
69 | |||
70 | } catch (error) { |
||
71 | //Error occurred |
||
72 | IdFilter.setError({'error' : error}); |
||
73 | |||
74 | console.log(error); |
||
0 ignored issues
–
show
|
|||
75 | return IdFilter.getError(); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Transform the ID |
||
83 | * |
||
84 | * @param {string} type |
||
85 | * @return {string} |
||
86 | */ |
||
87 | getType(type) |
||
88 | { |
||
89 | if (type === constants.idValues.TYPE_DRIVERS_LICENSE) { |
||
90 | return 'drivers_license'; |
||
91 | } |
||
92 | if (type === constants.idValues.TYPE_NIN ) { |
||
93 | return 'nin'; |
||
94 | } |
||
95 | if (type === constants.idValues.TYPE_VOTER_CARD) { |
||
96 | return 'vin'; |
||
97 | } |
||
98 | if (type === constants.idValues.TYPE_BVN) { |
||
99 | return 'bvn'; |
||
100 | } |
||
101 | return type.toLowerCase(); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | module.exports = VerifyMe; |