Created
April 20, 2022 01:05
-
-
Save mattbajorek/377e30c724494ca33e5260bd4bca1613 to your computer and use it in GitHub Desktop.
sendAll wrapper
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
import { Injectable } from '@nestjs/common'; | |
import * as firebase from 'firebase-admin'; | |
import { BatchResponse } from 'firebase-admin/lib/messaging/messaging-api'; | |
import * as shell from 'shelljs'; | |
@Injectable() | |
export class NotificationsService { | |
... | |
public async sendAll(messages: firebase.messaging.TokenMessage[], dryRun?: boolean): Promise<BatchResponse> { | |
if (process.env.NODE_ENV === 'local') { | |
for (const { notification, token } of messages) { | |
shell.exec( | |
`echo '{ "aps": { "alert": ${JSON.stringify(notification)}, "token": "${token}" } }' | xcrun simctl push booted com.company.appname -`, | |
); | |
} | |
} | |
return firebase.messaging().sendAll(messages, dryRun); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment