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 7a3248e commit 8126795
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 15 deletions.
18 changes: 3 additions & 15 deletions khelo/functions/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,8 @@ exports.fiveMinuteCron = (0, scheduler.onSchedule)({timeZone: exports.TIMEZONE,
await matchRepository.processUpcomingMatches();
});

exports.sendSupportRequest = onCall({region: "asia-south1"}, async (request) => {
exports.sendSupportRequest = onCall({ region: "asia-south1" }, async (request) => {
const data = request.data;
try {
await db.collection("support_requests")
.add({
to: ["sidhdhi.p@canopas.com", "mayank.v@canopas.com"],
template: {
name: "support_request",
data: {
request: data,
},
},
}).then(() => console.log("Queued email for delivery!"));
} catch (error) {
console.log("Failed to delivery email", error);
}
await mailRepository.sendSupportRequest(data);
});

70 changes: 70 additions & 0 deletions khelo/functions/src/mail/mail_repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MailRepository = void 0;

class MailRepository {
constructor(db) {
this.db = db;
}

htmlTemplate(data) {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="HandheldFriendly" content="true">
<style>
table {
width: 80%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
th {
font-weight: bold;
}
th, td {
height: 30px;
text-align: center;
}
</style>
</head>
<body>
<br>
<table>
<tbody>
${Object.entries(data).map(([key, value]) => {
// Handling arrays for multi-line values
const formattedValue = Array.isArray(value) ? value.join("</p><p>") : value;
return `<tr><td>${key}</td><td>${formattedValue}</td></tr>`;
}).join('')}
</tbody>
</table>
</body>
</html>
`;
}

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!"));
}

}

exports.MailRepository = MailRepository;

0 comments on commit 8126795

Please sign in to comment.