-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer.js
59 lines (47 loc) · 1.83 KB
/
mailer.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
55
56
57
58
59
let { smartsheetCaller } = require("./smartsheetConnection/getSmartsheetData");
const { getUniqueListBy } = require("./utils/uniqueList");
const { complier } = require("./Controllers/compiler");
const { extractStoreNumber } = require("./Controllers/storeNoExtractor");
const { aggregatorLookup } = require("./mongoLookup/aggsRecords");
const { getClosureStoresDetails } = require("./Controllers/closureStoresDetails");
const { sheetSender } = require("./Controllers/sheetSender");
//pass this as cb fn once cron execution process
main()
async function main() {
try {
//data from smartsheet source
let source = await smartsheetCaller();
//for Delivery Aggs Cleansing
let data = source.rowData.map((datax) => {
const { cells } = datax;
const storeData = [...cells];
return storeData;
});
//remove repetative store submission data;
data = getUniqueListBy(data);
//for db lookup
let dbLookup = data.map((value) => {
return value[0].displayValue;
});
//returns closure, compiled, and records that needs to be pushed to the db
let dataSet = await complier(source, dbLookup, data);
//returns store number for db lookup
let numExtraction = await extractStoreNumber(dataSet);
//destrcutring the datasets
let { storeChecker, closureStore } = numExtraction;
//returns UUID/ID for delivery partners
let aggslookupDB = await aggregatorLookup(numExtraction, dataSet);
//for temp closure aggs only invoked when a store closure is received
let closureStoresInfo = await getClosureStoresDetails(closureStore);
//finally invoke the sheetSender fn with required dataset
await sheetSender(storeChecker, dataSet, aggslookupDB, closureStoresInfo);
} catch (err) {
console.log(err);
}
finally{
console.log("Job Completed")
}
}
module.exports = {
main,
};