Skip to content

Commit

Permalink
Implemented: general basic methods for get and add data to firebase (…
Browse files Browse the repository at this point in the history
…382-firestoreConfig)
  • Loading branch information
amansinghbais committed Jan 12, 2024
1 parent 82e8b7c commit 04168ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useProductIdentificationStore } from "./store/productIdentification";
import { useAuthStore } from "./store/auth";
import { DxpAppVersionInfo, DxpImage, DxpLanguageSwitcher, DxpLogin, DxpMenuFooterNavigation, DxpOmsInstanceNavigator, DxpProductIdentifier, DxpShopifyImg, DxpUserProfile } from "./components";
import { goToOms, getProductIdentificationValue } from "./utils";
import { initialiseFirebaseApp } from "./utils/firebase"
import { addDocument, getDocument, initialiseFirebaseApp, updateDocument } from "./utils/firebase"
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { createI18n } from 'vue-i18n'
import { useUserStore } from "./store/user";
Expand Down Expand Up @@ -103,13 +103,15 @@ export let dxpComponents = {

export {
appContext,
addDocument,
DxpImage,
DxpLogin,
DxpMenuFooterNavigation,
DxpOmsInstanceNavigator,
DxpProductIdentifier,
DxpShopifyImg,
DxpUserProfile,
getDocument,
getProductIdentificationValue,
goToOms,
i18n,
Expand All @@ -120,6 +122,7 @@ export {
productIdentificationContext,
shopifyImgContext,
translate,
updateDocument,
useAuthStore,
useProductIdentificationStore,
useUserStore,
Expand Down
23 changes: 20 additions & 3 deletions src/utils/firebase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { initializeApp } from "firebase/app";
import { getMessaging, getToken, onMessage } from "firebase/messaging";
import { defineStore } from "pinia";
import { doc, getFirestore, getDoc, setDoc, updateDoc } from "firebase/firestore";

let app;
let database = {} as any

const initialiseFirebaseApp = async (
appFirebaseConfig: any,
Expand All @@ -12,6 +14,7 @@ const initialiseFirebaseApp = async (
const firebaseConfig = appFirebaseConfig

app = initializeApp(firebaseConfig);
database = getFirestore(app);

// Check for notifications required only in bopis app.
if(addNotification) {
Expand All @@ -38,10 +41,24 @@ const initialiseFirebaseApp = async (
alert("You denied notifications.");
}
}
console.log(app);

};

const getDocument = async (collection: any, document: any) => {
const querySnapshot = await getDoc(doc(database, collection, document));
return querySnapshot.data()
}

const addDocument = async (collection: any, document: any, data: any) => {
return await setDoc(doc(database, collection, document), data);
}

const updateDocument = async (collection: any, document: any, data: any) => {
return await updateDoc(doc(database, collection, document), data);
}

export {
addDocument,
initialiseFirebaseApp,
getDocument,
updateDocument
}

0 comments on commit 04168ae

Please sign in to comment.