Skip to content

Commit

Permalink
Fixed deploy error
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-nirali-s committed Dec 3, 2024
1 parent 731bc96 commit 3b8b9d4
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
2 changes: 2 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
{
"source": "functions",
"codebase": "default",
"timeoutSeconds": 300,
"runtime": "nodejs18",
"ignore": [
"node_modules",
".git",
Expand Down
16 changes: 16 additions & 0 deletions functions/firestore-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Dec 02, 2024 6:45:43 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
INFO: Started WebSocket server on ws://127.0.0.1:9150
API endpoint: http://127.0.0.1:8080
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

export FIRESTORE_EMULATOR_HOST=127.0.0.1:8080

If you are running a Firestore in Datastore Mode project, run:

export DATASTORE_EMULATOR_HOST=127.0.0.1:8080

Note: Support for Datastore Mode is in preview. If you encounter any bugs please file at https://github.com/firebase/firebase-tools/issues.
Dev App Server is now running.

*** shutting down gRPC server since JVM is shutting down
*** server shut down
4 changes: 2 additions & 2 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (admin.apps.length === 0) {
}
} else {
logger.debug('Firebase app already initialized');
}
}

exports.onGroupWrite = onGroupWrite;
exports.onActivityCreate = onActivityCreate;
exports.onActivityCreate = onActivityCreate;
10 changes: 8 additions & 2 deletions functions/src/notifications_service/notifications_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import * as admin from "firebase-admin";
import * as logger from "firebase-functions/logger";
import messages from '../locales/en.json';

// Initialize Firebase app if not already initialized
// Initialize Firebase app in users_service.ts to ensure it's always available
if (admin.apps.length === 0) {
admin.initializeApp();
try {
admin.initializeApp();
logger.info('Firebase app initialized in notifications_service');
} catch (error) {
logger.error('Failed to initialize Firebase app in notifications_service:', error);
throw error;
}
}

const db: Firestore = getFirestore();
Expand Down
14 changes: 9 additions & 5 deletions functions/src/users_service/users_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import * as admin from 'firebase-admin';
import { onDocumentWritten } from 'firebase-functions/v2/firestore';
import * as logger from 'firebase-functions/logger';
import * as _ from 'lodash';

// Initialize Firebase app if not already initialized
// Initialize Firebase app in users_service.ts to ensure it's always available
if (admin.apps.length === 0) {
admin.initializeApp();
try {
admin.initializeApp();
logger.info('Firebase app initialized in users_service');
} catch (error) {
logger.error('Failed to initialize Firebase app in users_service:', error);
throw error; // Prevent further function execution
}
}

const db = admin.firestore();
Expand Down Expand Up @@ -38,8 +43,7 @@ export const onGroupWrite = onDocumentWritten(
}

// Check if balances field changed
if (!_.isEqual(beforeData.balances, afterData.balances)) {

if (beforeData.balances != afterData.balances) {
const olderBalances = beforeData.balances || [];
const updatedBalances = afterData.balances || [];

Expand Down
6 changes: 5 additions & 1 deletion functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"noImplicitReturns": true,
"noUnusedLocals": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"outDir": "lib",
"sourceMap": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"target": "ES2020"
},
Expand All @@ -15,6 +18,7 @@
"src"
],
"exclude": [
"node_modules"
"node_modules",
"lib"
]
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
"dependencies": {
"firebase-admin": "^13.0.1",
"firebase-functions": "^6.1.1"
},
"devDependencies": {
"typescript": "^5.7.2"
},
"scripts": {
"build": "tsc"
}
}

0 comments on commit 3b8b9d4

Please sign in to comment.