-
Notifications
You must be signed in to change notification settings - Fork 0
/
tid.js
54 lines (45 loc) · 1.68 KB
/
tid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const soap = require('soap');
//Checking people with their real ID and infos (name, surname)
function isCorrect(infos){
const verifyString = 'https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?WSDL';
infos.Ad = infos.Ad.toLocaleUpperCase('tr-TR');
infos.Soyad = infos.Soyad.toLocaleUpperCase('tr-TR');
return new Promise((resolve, reject) => {
if(infos.Ad == undefined || infos.Soyad == undefined || infos.TCKimlikNo == undefined || infos.DogumYili == undefined){
const err = new Error('Please enter your info object like this. {Ad: string, Soyad: string, TCKimlikNo: number, DogumYili: number}');
reject(err);
}
soap.createClient(verifyString, function (err, client) {
if(err){
const err = new Error('Something happened while ID checking.');
reject(err);
}else{
client.TCKimlikNoDogrula(infos, function(err, result){
if(err){
const err = new Error('Something happened while ID checking.');
reject(err);
}else{
resolve({result: result.TCKimlikNoDogrulaResult, data: infos});
}
})
}
});
});
}
//Checks the Turkish ID rule (11 length, last digit % 2 = 0)
function isRuleOK(id) {
id = String(id);
if(isNaN(parseInt(id))) {
return {result: false, id};
}else{
const lastDigit = String(id).slice(-1);
if(id.length == 11 && (lastDigit % 2) == 0)
return {result: true, id}
else
return {result: false, id}
}
}
module.exports = {
isCorrect,
isRuleOK
}