Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions appwrite.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,10 @@
"timeout": 15
},
{
"$id": "rejectProject",
"name": "rejectProject",
"$id": "reviewProject",
"name": "reviewProject",
"runtime": "node-16.0",
"path": "functions/rejectProject",
"path": "functions/reviewProject",
"entrypoint": "src/index.js",
"ignore": [
"node_modules",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# rejectProject
# rewiewProject

Welcome to the documentation of this function 👋 We strongly recommend keeping this file in sync with your function's logic to make sure anyone can easily understand your function in the future. If you don't need documentation, you can remove this file.

## 🤖 Documentation

A function to send a project rejection email once a rejection reason is entered. After the email is sent, the project is deleted from the database.
A function to send an email once a project is approved or rejected. A project is approved when `isPublished` is set to `true` and rejected when any `rejectionReason` is entered. After rejection, the project is also deleted from the database.

<!-- Update with your description, for example 'Create Stripe payment and return payment URL' -->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const sdk = require("node-appwrite");
const nodemailer = require("nodemailer");
const template = require("./template");
const templates = require("./templates");

module.exports = async function (req, res) {
const client = new sdk.Client();
Expand Down Expand Up @@ -29,12 +29,6 @@ module.exports = async function (req, res) {
throw new Error("Invalid project update event.");
}

if (!project.rejectionReason || project.isPublished) {
console.log("Project has no rejection reason or is already published.");
res.json({ ok: true });
return;
}

console.log("Fetching project author");
const author = await user.get(project.userId);
if (!author || !author.email) {
Expand All @@ -55,29 +49,47 @@ module.exports = async function (req, res) {
},
});

console.log("Sending email to project author");
if (project.isPublished) {
console.log("Sending approval email");
try {
await transporter.sendMail({
from: SMTP_USERNAME,
to: author.email,
bcc: req.variables["APPROVER_EMAILS"],
subject: "Project Review - builtwith.appwrite.io ",
text: templates.approval(project),
});
console.log("Done - exiting.");
} catch (error) {
throw new Error(`Failed to send approval email: ${error}`);
}
return;
}

if (!project.rejectionReason) {
console.log("Project is not rejected - exiting.");
return;
}

console.log("Sending rejection email");
try {
await transporter.sendMail({
from: SMTP_USERNAME,
to: author.email,
bcc: req.variables["APPROVER_EMAILS"],
subject: "Project Review - builtwith.appwrite.io ",
text: template(project),
text: templates.rejection(project),
});
console.log("Done");
} catch (error) {
throw new Error(`Failed to send email: ${error}`);
throw new Error(`Failed to send rejection email: ${error}`);
}

console.log("Deleting the project document");
try {
await database.deleteDocument("main", "projects", project.$id);
console.log("Done");
console.log("Done - exiting.");
} catch (error) {
throw new Error(`Failed to delete project: ${error}`);
}

res.json({
ok: true,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Thank you for submitting your project "${project.name}" to Built With Appwrite.

Unfortunately, we have decided to reject it for the following reason:
> ${project.rejectionReason}

Don't sweat it, though! This is all part of the process and an opportunity for growth. 🌱
After addressing the reason for rejection, feel free to submit the project again. We'd be excited to see your improved version! 🚀

Expand All @@ -60,4 +61,15 @@ Keep on coding and creating awesome stuff! 💻🔥
The Built With Appwrite Team`;
}

module.exports = rejectionTemplate;
function approvalTemplate(project) {
return `Hey 👋,
Thank you for submitting your project "${project.name}" to Built With Appwrite.

After reviewing your project, we have decided to approve it! 🎉
You can now find it on our website: https://builtwith.appwrite.io/projects/${project.$id}

Keep on coding and creating awesome stuff! 💻🔥
The Built With Appwrite Team`;
}

module.exports = { rejection: rejectionTemplate, approval: approvalTemplate };