-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase.js
43 lines (34 loc) · 1.14 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
import {
initializeApp
} from "https://www.gstatic.com/firebasejs/9.6.4/firebase-app.js";
import {
getFirestore,
collection,
addDoc,
getDocs,
onSnapshot,
deleteDoc,
doc,
getDoc,
updateDoc
} from "https://www.gstatic.com/firebasejs/9.6.4/firebase-firestore.js";
const firebaseConfig = {
apiKey: "AIzaSyCcbta16xkYb4SL_210Vjqy5mhzVQd7bzQ",
authDomain: "crud-js-ac615.firebaseapp.com",
projectId: "crud-js-ac615",
storageBucket: "crud-js-ac615.appspot.com",
messagingSenderId: "656728936289",
appId: "1:656728936289:web:d5809dc8248f5650d7ff20"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore();
export const guardarPost = (titulo, descripcion) =>
addDoc(collection(db, "posteos"), {
titulo,
descripcion
})
export const getPosteos = () => getDocs(collection(db, "posteos"));
export const onGetPosteos = (callback) => onSnapshot(collection(db, "posteos"), callback);
export const eliminarPosteo = id => deleteDoc(doc(db, 'posteos', id));
export const getPost = id => getDoc(doc(db, 'posteos', id));
export const actualizarPosteo = (id, nuevoPosteo) => updateDoc(doc(db, 'posteos', id), nuevoPosteo);