1 | const constants = require('../../config/constants'); |
||
2 | |||
3 | class AppruveValidation { |
||
4 | |||
5 | validate(response, IdFilter){ |
||
6 | const idType = IdFilter.getIDType(); |
||
7 | |||
8 | if(IdFilter.getCountry() == 'GH'){ |
||
9 | |||
10 | if(idType == constants.idValues.TYPE_VOTER_CARD){ |
||
11 | return response; |
||
12 | }//Exclude Appruve Field Verification for this |
||
13 | |||
14 | if(idType == constants.idValues.TYPE_TIN){ |
||
15 | if(!response.data.is_valid){ |
||
16 | return { 'error' : 'Tin is not valid'} ; |
||
17 | } |
||
18 | |||
19 | return response; |
||
20 | }//Exclude Appruve Field Verification for this |
||
21 | |||
22 | if(idType == constants.idValues.TYPE_DRIVERS_LICENSE){ |
||
23 | if(!response.data.is_full_name_match){ |
||
24 | return { 'error' : 'Fullname does not match'} ; |
||
25 | } |
||
26 | |||
27 | if(!response.data.is_date_of_birth_match){ |
||
28 | return { 'error' : 'Date of birth does not match'} ; |
||
29 | } |
||
30 | return response; |
||
31 | }//Exclude Appruve Field Verification for this |
||
32 | |||
33 | if(idType == constants.idValues.TYPE_SSNIT){ |
||
34 | if(!response.data.is_full_name_match){ |
||
35 | return { 'error' : 'Fullname does not match'} ; |
||
36 | } |
||
37 | |||
38 | return response; |
||
39 | }//Exclude Appruve Field Verification for this |
||
40 | |||
41 | } |
||
42 | |||
43 | if(idType == constants.idValues.TYPE_TIN |
||
44 | || idType == constants.idValues.TYPE_KRA |
||
45 | || idType == constants.idValues.TELCO_SUBSCRIBER |
||
46 | ){ |
||
47 | return response; |
||
48 | }//Exclude Appruve Field Verification for this |
||
49 | |||
50 | const isVerified = this.verify(response); |
||
51 | |||
52 | if(isVerified == true){ |
||
0 ignored issues
–
show
Best Practice
introduced
by
![]() |
|||
53 | return response; |
||
54 | } |
||
55 | |||
56 | return isVerified; |
||
57 | |||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Verify Appruve information |
||
62 | * |
||
63 | * @param {object} result |
||
64 | * @return boolean |
||
65 | */ |
||
66 | verify(result){ |
||
67 | const data = result.data; |
||
68 | |||
69 | if (! data.is_first_name_match) { |
||
70 | return { 'error' : 'Firstname does not match'} ; |
||
71 | } |
||
72 | |||
73 | if (! data.is_last_name_match) { |
||
74 | return { 'error' : 'Lastname does not match'}; |
||
75 | } |
||
76 | |||
77 | if (! data.is_date_of_birth_match) { |
||
78 | return { 'error' : 'Date of birth does not match'}; |
||
79 | } |
||
80 | |||
81 | return true; |
||
82 | |||
83 | } |
||
84 | } |
||
85 | |||
86 | module.exports = AppruveValidation; |
||
87 |