emailer and resume start
ci / docker_image (push) Successful in 1m34s
ci / deploy (push) Successful in 16s

This commit is contained in:
2025-03-23 12:26:12 -05:00
parent 4f9e770270
commit 1877aee8a5
11 changed files with 292 additions and 167 deletions
+33
View File
@@ -10,6 +10,7 @@ import {
type Posting,
type Application
} from '$lib/types';
import { sendEmployerNotificationEmail } from '$lib/emailer.server';
export async function createUser(user: User): Promise<number> {
const password_hash: string = await bcrypt.hash(user.password!, 12);
@@ -700,6 +701,9 @@ export async function createApplication(application: Application): Promise<numbe
RETURNING id;
`;
sendEmployerNotificationEmail(application.postingId).catch((err) => {
console.error('Failed to send employer notification email: ', err);
});
return response[0].id;
}
@@ -764,3 +768,32 @@ export async function setUserCompanyId(userId: number, companyId: number): Promi
WHERE id = ${userId};
`;
}
export async function getNotificationInfo(
postingId: number
): Promise<{ title: string; emails: string[] }> {
const data = await sql`
WITH posting_data AS (
SELECT title, company_id
FROM postings
WHERE id = ${postingId}
),
user_emails AS (
SELECT email
FROM users
WHERE company_id = (SELECT company_id FROM posting_data)
)
SELECT
(SELECT title FROM posting_data) AS title,
(SELECT json_agg(email) FROM user_emails) AS emails;
`;
if (!data || !data[0]) {
error(404, 'Posting not found');
}
return {
title: data[0].title,
emails: data[0].emails
};
}
+26
View File
@@ -0,0 +1,26 @@
// Import the Nodemailer library
import nodemailer from 'nodemailer';
import { getNotificationInfo } from '$lib/db/index.server';
// Create a transporter object using SMTP transport
const transporter = nodemailer.createTransport({
host: process.env.EMAIL_HOST,
port: Number(process.env.EMAIL_PORT),
secure: true, // true for 465, false for other ports
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS
}
});
export async function sendEmployerNotificationEmail(postingId: number) {
let info = await getNotificationInfo(postingId);
// Send mail with defined transport object
await transporter.sendMail({
from: `CareerConnect Notifications <${process.env.EMAIL_USER}>`,
// to: info.emails.join(', '), // EMAILING OF REAL COMPANIES DISABLED, UNCOMMENT TO ENABLE
to: 'drake@marinodev.com', // TEMPORARY EMAIL FOR TESTING
subject: 'New Application Received!',
text: `A new application has been received for the posting '${info.title}'!\n\nCheck it out at ${process.env.BASE_URL}/postings/${postingId}/manage/applications`
});
}