1 | const IdVerification = require('./src/services/IdVerification'); |
||
2 | const services = require('./src/config/services'); |
||
3 | const { isString } = require('./src/classes/Helper'); |
||
4 | const { idValues } = require('./src/config/constants'); |
||
5 | const { countries } = require('./src/classes/Helper'); |
||
6 | |||
7 | class SabiCustomer{ |
||
8 | |||
9 | async verifyID(requestData = {}, handler = null){ |
||
10 | |||
11 | //Checks whether Handler is valid |
||
12 | if(handler != null){ |
||
0 ignored issues
–
show
Best Practice
introduced
by
![]() |
|||
13 | if(!isString(handler)){ |
||
14 | return { 'error' : handler + ' is not a valid string' }; |
||
15 | } |
||
16 | |||
17 | const pipes = [ |
||
18 | services.credequity.client.toUpperCase(), |
||
19 | services.appruve.client.toUpperCase(), |
||
20 | services.smile.client.toUpperCase() |
||
21 | ]; |
||
22 | |||
23 | if(!pipes.includes(handler.toUpperCase())){ |
||
24 | return { 'error' : handler + ' is not a valid handler' }; |
||
25 | } |
||
26 | } |
||
27 | |||
28 | if(Object.keys(requestData).length <= 0 ){ |
||
29 | return { 'error' : 'Payload must not be empty'}; |
||
30 | } |
||
31 | |||
32 | const idValue = Object.values(idValues); |
||
33 | |||
34 | //Checks for valid ID Types |
||
35 | if(!idValue.includes(requestData.id_type)){ |
||
36 | return { 'error' : requestData.id_type + ' is not supported or not a valid ID TYPE, supported types: ' + idValue }; |
||
37 | } |
||
38 | |||
39 | const supportedCountries = Object.values(countries); |
||
40 | |||
41 | //Checks for supported country |
||
42 | if(!supportedCountries.includes(requestData.country)){ |
||
43 | return { 'error' : requestData.country + ' is not a valid country or not supported, supported countries are: ' + supportedCountries }; |
||
44 | } |
||
45 | |||
46 | const idVerification = new IdVerification(requestData); |
||
47 | |||
48 | return await idVerification.verify(handler); |
||
49 | |||
50 | } |
||
51 | } |
||
52 | |||
53 | module.exports = SabiCustomer; |