Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #95 from mauro8778/mauro2
Browse files Browse the repository at this point in the history
mails configurados
  • Loading branch information
MaxiSalguero authored Dec 9, 2024
2 parents 7b443f2 + 7059969 commit bb66262
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 138 deletions.
1 change: 1 addition & 0 deletions src/services/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const createUserService = async (userData: { name: string; last_name:stri

const newUser = new Usuario(userData);
const savedUser = await newUser.save();

return savedUser;
};

Expand Down
140 changes: 113 additions & 27 deletions src/services/mailService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import nodemailer from "nodemailer";
import { MailConfig } from "../config/mailConfig";
import { postAdoptionDto } from "../dtos/postAdoption.dto";
import { IAnimal } from "../models/animalModel";
import { IRefugee } from "../models/refugeeModel";
import { generatePDF } from "../config/pdfConfig";
import juice from "juice";

class MailService {
private transporter;
Expand All @@ -15,48 +14,111 @@ class MailService {
async confirmCambioDePassword(email: string, name: string, password: string) {
const subject = "Confirmación de Cambio de Contraseña";
const html = `
<h1>Hola, ${name}</h1>
<p>Tu contraseña ha sido actualizada con éxito.</p>
<p>Tu nueva contraseña es: <strong>${password}</strong></p>
<p>Si no realizaste este cambio, por favor contacta con soporte de inmediato.</p>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Confirmación de Cambio de Contraseña</title>
</head>
<body style="font-family: Arial, sans-serif; background-color: #6AB4A8; color: #333; margin: 0; padding: 0;">
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);">
<tr>
<td style="text-align: center; color: #08121F; padding-bottom: 20px;">
<h1 style="font-size: 40px; margin: 0; font-weight: bold;">Confirmación de Cambio de Contraseña</h1>
<div style="font-size: 50px; color: #08121F; font-weight: bold; text-transform: uppercase; margin-top: 30px;">PAWSOME!</div>
</td>
</tr>
<tr>
<td style="font-size: 16px; line-height: 1.5; color: #333;">
<p>Hola <b>${name}</b>,</p>
<p>Tu contraseña ha sido actualizada con éxito.</p>
<p>Tu nueva contraseña es: <strong>${password}</strong></p>
<p>Si no realizaste este cambio, por favor contacta con soporte de inmediato.</p>
<div style="font-size: 30px; text-align: center; margin-top: 20px;">
🐾🐾🐾🐾🐾
</div>
<div style="text-align: center; margin-top: 40px; font-size: 14px; color: #888;">
<p>¡El equipo de Mi App!</p>
</div>
</td>
</tr>
</table>
</body>
</html>
`;


const inlinedHtml = juice(html);

try {
const info = await this.transporter.sendMail({
from: `"Mi App" <${MailConfig.auth.user}>`,
to: email,
subject,
html,
html: inlinedHtml,
});
return info;
} catch (error) {
throw new Error("Error al enviar el correo: " );
throw new Error("Error al enviar el correo: ");
}
}

async cambioPasswordMail(email: string, name: string, resetUrl: string) {
const subject = "Solicitud de cambio de contraseña";
const html = `
<h1>Hola, ${name}</h1>
<p>Hemos recibido una solicitud para cambiar tu contraseña.</p>
<p>Si fuiste tú, por favor haz clic en el siguiente enlace para restablecer tu contraseña:</p>
<a href="${resetUrl}">Restablecer mi contraseña</a>
<p>Si no solicitaste este cambio, por favor ignora este correo.</p>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Solicitud de Cambio de Contraseña</title>
</head>
<body style="font-family: Arial, sans-serif; background-color: #6AB4A8; color: #333; margin: 0; padding: 0;">
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);">
<tr>
<td style="text-align: center; color: #08121F; padding-bottom: 20px;">
<h1 style="font-size: 40px; margin: 0; font-weight: bold;">Solicitud de Cambio de Contraseña</h1>
<div style="font-size: 50px; color: #08121F; font-weight: bold; text-transform: uppercase; margin-top: 30px;">PAWSOME!</div>
</td>
</tr>
<tr>
<td style="font-size: 16px; line-height: 1.5; color: #333;">
<p>Hola <b>${name}</b>,</p>
<p>Hemos recibido una solicitud para cambiar tu contraseña.</p>
<p>Si fuiste tú, por favor haz clic en el siguiente enlace para restablecer tu contraseña:</p>
<p style="text-align: center;">
<a href="${resetUrl}" style="background-color: #08121F; color: #fff; padding: 12px 20px; font-size: 18px; border-radius: 5px; text-decoration: none; font-weight: bold;">Restablecer mi contraseña</a>
</p>
<p>Si no solicitaste este cambio, por favor ignora este correo.</p>
<div style="font-size: 30px; text-align: center; margin-top: 20px;">
🐾🐾🐾🐾🐾
</div>
<div style="text-align: center; margin-top: 40px; font-size: 14px; color: #888;">
<p>¡El equipo de Mi App!</p>
</div>
</td>
</tr>
</table>
</body>
</html>
`;


const inlinedHtml = juice(html);

try {
const info = await this.transporter.sendMail({
from: `"Mi App" <${MailConfig.auth.user}>`,
to: email,
subject,
html,
html: inlinedHtml,
});
return info;
} catch (error) {
throw new Error("Error al enviar el correo de cambio de contraseña: " );
throw new Error("Error al enviar el correo de cambio de contraseña: ");
}
}

async getAdopterEmailTemplate(
useremail: string,
adoptante: postAdoptionDto,
Expand All @@ -81,17 +143,41 @@ class MailService {
</div>
</div>
`;

// HTML para el correo

const htmlContent = `
<div style="text-align: center; font-family: Arial, sans-serif;">
<h1 style="font-size: 36px; color: #2c3e50;">Pawsome</h1>
<h3>Detalles de la adopción</h3>
${adoptionDetails}
</div>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Detalles de la Adopción</title>
</head>
<body style="font-family: Arial, sans-serif; background-color: #6AB4A8; color: #333; margin: 0; padding: 0;">
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);">
<tr>
<td style="text-align: center; color: #08121F; padding-bottom: 20px;">
<h1 style="font-size: 36px; color: #2c3e50; margin: 0; font-weight: bold;">Pawsome</h1>
<h3>Detalles de la adopción</h3>
</td>
</tr>
<tr>
<td>
${adoptionDetails}
<div style="font-size: 30px; text-align: center; margin-top: 20px;">
🐾🐾🐾🐾🐾
</div>
<div style="text-align: center; margin-top: 40px; font-size: 14px; color: #888;">
<p>¡Gracias por adoptar!</p>
</div>
</td>
</tr>
</table>
</body>
</html>
`;

return { html: htmlContent };

const inlinedHtml = juice(htmlContent);

return { html: inlinedHtml };
}


Expand Down
112 changes: 1 addition & 111 deletions src/services/volunteersServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,115 +144,5 @@ export const registerVolunteer = async (input: VolunteerRegistrationInput, userI
if (!usuario) {
throw new Error('Usuario no encontrado');
}
const mailContent = `
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Confirmación de Inscripción</title>
</head>
<body style="font-family: Arial, sans-serif; background-color: #6AB4A8; color: #333; margin: 0; padding: 0;">
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);">
<tr>
<td style="text-align: center; color: #08121F; padding-bottom: 20px;">
<h1 style="font-size: 40px; margin: 0; font-weight: bold;">Confirmación de Inscripción</h1>
<div style="font-size: 50px; color: #08121F; font-weight: bold; text-transform: uppercase; margin-top: 30px;">PAWSOME!</div>
</td>
</tr>
<tr>
<td style="font-size: 16px; line-height: 1.5; color: #333;">
<p>Hola <b>${usuario.name} ${usuario.last_name}</b>,</p>
<p>Gracias por inscribirte a la oportunidad de voluntariado "<b>${detalleOportunidad.description}</b>" en el refugio "<b>${refugio.name_refugee}</b>". Aquí están los detalles de tu inscripción:</p>
<div style="background-color: #08121F; padding: 20px; border-radius: 8px; color: white; text-align: left;">
<p style="font-size: 20px; font-weight: bold; text-align: center; margin: 0; padding-bottom: 15px;">Detalles de tu Inscripción</p>
<table style="width: 100%; font-size: 14px; color: #fff; margin-bottom: 10px;">
<tr><td><b>Nombre completo:</b></td><td>${formData.personalData.fullName || `${usuario.name} ${usuario.last_name}`}</td></tr>
<tr><td><b>Fecha de nacimiento:</b></td><td>${formData.personalData.birth || "No especificada"}</td></tr>
<tr><td><b>Género:</b></td><td>${formData.personalData.gender || "No especificado"}</td></tr>
<tr><td><b>Dirección:</b></td><td>${formData.personalData.address || "No especificada"}</td></tr>
<tr><td><b>Teléfono de contacto:</b></td><td>${formData.personalData.contactTel || "No especificado"}</td></tr>
<tr><td><b>Email:</b></td><td>${formData.personalData.email || usuario.email}</td></tr>
</table>
<div style="font-size: 30px; text-align: center;">
🐾🐾🐾🐾🐾
</div>
</div>
<div style="font-size: 30px; text-align: center; margin-top: 20px;">
🐾🐾🐾🐾🐾
</div>
<table width="100%" cellspacing="0" cellpadding="5" style="border-top: 2px solid #08121F;">
<tr><td colspan="2" style="color: #08121F; font-size: 18px;"><b>**Disponibilidad:**</b></td></tr>
<tr><td><b>Días disponibles:</b></td><td>${formData.availability.availableDays || "No especificados"}</td></tr>
<tr><td><b>Horas disponibles:</b></td><td>${formData.availability.availableHours}</td></tr>
<tr><td><b>Frecuencia:</b></td><td>${formData.availability.frecuency || "No especificada"}</td></tr>
</table>
<table width="100%" cellspacing="0" cellpadding="5" style="border-top: 2px solid #08121F;">
<tr><td colspan="2" style="color: #08121F; font-size: 18px;"><b>**Experiencia y habilidades:**</b></td></tr>
<tr><td><b>Experiencia:</b></td><td>${formData.experienceAndSkills.experience || "No especificada"}</td></tr>
<tr><td><b>Área de preferencia:</b></td><td>${formData.experienceAndSkills.preferenceArea || "No especificada"}</td></tr>
<tr><td><b>Conocimientos adicionales:</b></td><td>${formData.experienceAndSkills.knowledge || "No especificados"}</td></tr>
</table>
<table width="100%" cellspacing="0" cellpadding="5" style="border-top: 2px solid #08121F;">
<tr><td colspan="2" style="color: #08121F; font-size: 18px;"><b>**Motivación:**</b></td></tr>
<tr><td><b>Razón para ser voluntario:</b></td><td>${formData.motivation.volunteer || "No especificada"}</td></tr>
<tr><td><b>Aprendizajes esperados:</b></td><td>${formData.motivation.learn || "No especificado"}</td></tr>
</table>
<table width="100%" cellspacing="0" cellpadding="5" style="border-top: 2px solid #08121F;">
<tr><td colspan="2" style="color: #08121F; font-size: 18px;"><b>**Preferencias de rol:**</b></td></tr>
<tr><td><b>Rol deseado:</b></td><td>${formData.rolePreferences.role || "No especificado"}</td></tr>
<tr><td><b>Trabajo:</b></td><td>${formData.rolePreferences.individualTeam || "No especificado"}</td></tr>
</table>
<table width="100%" cellspacing="0" cellpadding="5" style="border-top: 2px solid #08121F;">
<tr><td colspan="2" style="color: #08121F; font-size: 18px;"><b>**Condiciones médicas:**</b></td></tr>
<tr><td><b>Condiciones médicas:</b></td><td>${formData.healthConditions.medicalConditions || "No especificadas"}</td></tr>
<tr><td><b>Alergias:</b></td><td>${formData.healthConditions.alergics || "No especificadas"}</td></tr>
</table>
<table width="100%" cellspacing="0" cellpadding="5" style="border-top: 2px solid #08121F;">
<tr><td colspan="2" style="color: #08121F; font-size: 18px;"><b>**Información adicional:**</b></td></tr>
<tr><td><b>Detalles adicionales:</b></td><td>${formData.additionalObservations.adicionalInfo || "No especificada"}</td></tr>
</table>
<table width="100%" cellspacing="0" cellpadding="5" style="border-top: 2px solid #08121F;">
<tr><td colspan="2" style="color: #08121F; font-size: 18px;"><b>**Detalles del voluntariado seleccionado:**</b></td></tr>
<tr><td><b>Nombre:</b></td><td>${formData.selectedVolunteering.volunteeringName || detalleOportunidad.description}</td></tr>
<tr><td><b>Descripción:</b></td><td>${formData.selectedVolunteering.volunteeringDescription || "No especificada"}</td></tr>
</table>
<p>¡Gracias por tu interés en ayudar!</p>
<div style="text-align: center; margin-top: 40px; font-size: 14px; color: #888;">
<p>¡El equipo de ${refugio.name_refugee}!</p>
</div>
</td>
</tr>
</table>
</body>
</html>
`;

const inlinedHtml = juice(mailContent);

await mailService.sendEmail({
to: usuario.email,
subject: `Confirmación de inscripción: ${detalleOportunidad.description}`,
html: inlinedHtml
});

return {
message: 'Inscripción exitosa. Se ha enviado un correo de confirmación.',
refugio: refugio.name_refugee,
oportunidad: detalleOportunidad.description,
detallesEnviados: inlinedHtml
};

};

0 comments on commit bb66262

Please sign in to comment.