-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (56 loc) · 1.75 KB
/
script.js
File metadata and controls
64 lines (56 loc) · 1.75 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
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getFirestore, setDoc, getDoc, doc } from "firebase/firestore";
import "dotenv/config";
import stations from "./stations.json" assert { type: "json" };
const firebaseConfig = {
apiKey: process.env.FIREBASE_API_KEY,
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
projectId: process.env.FIREBASE_PROJECT_ID,
storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.FIREBASE_APP_ID,
measurementId: process.env.FIREBASE_MEASUREMENT_ID
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const collectionName = "allStations";
class subwayStation {
constructor(id, location, name) {
this.id = id;
this.location = location;
this.name = name;
}
async save() {
try {
await setDoc(doc(db, collectionName, this.id), {
id: this.id,
location: this.location,
name: this.name,
});
}
catch (e) {
console.error(e);
}
}
async get() {
try {
const docSnap = await getDoc(doc(db, collectionName, this.id));
if (docSnap.exists()) {
const data = docSnap.data();
return data;
}
else {
console.error("No such document!");
}
}
catch (e) {
console.error(e);
}
}
}
for (let station in stations) {
const newStation = new subwayStation(stations[station].id, stations[station].location, stations[station].name);
newStation.save();
}