functions

This commit is contained in:
Thomas Demirdjian
2025-11-03 13:47:07 +01:00
parent 460c91f1e6
commit 7b3a47090d
16 changed files with 23868 additions and 2399 deletions
+15 -4
View File
@@ -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() || {};