-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_script.js
More file actions
84 lines (68 loc) · 2.04 KB
/
Copy pathmain_script.js
File metadata and controls
84 lines (68 loc) · 2.04 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const readline = require("readline");
const axios = require("axios");
const fs = require("fs");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question(
"Choose a document type (PAN/ICSE/CBSE/AADHAR): ",
async (documentType) => {
const fileName = await askForFileName();
// Make API call with document type and file content
const firstApiResponse = await makeFirstApiCall(documentType, fileName);
console.log("Parser result: ", firstApiResponse);
function generateRandomId() {
return Math.floor(1000 + Math.random() * 9000);
}
const randomId = generateRandomId();
let data = {
identifier: documentType,
id: randomId,
data: firstApiResponse,
};
console.log("Data: ", data);
// Make another API call with the result from the first call
const secondApiResponse = await makeSecondApiCall(data);
console.log("Result:", secondApiResponse);
console.log("Waiting....");
setTimeout(async () => {
const res = await makeSecondApiCall(data);
console.log("Verdict: ", res);
if (res.verification === "Verified") console.log("Document verified!");
else console.log("Document rejected!");
}, 3000);
rl.close();
}
);
function askForFileName() {
return new Promise((resolve, reject) => {
rl.question("Enter the file name: ", (fileName) => {
resolve(fileName);
});
});
}
async function makeFirstApiCall(documentType, filename) {
try {
const response = await axios.post("http://localhost:5000/parse_document", {
document_type: documentType,
filename: filename,
});
return response.data;
} catch (error) {
console.error("Error making first API call:", error);
process.exit(1);
}
}
async function makeSecondApiCall(data) {
try {
const response = await axios.post(
"http://localhost:4000/uploadDocument",
data
);
return response.data;
} catch (error) {
console.error("Error making second API call:", error);
process.exit(1);
}
}