-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
24 lines (20 loc) · 976 Bytes
/
index.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
const {logProcessStart, logTotalCustomersFound, logCustomerRecordFile} = require('./src/helpers/logs.js');
const intercomGetCustomers = require('./src/program/index.js');
const { join } = require('path');
const { writeFile } = require('fs');
const { promisify } = require('util');
var customerOutputFile = join(__dirname, 'output.txt');
var customerInputFile = join(__dirname, 'src/program/customers.txt');
const getCustomersWithinRequiredDistance = async (distance, latitude, longitude) => {
logProcessStart(distance);
const customers = await intercomGetCustomers.getCustomersWithinDistance(customerInputFile,latitude,longitude,distance);
logTotalCustomersFound(customers.length);
await promisify(writeFile)(
customerOutputFile,
JSON.stringify(customers)
);
logCustomerRecordFile(customerOutputFile);
}
//get the last 3 command line arguments
const args = [...process.argv.slice(3)];
getCustomersWithinRequiredDistance(...args);