-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from CybTekk-LLP/feat/email
Feat/email
- Loading branch information
Showing
11 changed files
with
169 additions
and
1,091 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { | ||
Logger, | ||
NODEMAILER_EMAIL, | ||
NODEMAILER_PASSWORD, | ||
PUBLIC_BASE_URI, | ||
KLAVIYO_PRIVATE_API_KEY, | ||
} from "@/config"; | ||
|
||
import fetch from "node-fetch"; | ||
|
||
export class EmailService { | ||
async uploadImage(imageURL) { | ||
const url = "https://a.klaviyo.com/api/images/"; | ||
const options = { | ||
method: "POST", | ||
headers: { | ||
accept: "application/json", | ||
revision: "2024-06-15", | ||
"content-type": "application/json", | ||
Authorization: `Klaviyo-API-Key ${KLAVIYO_PRIVATE_API_KEY}`, | ||
}, | ||
body: JSON.stringify({ | ||
data: { | ||
type: "image", | ||
attributes: { | ||
import_from_url: `${imageURL}`, | ||
hidden: false, | ||
}, | ||
}, | ||
}), | ||
}; | ||
|
||
const data = await fetch(url, options); | ||
return await data.json(); | ||
} | ||
async sendEmail(recipientEmail: string, imageURL: string) { | ||
const url = "https://a.klaviyo.com/api/events/"; | ||
const options = { | ||
method: "POST", | ||
headers: { | ||
accept: "application/json", | ||
revision: "2024-06-15", | ||
"content-type": "application/json", | ||
Authorization: `Klaviyo-API-Key ${KLAVIYO_PRIVATE_API_KEY}`, | ||
}, | ||
body: JSON.stringify({ | ||
data: { | ||
type: "event", | ||
attributes: { | ||
properties: { | ||
submit: "Yes", | ||
imageURL: imageURL, | ||
}, | ||
|
||
metric: { | ||
data: { | ||
type: "metric", | ||
attributes: { | ||
name: "Picture Submit", | ||
}, | ||
}, | ||
}, | ||
profile: { | ||
data: { | ||
type: "profile", | ||
attributes: { | ||
properties: { | ||
submit: "Yes", | ||
}, | ||
email: `${recipientEmail}`, | ||
}, | ||
imageURL: | ||
"https://d3k81ch9hvuctc.cloudfront.net/company/TWnsJV/images/e9c9c693-0df8-4954-8b6d-47af088b0fd1.jpeg", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}), | ||
}; | ||
fetch(url, options) | ||
.then((res) => res.json()) | ||
.then((json) => JSON.parse(json)) | ||
.catch((err) => console.error("error:" + err)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./UploadService"; | ||
export * from "./EmailService"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ export const { | |
UPLOADS_PATH, | ||
ALLOWED_ORIGINS, | ||
PUBLIC_BASE_URI, | ||
KLAVIYO_PRIVATE_API_KEY, | ||
} = process.env; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { EmailService } from "@/application/services"; | ||
import { Request, Response } from "express"; | ||
export class EmailController { | ||
constructor(private emailService?: EmailService) { | ||
this.emailService = emailService; | ||
} | ||
sendEmail = async (req: Request, res: Response) => { | ||
let email = req.query.email.toString(); | ||
let imageURL = req.query.imageurl.toString(); | ||
await this.emailService.sendEmail(email, imageURL); | ||
res.status(200).send("Email sent successfully"); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Router } from "express"; | ||
import { EmailController } from "../controllers/email.controller"; | ||
import { EmailService } from "@/application/services"; | ||
|
||
const router = Router(); | ||
|
||
const emailService = new EmailService(); | ||
const emailController = new EmailController(emailService); | ||
router.route("/").post(emailController.sendEmail); | ||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { Router } from "express"; | ||
import uploadRouter from "./upload.router"; | ||
import emailrouter from "./email.router"; | ||
|
||
const appRouter = Router(); | ||
|
||
appRouter.use("/uploads", uploadRouter); | ||
appRouter.use("/email", emailrouter); | ||
|
||
export { appRouter }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { Router } from "express"; | ||
import { UploadsController } from "../controllers"; | ||
import { uploadGallery } from "@/application/services"; | ||
import { EmailService, uploadGallery } from "@/application/services"; | ||
|
||
const router = Router(); | ||
|
||
const uploadController = new UploadsController(); | ||
const emailService = new EmailService(); | ||
const uploadController = new UploadsController(emailService); | ||
|
||
router | ||
.route("/gallery") | ||
.post( | ||
uploadGallery.array("gallery", 3), | ||
uploadController.handleGalleryUpload | ||
); | ||
router.route("/images/email").post(uploadController.handleEmailImage); | ||
|
||
export default router; |