Avoiding recursive references
This commit is contained in:
parent
370573de1a
commit
59bc1fde6b
@ -1,2 +1,2 @@
|
|||||||
export * from './sendEmail';
|
export { sendEmailMessage } from './sendEmail';
|
||||||
export * from './sendEmailWithAttachment';
|
export { sendEmailWithAttachment } from './sendEmailWithAttachment';
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
export * from './shared/config';
|
export * from './shared/config';
|
||||||
export * from './email';
|
export { sendEmailMessage, sendEmailWithAttachment } from './email';
|
||||||
export * from './storage';
|
export { accessFile } from './storage';
|
||||||
export * from './sms';
|
export { sendSMSMessage } from './sms';
|
||||||
export * from './notifications';
|
export { processNotificationOnCreate } from './notifications';
|
||||||
export * from './payments';
|
export { createCashfreeLink, createCashfreeOrder, verifyCashfreePayment } from './payments';
|
||||||
export * from './places';
|
export { getPlaceDetails, getPlacesAutocomplete } from './places';
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export * from './processNotification';
|
export { processNotificationOnCreate } from './processNotification';
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
import { onDocumentCreated } from "firebase-functions/v2/firestore";
|
import { onDocumentCreated } from "firebase-functions/v2/firestore";
|
||||||
import { logger } from "../shared/config";
|
import { getLogger } from "../shared/config";
|
||||||
import { admin } from "../shared/config";
|
import { getAdmin } from "../shared/config";
|
||||||
|
import * as admin from 'firebase-admin';
|
||||||
|
|
||||||
|
const app = getAdmin();
|
||||||
|
const logger = getLogger();
|
||||||
|
|
||||||
interface NotificationData {
|
interface NotificationData {
|
||||||
notificationSent?: boolean;
|
notificationSent?: boolean;
|
||||||
@ -49,7 +53,7 @@ export const processNotificationOnCreate = onDocumentCreated({
|
|||||||
|
|
||||||
const message = prepareNotificationMessage(notification, fcmToken);
|
const message = prepareNotificationMessage(notification, fcmToken);
|
||||||
try {
|
try {
|
||||||
const fcmResponse = await admin.messaging().send({
|
const fcmResponse = await app.messaging().send({
|
||||||
...message,
|
...message,
|
||||||
token: fcmToken
|
token: fcmToken
|
||||||
});
|
});
|
||||||
@ -80,7 +84,7 @@ async function getUserAndFCMToken(notification: NotificationData): Promise<{ use
|
|||||||
userId = notification.invitorId;
|
userId = notification.invitorId;
|
||||||
fcmToken = await getFCMTokenFromUserDoc(userId);
|
fcmToken = await getFCMTokenFromUserDoc(userId);
|
||||||
} else if (notification.phoneNumber) {
|
} else if (notification.phoneNumber) {
|
||||||
const userQuery = await admin
|
const userQuery = await app
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('users')
|
.collection('users')
|
||||||
.where('phoneNumber', '==', notification.phoneNumber)
|
.where('phoneNumber', '==', notification.phoneNumber)
|
||||||
@ -98,7 +102,7 @@ async function getUserAndFCMToken(notification: NotificationData): Promise<{ use
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getFCMTokenFromUserDoc(userId: string): Promise<string | null> {
|
async function getFCMTokenFromUserDoc(userId: string): Promise<string | null> {
|
||||||
const userDoc = await admin.firestore().collection('users').doc(userId).get();
|
const userDoc = await app.firestore().collection('users').doc(userId).get();
|
||||||
return userDoc.exists ? userDoc.data()?.fcmToken : null;
|
return userDoc.exists ? userDoc.data()?.fcmToken : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,15 +208,15 @@ function getInvitationBody(status: string, name?: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function markNotificationAsSent(notificationId: string): Promise<void> {
|
async function markNotificationAsSent(notificationId: string): Promise<void> {
|
||||||
await admin.firestore().collection('notifications').doc(notificationId).update({
|
await app.firestore().collection('notifications').doc(notificationId).update({
|
||||||
notificationSent: true,
|
notificationSent: true,
|
||||||
sentAt: admin.firestore.FieldValue.serverTimestamp()
|
sentAt: app.firestore.FieldValue.serverTimestamp()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateNotificationWithError(notificationId: string, error: string): Promise<void> {
|
async function updateNotificationWithError(notificationId: string, error: string): Promise<void> {
|
||||||
await admin.firestore().collection('notifications').doc(notificationId).update({
|
await app.firestore().collection('notifications').doc(notificationId).update({
|
||||||
notificationError: error,
|
notificationError: error,
|
||||||
updatedAt: admin.firestore.FieldValue.serverTimestamp()
|
updatedAt: app.firestore.FieldValue.serverTimestamp()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
import { onRequest } from "firebase-functions/v2/https";
|
import { onRequest } from "firebase-functions/v2/https";
|
||||||
import { Request } from "firebase-functions/v2/https";
|
import { Request } from "firebase-functions/v2/https";
|
||||||
import { corsHandler } from "../../shared/middleware";
|
import { getCorsHandler } from "../../shared/middleware";
|
||||||
import { admin, logger } from "../../shared/config";
|
import { getAdmin, getLogger } from "../../shared/config";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
const { v4: uuidv4 } = require('uuid');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
|
const corsHandler = getCorsHandler();
|
||||||
|
const admin = getAdmin();
|
||||||
|
const logger = getLogger();
|
||||||
|
|
||||||
interface CashfreeLinkRequest {
|
interface CashfreeLinkRequest {
|
||||||
amount: number;
|
amount: number;
|
||||||
customerName?: string;
|
customerName?: string;
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export * from './createOrder';
|
export { createCashfreeLink } from './createLink';
|
||||||
export * from './createLink';
|
export { verifyCashfreePayment } from './verifyPayment';
|
||||||
export * from './verifyPayment';
|
export { createCashfreeOrder } from './createOrder';
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
import { onRequest } from "firebase-functions/v2/https";
|
import { onRequest } from "firebase-functions/v2/https";
|
||||||
import { Request } from "firebase-functions/v2/https";
|
import { Request } from "firebase-functions/v2/https";
|
||||||
import * as express from "express";
|
import * as express from "express";
|
||||||
import { logger } from "../shared/config";
|
import { getLogger } from "../shared/config";
|
||||||
|
import { getCorsHandler } from "../shared/middleware";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { corsHandler } from "../shared/middleware";
|
|
||||||
|
const logger = getLogger();
|
||||||
|
const corsHandler = getCorsHandler();
|
||||||
|
|
||||||
export const getPlacesAutocomplete = onRequest({
|
export const getPlacesAutocomplete = onRequest({
|
||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
import { onRequest } from "firebase-functions/v2/https";
|
import { onRequest } from "firebase-functions/v2/https";
|
||||||
import { Request } from "firebase-functions/v2/https";
|
import { Request } from "firebase-functions/v2/https";
|
||||||
import * as express from "express";
|
import * as express from "express";
|
||||||
import * as logger from "firebase-functions/logger";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { corsHandler } from "../shared/middleware";
|
|
||||||
|
const corsHandler = require('../shared/middleware').corsHandler;
|
||||||
|
const logger = require('../shared/config').getLogger();
|
||||||
|
|
||||||
|
|
||||||
export const getPlaceDetails = onRequest({
|
export const getPlaceDetails = onRequest({
|
||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
export * from './autocomplete';
|
export { getPlaceDetails } from './details';
|
||||||
export * from './details';
|
export { getPlacesAutocomplete } from './autocomplete';
|
||||||
|
|||||||
@ -5,4 +5,5 @@ if (!admin.apps.length) {
|
|||||||
admin.initializeApp();
|
admin.initializeApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
export { admin, logger };
|
export const getAdmin = () => admin;
|
||||||
|
export const getLogger = () => logger;
|
||||||
@ -1,3 +1,3 @@
|
|||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
|
|
||||||
export const corsHandler = cors({ origin: true });
|
export const getCorsHandler = () => cors({ origin: true });
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export * from './sendSMS';
|
export { sendSMSMessage } from './sendSMS';
|
||||||
@ -1,9 +1,12 @@
|
|||||||
import { onRequest } from "firebase-functions/v2/https";
|
import { onRequest } from "firebase-functions/v2/https";
|
||||||
import { Request } from "firebase-functions/v2/https";
|
import { Request } from "firebase-functions/v2/https";
|
||||||
import { corsHandler } from "../shared/middleware";
|
import { getCorsHandler } from "../shared/middleware";
|
||||||
import { logger } from "../shared/config";
|
import { getLogger } from "../shared/config";
|
||||||
import twilio from 'twilio';
|
import twilio from 'twilio';
|
||||||
|
|
||||||
|
const corsHandler = getCorsHandler();
|
||||||
|
const logger = getLogger();
|
||||||
|
|
||||||
// Initialize Twilio client
|
// Initialize Twilio client
|
||||||
const twilioClient = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
|
const twilioClient = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
import { onRequest } from "firebase-functions/v2/https";
|
import { onRequest } from "firebase-functions/v2/https";
|
||||||
import { Request } from "firebase-functions/v2/https";
|
import { Request } from "firebase-functions/v2/https";
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { corsHandler } from "../shared/middleware";
|
import { getCorsHandler } from "../shared/middleware";
|
||||||
import { admin, logger } from "../shared/config";
|
import { getLogger, getAdmin } from "../shared/config";
|
||||||
|
|
||||||
|
const corsHandler = getCorsHandler();
|
||||||
|
const admin = getAdmin();
|
||||||
|
const logger = getLogger();
|
||||||
|
|
||||||
export const accessFile = onRequest({
|
export const accessFile = onRequest({
|
||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export * from './accessFile';
|
export { accessFile } from './accessFile';
|
||||||
Loading…
Reference in New Issue
Block a user