Send email when adding participant
- create invite email template - move email config - implement sendEmail functionality
This commit is contained in:
@@ -21,7 +21,6 @@ router.post('/', authenticate, async (req, res) => {
|
||||
const [meeting] = await Meeting.addMeeting(data);
|
||||
res.status(201).json(meeting);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).json({ message: 'Failed to add new meeting.', error });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -7,15 +7,53 @@ const {
|
||||
validateParticipantID,
|
||||
} = require('../../middlewares/validateParticipantID');
|
||||
const Participant = require('../models/participantModel');
|
||||
const { createInvite } = require('../../services/email/emailModels');
|
||||
const sendEmail = require('../../services/email/sendEmail');
|
||||
|
||||
router.post('/', authenticate, async (req, res) => {
|
||||
id = uuidv4();
|
||||
const data = { ...req.body, id };
|
||||
|
||||
let data = { ...req.body, id };
|
||||
const {
|
||||
account_id,
|
||||
email,
|
||||
meeting_id,
|
||||
quorum,
|
||||
mandatory,
|
||||
host,
|
||||
answered,
|
||||
meetingTitle,
|
||||
senderUsername,
|
||||
} = data;
|
||||
|
||||
// Create invite message
|
||||
const invite = createInvite({
|
||||
receiver: email,
|
||||
senderUsername,
|
||||
meetingTitle,
|
||||
meetingId: meeting_id,
|
||||
});
|
||||
|
||||
const participantData = {
|
||||
id,
|
||||
account_id,
|
||||
email,
|
||||
meeting_id,
|
||||
quorum,
|
||||
mandatory,
|
||||
host,
|
||||
answered,
|
||||
};
|
||||
|
||||
try {
|
||||
const [participant] = await Participant.addParticipant(data);
|
||||
const [participant] = await Participant.addParticipant(participantData);
|
||||
|
||||
// Send email
|
||||
sendEmail(invite);
|
||||
|
||||
res.status(201).json(participant);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).json({
|
||||
message: 'Failed to add new participant.',
|
||||
error,
|
||||
@@ -29,7 +67,7 @@ router.put('/:id', authenticate, validateParticipantID, async (req, res) => {
|
||||
|
||||
try {
|
||||
const participant = await Participant.updateParticipant(data, id);
|
||||
res.status(200).json(...participant);
|
||||
res.status(200).json(participant);
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: 'Failed to update participant.',
|
||||
|
||||
@@ -4,7 +4,7 @@ const bodyParser = require('body-parser');
|
||||
const cors = require('cors');
|
||||
const helmet = require('helmet');
|
||||
|
||||
const logSmtpStatus = require('../helpers/logSmtpStatus');
|
||||
const logSmtpStatus = require('../services/email/logSmtpStatus');
|
||||
|
||||
const accountsRoute = require('./routes/accountRoute');
|
||||
const meetingsRoute = require('./routes/meetingRoute');
|
||||
|
||||
Reference in New Issue
Block a user