-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirebase.js
81 lines (62 loc) · 2.09 KB
/
Firebase.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { initializeApp } from 'firebase/app';
import { getAuth } from "firebase/auth";
import { getDatabase, push, ref, set, update } from "firebase/database";
const firebaseConfig = {
apiKey: "AIzaSyCWk2EKd0342I82gVHHpDNQYCzdGTjo5Ew",
authDomain: "breathanalyzer-db8fb.firebaseapp.com",
databaseURL: "https://breathanalyzer-db8fb-default-rtdb.firebaseio.com",
projectId: "breathanalyzer-db8fb",
storageBucket: "breathanalyzer-db8fb.appspot.com",
messagingSenderId: "444177996622",
appId: "1:444177996622:web:3e2ea687b31085fb2adc1f",
measurementId: "G-YNESQV4MPD",
databaseURL: "https://breathanalyzer-db8fb-default-rtdb.firebaseio.com/"
};
const app = initializeApp(firebaseConfig)
const authen = getAuth(app);
// const reference =
const database = getDatabase(app);
function createUserData(userId, name, email){
set(ref(database, 'users/' + userId), {
name: name,
email: email
})
}
function pairDevice(userID){
set(ref(database, 'users/currPairingUID/'), userID);
}
function unPair(userID){
update(ref(database, "/users/"), {
currPairingUID: null
})
}
function updateSettings(userID, isDarkMode){
console.log(userID);
set(ref(database, 'users/' + userID + '/settings'), {
isDarkMode: isDarkMode
})
}
function writeHealthData(dataType, key, val){
const dataListRef = ref(database, 'users/' + authen.currentUser.uid + '/data/' + dataType + '/' + key);
let temp = parseFloat(val);
set(dataListRef, temp);
}
function editKey(dataType, key, value){
}
function editValue(dataType, key, value){
}
const getStringDate = (d) => {
let date = new Date(d);
let month = date.getMonth() + 1;
let day = date.getDate();
let year = date.getFullYear();
return (month + "/" + day + "/" + year);
}
export function clearSpecData(type){
set(ref(database, 'users/' + authen.currentUser.uid + '/data/' + type), {
})
}
let test = getStringDate("02-01-1997T11:08");
console.log(test);
export { authen, database, writeHealthData,
createUserData, pairDevice, unPair, updateSettings, editKey, editValue};