zeitadler-terminplaner-backend/src/mail/verifyFail.ts

76 lines
2.2 KiB
TypeScript

import MyEvents, { CalendarEvent } from '../database/reservedCustomer';
import { getStore } from '../database/store';
import { getUser } from '../database/user';
import { User } from '../user/types';
import { getDateText } from './dateText';
import getConnection from './getConnection';
async function sendAppointmentCanceledMail(event: CalendarEvent) {
const queue = 'kk.mails';
const conn = await getConnection();
// Sender
const ch2 = await conn.createChannel();
const store = await getStore(event.store_id);
let data = {
m: event.customer_email, // UserMail
t: 'embedAppointmentCanceledZeitAdler', // TemplateId
l: 'de', // LanguageId
// BodyData
b: {
name: event.customer_name,
appointment1: 'Termin',
appointment2: event.time_start.toISOString(),
appointment3: event.time_end.toISOString(),
address: store.address,
...(await getDateText(event)),
},
};
ch2.sendToQueue(queue, Buffer.from(JSON.stringify(data)));
try {
await sendCancelAppointmentForEmployeeMail(event);
} catch (error) {
console.log('error sending sendNewAppointmentForEmployeeMail');
console.error(error);
}
console.log('Sent:', data);
}
async function sendCancelAppointmentForEmployeeMail(event: CalendarEvent) {
if (!event.customer_verified_time) return;
const user = await getUser(event.user_id);
if (!user.email) return;
const queue = 'kk.mails';
const conn = await getConnection();
// Sender
const ch2 = await conn.createChannel();
const store = await getStore(event.store_id);
let data = {
m: user.email, // UserMail
t: 'embedEmployeeCancelNotificationZeitAdler', // TemplateId
l: 'de', // LanguageId
// BodyData
b: {
name: event.customer_name,
customerEMail: event.customer_email,
address: store.address,
...(await getDateText(event)),
},
};
ch2.sendToQueue(queue, Buffer.from(JSON.stringify(data)));
console.log('Sent:', data);
}
export default sendAppointmentCanceledMail;