Skip to content

Commit

Permalink
refcator: remove the unnecessary firebase-admin package and module
Browse files Browse the repository at this point in the history
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
KulkarniShashank committed Feb 6, 2024
1 parent 6e15546 commit 6eddaa5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 39 deletions.
8 changes: 1 addition & 7 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,5 @@ POSTGRES_HOST=
POSTGRES_ADMIN_USER=
POSTGRES_ADMIN_PASSWORD=

USE_PUSH_NOTIFICATIONS=true

FIREBASE_PROJECT_ID=
FIREBASE_PRIVATE_KEY=
FIREBASE_CLIENT_EMAIL=
FIREBASE_NOTIFICATION_TITLE=You have message from your contacts
FIREBASE_NOTIFICATION_BODY=Please open your app to read the message
USE_PUSH_NOTIFICATIONS='true'
NOTIFICATION_WEBHOOK_URL=
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"@aries-framework/node": "0.4.2",
"@hyperledger/aries-askar-nodejs": "^0.1.1",
"express": "^4.18.1",
"firebase-admin": "^11.10.1",
"prettier": "^2.8.4",
"tslog": "^3.3.3",
"tsyringe": "^4.7.0",
Expand Down
10 changes: 1 addition & 9 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ export const LOG_LEVEL = LogLevel.debug
export const IS_DEV = process.env.NODE_ENV === 'development'

export const USE_PUSH_NOTIFICATIONS = process.env.USE_PUSH_NOTIFICATIONS === 'true'
export const FIREBASE_PROJECT_ID = process.env.FIREBASE_PROJECT_ID
export const FIREBASE_PRIVATE_KEY = process.env.FIREBASE_PRIVATE_KEY
? process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n')
: undefined
export const FIREBASE_CLIENT_EMAIL = process.env.FIREBASE_CLIENT_EMAIL

export const FIREBASE_NOTIFICATION_TITLE = process.env.FIREBASE_NOTIFICATION_TITLE
export const FIREBASE_NOTIFICATION_BODY = process.env.FIREBASE_NOTIFICATION_BODY

export const NOTIFICATION_WEBHOOK_URL = process.env.NOTIFICATION_WEBHOOK_URL
export const NOTIFICATION_WEBHOOK_URL = process.env.NOTIFICATION_WEBHOOK_URL || 'http://localhost:5000'

27 changes: 5 additions & 22 deletions src/push-notifications/fcm/services/PushNotificationsFcmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ export class PushNotificationsFcmService {
connectionId,
})

// if (!pushNotificationFcmRecord?.deviceToken) {
// this.logger.info(`No device token found for connectionId so skip sending notification`)
// return
// }
if (!pushNotificationFcmRecord?.deviceToken) {
this.logger.info(`No device token found for connectionId so skip sending notification`)
return
}


// Prepare a message to be sent to the device
Expand All @@ -141,11 +141,6 @@ export class PushNotificationsFcmService {

public async processNotification(message: NotificationMessage) {
try {
if (!NOTIFICATION_WEBHOOK_URL) {
this.logger.error("Notification webhook URL not found");
return
}

const body = {
fcmToken: message.token || 'abc',
messageType: message.messageType,
Expand All @@ -159,19 +154,7 @@ export class PushNotificationsFcmService {
body: JSON.stringify(body)
};

fetch(NOTIFICATION_WEBHOOK_URL, requestOptions)
.then(response => {
if (!response.ok) {
this.logger.error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
this.logger.debug(`Data: ${data}`);
})
.catch(error => {
this.logger.error(`Error: ${error}`);
});
await fetch(NOTIFICATION_WEBHOOK_URL, requestOptions)

} catch (error) {
this.logger.error(`Error sending notification`, {
Expand Down

0 comments on commit 6eddaa5

Please sign in to comment.