1 | const constants = require('../../config/constants'); |
||
2 | class CredequityValidation { |
||
3 | |||
4 | validate(response, IdFilter){ |
||
5 | |||
6 | const isVerified = this.verify(response, IdFilter); |
||
7 | |||
8 | if(isVerified == true){ |
||
0 ignored issues
–
show
Best Practice
introduced
by
![]() |
|||
9 | return response; |
||
10 | } |
||
11 | |||
12 | return isVerified; |
||
13 | } |
||
14 | |||
15 | /** |
||
16 | * Verify Credequity information |
||
17 | * |
||
18 | * @param {object} result |
||
19 | * @param {object} IdFilter |
||
20 | * @return boolean |
||
21 | */ |
||
22 | verify(result, IdFilter){ |
||
23 | const data = result.data; |
||
24 | const idType = IdFilter.getIDType(); |
||
25 | |||
26 | if(idType == constants.idValues.TYPE_BVN ){ |
||
27 | |||
28 | if (data.firstName.toUpperCase() !== IdFilter.getFirstName().toUpperCase()) { |
||
29 | return { 'error' : 'Firstname does not match'} ; |
||
30 | } |
||
31 | |||
32 | if (data.lastName.toUpperCase() !== IdFilter.getLastName().toUpperCase()) { |
||
33 | return { 'error' : 'Lastname does not match'}; |
||
34 | } |
||
35 | |||
36 | if (data.dateOfBirth !== IdFilter.getDOB()) { |
||
37 | return { 'error' : 'Date of birth does not match'}; |
||
38 | } |
||
39 | } |
||
40 | |||
41 | if(idType == constants.idValues.TYPE_DRIVERS_LICENSE ){ |
||
42 | if (data.Birthdate !== IdFilter.getDOB()) { |
||
43 | return { 'error' : 'Date of birth does not match'}; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | if(idType == constants.idValues.TYPE_NIN ){ |
||
48 | if (data.firstname.toUpperCase() !== IdFilter.getFirstName().toUpperCase()) { |
||
49 | return { 'error' : 'Firstname does not match'} ; |
||
50 | } |
||
51 | |||
52 | if (data.birthdate !== IdFilter.getDOB()) { |
||
53 | return { 'error' : 'Date of birth does not match'}; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | return true; |
||
58 | |||
59 | } |
||
60 | |||
61 | } |
||
62 | |||
63 | module.exports = CredequityValidation; |