-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (34 loc) · 1.28 KB
/
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
25
26
27
28
29
30
31
32
33
34
35
36
require('dotenv').config();
const logger = require('./logger');
const { importDataFromCSV } = require('./import');
const {
loadResult, upsertEvent, upsertMatch, upsertPlayer,
} = require('./store/supabase');
const main = async (path) => {
logger.info(`Importing file ${path}...`);
const { players, matches, results } = await importDataFromCSV(path);
logger.info(`File ${path} imported: ${players.length} players; ${matches.length} matches; ${results.length} records...`);
if (process.env.USER) {
for (let index = 0; index < players.length; index += 1) {
const player = players[index];
await upsertPlayer(player.Players);
}
logger.info('all players imported/updated...');
}
if (process.env.MATCHES) {
for (let index = 0; index < matches.length; index += 1) {
const match = matches[index];
await upsertEvent(match.eventName, match.eventYear);
await upsertMatch(match.eventName, match.eventYear, match.id, match.winner, match.loser);
}
logger.info('all events/matches imported/updated...');
}
if (process.env.RESULTS) {
for (let index = 0; index < results.length; index += 1) {
const result = results[index];
await loadResult(result);
}
logger.info('success importing all results...');
}
};
module.exports = main;