Skip to content

Commit

Permalink
Deploy function
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-mayank committed Sep 16, 2024
1 parent 8126795 commit 77eba88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
13 changes: 7 additions & 6 deletions khelo/functions/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

Object.defineProperty(exports, "__esModule", {value: true});
Object.defineProperty(exports, "__esModule", { value: true });
exports.fiveMinuteCron = exports.teamPlayerChangeObserver = exports.TIMEZONE = void 0;

const app_1 = require("firebase-admin/app");
Expand All @@ -11,6 +11,7 @@ const scheduler = require("firebase-functions/v2/scheduler");
const team_repository = require("./team/team_repository");
const user_repository = require("./user/user_repository");
const match_repository = require("./match/match_repository");
const mail_repository = require("./mail/mail_repository");

const notification_service = require("./notification/notification_service");
const team_service = require("./team/team_service");
Expand All @@ -22,18 +23,19 @@ exports.TIMEZONE = "Asia/Kolkata";
const REGION = "asia-south1";
const app = (0, app_1.initializeApp)();
const db = (0, firestore_1.getFirestore)(app);
const {onCall} = require("firebase-functions/v2/https");
const { onCall } = require("firebase-functions/v2/https");

const userRepository = new user_repository.UserRepository(db);
const teamRepository = new team_repository.TeamRepository(db);
const mailRepository = new mail_repository.MailRepository(db);

const notificationService = new notification_service.NotificationService(userRepository);
const teamService = new team_service.TeamService(userRepository, notificationService);
const matchService = new match_service.MatchService(userRepository, teamRepository, notificationService);

const matchRepository = new match_repository.MatchRepository(db, matchService);

exports.teamPlayerChangeObserver = (0, firestore_2.onDocumentUpdated)({region: REGION, document: "teams/{teamId}"}, async (event) => {
exports.teamPlayerChangeObserver = (0, firestore_2.onDocumentUpdated)({ region: REGION, document: "teams/{teamId}" }, async (event) => {
const snapshot = event.data;
if (!snapshot) {
(0, logger.error)("No data associated with the event");
Expand All @@ -45,12 +47,11 @@ exports.teamPlayerChangeObserver = (0, firestore_2.onDocumentUpdated)({region: R
await teamService.notifyOnAddedToTeam(oldTeam, newTeam);
});

exports.fiveMinuteCron = (0, scheduler.onSchedule)({timeZone: exports.TIMEZONE, schedule: "*/5 * * * *"}, async () => {
exports.fiveMinuteCron = (0, scheduler.onSchedule)({ timeZone: exports.TIMEZONE, schedule: "*/5 * * * *" }, async () => {
await matchRepository.processUpcomingMatches();
});

exports.sendSupportRequest = onCall({ region: "asia-south1" }, async (request) => {
const data = request.data;
await mailRepository.sendSupportRequest(data);
});

});
22 changes: 12 additions & 10 deletions khelo/functions/src/mail/mail_repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ class MailRepository {
}

async sendSupportRequest(data) {
const htmlTemplate = this.htmlTemplate(data);

return await this.db.collection("support_requests")
.add({
to: ["sidhdhi.p@canopas.com", "mayank.v@canopas.com"],
message: {
subject: "Report problem",
html: htmlTemplate,
},
}).then(() => console.log("Queued email for delivery!"));
try {
await this.db.collection("support_requests")
.add({
to: ["sidhdhi.p@canopas.com", "mayank.v@canopas.com"],
message: {
subject: "Report problem",
html: this.htmlTemplate(data),
},
}).then(() => console.log("Queued email for delivery!"));
} catch (e) {
console.log("MailRepository: Error sending support request:", e);
}
}

}
Expand Down

0 comments on commit 77eba88

Please sign in to comment.