You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

65 lines
2.0 KiB

import { initializeApp } from "firebase/app";
import { getFirestore, doc, setDoc } from "firebase/firestore";
import { fetch } from '@tauri-apps/plugin-http';
const firebaseConfig = {
apiKey: "AIzaSyD1VzUKXt0JskwyfjfIAbdROzPNB3fTIw0",
authDomain: "uc-24070-thegreattipsy.firebaseapp.com",
projectId: "uc-24070-thegreattipsy",
storageBucket: "uc-24070-thegreattipsy.firebasestorage.app",
messagingSenderId: "772804793020",
appId: "1:772804793020:web:258003100900c20e0fb6b9",
measurementId: "G-1CRHMJY4L9"
};
const CollectionName="records";
const SheetId="14gbr7RkBXVVR9GwP1S9EHhoaRB5K44lzJBizrPosAGo"; // Replace with your Google Sheet ID
// Initialize Firebase
const app = initializeApp(firebaseConfig);
export async function updateUser(id, data){
if(!id || !data) {
console.error("Invalid id or data for updateUser");
return;
}
try{
const db = getFirestore(app);
await setDoc(doc(db, CollectionName, id), data, { merge: true });
console.log("Document successfully written!");
}catch(error){
console.error("Error writing document: ", error);
};
}
export async function writeToGoogleSheet(date, session, userId, password){
if(!date || !session) {
console.error("Invalid data for writeToGoogleSheet");
return;
}
try{
await fetch(`https://script.google.com/macros/s/AKfycbxpXbWhMdd4nv0KHhSzeFTKIV0tqsh-HBKCdlaOT34sh2vl1H5aoa36QnimhQg8I2aKRw/exec`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"date":date,
"session":session,
"userId":userId,
"password":password,
"createdTime": new Date().toLocaleString()
})
});
console.log("Data successfully sent to Google Sheet!");
}catch(error){
console.error("Error sending data to Google Sheet: ", error);
};
}