functions
This commit is contained in:
@@ -13,10 +13,16 @@ const resendInstance = new Resend(RESEND_API_KEY);
|
||||
|
||||
// Initialisation de Expo SDK
|
||||
let expo = new Expo();
|
||||
const db = admin.firestore();
|
||||
|
||||
const EMAIL_FROM = "MusicLand <musicland@minuit.app>";
|
||||
|
||||
function getCollectionRef(collectionName = "") {
|
||||
const ref = refList?.[collectionName];
|
||||
if (!ref) {
|
||||
throw new Error(`Unknown collection "${collectionName}"`);
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
|
||||
exports.sendNotificationWhenDocIsCreated = onDocumentCreated(
|
||||
{ region: "europe-west1", document: "notifications/{notificationId}" },
|
||||
async (event) => {
|
||||
@@ -34,12 +40,17 @@ exports.sendNotificationWhenDocIsCreated = onDocumentCreated(
|
||||
throw new Error("Receiver and message are required");
|
||||
}
|
||||
|
||||
const receiverSnap = await getCollectionRef(receiverCollection)
|
||||
.doc(receiver)
|
||||
.get();
|
||||
const receiverData = receiverSnap.exists ? receiverSnap.data() : {};
|
||||
|
||||
const {
|
||||
pushToken = null,
|
||||
pushTokens = [],
|
||||
email = "",
|
||||
emailNotifications = false,
|
||||
} = (await db.collection(receiverCollection).doc(receiver).get()).data();
|
||||
} = receiverData;
|
||||
|
||||
if (!mailOnly) {
|
||||
const tokensSet = new Set(
|
||||
@@ -193,7 +204,7 @@ async function removeInvalidTokens({
|
||||
return;
|
||||
}
|
||||
|
||||
const docRef = db.collection(receiverCollection).doc(receiverId);
|
||||
const docRef = getCollectionRef(receiverCollection).doc(receiverId);
|
||||
const userSnap = await docRef.get();
|
||||
const userData = userSnap?.data() || {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user