-
Notifications
You must be signed in to change notification settings - Fork 2
/
methods.js
54 lines (40 loc) · 1.91 KB
/
methods.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
import { getAuth,GoogleAuthProvider} from "firebase/auth";//'https://www.gstatic.com/firebasejs/9.10.0/firebase-auth.js'
import {db} from "./config.js";
import { collection, addDoc ,query,where,getDocs} from "firebase/firestore";//"https://www.gstatic.com/firebasejs/9.10.0/firebase-firestore.js";
const auth = getAuth();
const provider = new GoogleAuthProvider();
let isNewUser = false; //global variable isNewUser intialized to true
const environment = "prod"; // NOTE : Change environment to "prod" before deployment
const users_collection = "users";
const tasks_collection = "tasks";
const volunteers_collection = "volunteers";
const organisations_collection = "organisations";
const task_images_storage_path = "task_images/";
if(environment == "dev"){
console.log("Environment is set to development. Please change to prod before deployment");
}
async function addNewDoc(db_collection,db_doc){
try{
//const redirectHTML = await getPage(pageHTML); // Do we need this?
//window.location = top_level_url + redirectHTML;
const docRef = await addDoc(collection(db,db_collection), db_doc);
console.log("Document written with ID: ", docRef.id);
}
catch(error){
console.error("Error adding document: ", error);
throw error;
}
}
async function query_db(query_field,query_operator,query_value,db_collection){
try{
const query_res = query(collection(db, db_collection), where(query_field, query_operator, query_value));
const querySnapshot = await getDocs(query_res);
//const querySnapshot = await getDocs(query_res);
return querySnapshot;
}
catch(error){
console.error("Error querying document: ", error);
throw error;
}
}
export {addNewDoc,query_db,users_collection,organisations_collection,auth,provider,environment,isNewUser,tasks_collection,task_images_storage_path,volunteers_collection};