Skip to content

Commit

Permalink
Merge pull request #1 from Cancogang69/tiendat-base-server
Browse files Browse the repository at this point in the history
base server
  • Loading branch information
cancogang69 authored Dec 27, 2023
2 parents 0527868 + 7d5417f commit 1e7c0b7
Show file tree
Hide file tree
Showing 6 changed files with 10,263 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
61 changes: 61 additions & 0 deletions Database/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
import { getFirestore, collection, getDocs } from 'firebase/firestore';
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyBKvPY1Oxu3Tl2pr58WYJG_uYkTHHUIB5E",
authDomain: "groupplanning-2d3e0.firebaseapp.com",
projectId: "groupplanning-2d3e0",
storageBucket: "groupplanning-2d3e0.appspot.com",
messagingSenderId: "586489896437",
appId: "1:586489896437:web:1b2e9812ad9a76a551d4bc",
measurementId: "G-FVDXWR2RNT"
};



const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

const UsersCollectionRef = collection(db, "userData");


export async function addUserData(userData) {
try {
const docRef = await addDoc(UsersCollectionRef, userData);
console.log("Document written with ID: ", docRef.id);
} catch (e) {
console.error("Error adding document: ", e);
}
}


export async function getUserData() {
try {
const querySnapshot = await getDocs(UsersCollectionRef);
const users = [];
querySnapshot.forEach((doc) => {
console.log(doc.id, " => ", doc.data());
users.push(doc.data());
});
return users;
} catch (e) {
console.error("Error getting documents: ", e);
}
}

export async function updateUserData(userId, updatedData) {
try {
const userDocRef = doc(db, "userData", userId);
await updateDoc(userDocRef, updatedData);
console.log("Document updated with ID: ", userId);
} catch (e) {
console.error("Error updating document: ", e);
}
}

12 changes: 12 additions & 0 deletions connection_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import io from 'socket.io-client';

const socket = io('http://localhost:4000');

function test_server(){
socket.on('connect', () => {
console.log('Connected to server');
});

}

test_server()
Loading

0 comments on commit 1e7c0b7

Please sign in to comment.