-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ts
37 lines (28 loc) · 1.32 KB
/
setup.ts
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
import { createClient } from "@supabase/supabase-js";
import { getAccessToken, getRankedMaps, getQualifiedMaps, getLatestEvent } from "./osuRequests";
import { adjustAllRankDates } from "./osuHelpers";
import { beatmapSetToDatabase } from "./utils";
import { Database } from "./database.types";
require("dotenv").config();
const supabase = createClient<Database>(process.env.SUPABASE_URL!, process.env.SERVICE_ROLE!);
export const setUp = async () => {
const [accessToken, expireDate] = await getAccessToken();
const lastEventId = await getLatestEvent(accessToken);
const rankedMaps = await getRankedMaps(accessToken);
const qualifiedMaps = await getQualifiedMaps(accessToken);
adjustAllRankDates(qualifiedMaps, rankedMaps);
let { error: errorAppData } = await supabase
.from("app_data")
.insert([
{ id: 1, access_token: accessToken, expire_date: expireDate, last_event_id: lastEventId },
])
.select();
if (errorAppData) console.log(errorAppData);
const combinedMaps = qualifiedMaps.flat().concat(rankedMaps.flat());
const formattedData = combinedMaps.map((beatmapSet) => beatmapSetToDatabase(beatmapSet));
let { error: errorBeatmapSets } = await supabase.from("beatmapsets").insert(formattedData);
if (errorBeatmapSets) console.log(errorBeatmapSets);
};
if (require.main === module) {
setUp();
}