-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Cancogang69/tiendat-base-server
base server
- Loading branch information
Showing
6 changed files
with
10,263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.