Skip to content

Commit

Permalink
Add admin email notification
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed May 11, 2024
1 parent 4b3d8f8 commit 3f5e0d5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 42 deletions.
1 change: 1 addition & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ MI_MINIMUM_AGE=21
MI_EXPO_ACCESS_TOKEN=EXPO_ACCESS_TOKEN
MI_STRIPE_SECRET_KEY=STRIPE_SECRET_KEY
MI_STRIPE_SESSION_EXPIRE_AT=82800
MI_ADMIN_EMAIL=admin@movinin.io
7 changes: 7 additions & 0 deletions api/src/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ export const STRIPE_SESSION_EXPIRE_AT = stripeSessionExpireAt
*/
export const BOOKING_EXPIRE_AT = STRIPE_SESSION_EXPIRE_AT + (10 * 60)

/**
* Private SSL key filepath.
*
* @type {string}
*/
export const ADMIN_EMAIL = __env__('MI_ADMIN_EMAIL', false)

/**
* User Document.
*
Expand Down
16 changes: 12 additions & 4 deletions api/src/controllers/bookingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mongoose from 'mongoose'
import escapeStringRegexp from 'escape-string-regexp'
import { Expo, ExpoPushMessage, ExpoPushTicket } from 'expo-server-sdk'
import { Request, Response } from 'express'
import nodemailer from 'nodemailer'
import * as movininTypes from ':movinin-types'
import i18n from '../lang/i18n'
import Booking from '../models/Booking'
Expand Down Expand Up @@ -72,13 +73,19 @@ const notifyAgency = async (user: env.User, bookingId: string, agency: env.User,
// mail
i18n.locale = agency.language

const to = [agency.email]
const admin = !!env.ADMIN_EMAIL && await User.exists({ email: env.ADMIN_EMAIL, type: movininTypes.UserType.Admin, active: true, verified: true, enableEmailNotifications: true })
if (admin) {
to.push(env.ADMIN_EMAIL)
}

const mailOptions = {
from: env.SMTP_FROM,
to: agency.email,
to,
subject: message,
html: `<p>${i18n.t('HELLO')}${agency.fullName},
<br><br>${message}
<br><br>${helper.joinURL(env.BACKEND_HOST, `booking?b=${bookingId}`)}
<br><br>${helper.joinURL(env.BACKEND_HOST, `update-booking?b=${bookingId}`)}
<br><br>${i18n.t('REGARDS')}
<br></p>`,
}
Expand Down Expand Up @@ -210,7 +217,7 @@ export const checkout = async (req: Request, res: Response) => {
return res.sendStatus(204)
}

const mailOptions = {
const mailOptions: nodemailer.SendMailOptions = {
from: env.SMTP_FROM,
to: user.email,
subject: `${i18n.t('BOOKING_CONFIRMED_SUBJECT_PART1')} ${booking._id} ${i18n.t('BOOKING_CONFIRMED_SUBJECT_PART2')}`,
Expand All @@ -236,7 +243,8 @@ export const checkout = async (req: Request, res: Response) => {
return res.sendStatus(204)
}
i18n.locale = agency.language
await notifyAgency(user, booking._id.toString(), agency, i18n.t('BOOKING_NOTIFICATION'))
const message = body.payLater ? i18n.t('BOOKING_PAY_LATER_NOTIFICATION') : i18n.t('BOOKING_PAID_NOTIFICATION')
await notifyAgency(user, booking._id.toString(), agency, message)

return res.status(200).send({ bookingId: booking._id })
} catch (err) {
Expand Down
75 changes: 38 additions & 37 deletions api/src/lang/en.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
export const en = {
ERROR: 'Internal Error: ',
DB_ERROR: 'Database Failure: ',
SMTP_ERROR: 'SMTP Error - Failed to send email: ',
ACCOUNT_ACTIVATION_SUBJECT: 'Account Activation',
HELLO: 'Hello ',
ACCOUNT_ACTIVATION_LINK: 'Please activate your account by clicking the link:',
REGARDS: "Kind regards,<br>Movin' In team",
ACCOUNT_ACTIVATION_TECHNICAL_ISSUE: 'Technical Issue! Please click on resend to validate your email.',
ACCOUNT_ACTIVATION_LINK_EXPIRED: 'Your validation link may have expired. Please click on resend to validate your email.',
ACCOUNT_ACTIVATION_LINK_ERROR: 'We were unable to find a user for this verification. Please Sign up.',
ACCOUNT_ACTIVATION_SUCCESS: 'Your account was successfully verified.',
ACCOUNT_ACTIVATION_RESEND_ERROR: 'We were unable to find a user with that email. Make sure your Email is correct.',
ACCOUNT_ACTIVATION_ACCOUNT_VERIFIED: 'This account has already been verified. Please sign in.',
ACCOUNT_ACTIVATION_EMAIL_SENT_PART_1: 'A validation email has been sent to ',
ACCOUNT_ACTIVATION_EMAIL_SENT_PART_2: ". It will be expire after one day. If you didn't receive validation email click on resend.",
PASSWORD_RESET_SUBJECT: 'Password Reset',
PASSWORD_RESET_LINK: 'Please reset your password by clicking the link:',
BOOKING_CONFIRMED_SUBJECT_PART1: 'Your booking',
BOOKING_CONFIRMED_SUBJECT_PART2: 'is confirmed.',
BOOKING_CONFIRMED_PART1: 'Your booking',
BOOKING_CONFIRMED_PART2: 'is confirmed and the payment was successfully done.',
BOOKING_CONFIRMED_PART3: ' Please present yourself to our agency ',
export const fr = {
ERROR: 'Erreur interne : ',
DB_ERROR: 'Échec de la requête dans la base de données : ',
SMTP_ERROR: "Erreur SMTP - Échec de l'envoi de l'email: ",
ACCOUNT_ACTIVATION_SUBJECT: 'Activation de votre compte',
HELLO: 'Bonjour ',
ACCOUNT_ACTIVATION_LINK: 'Veuillez activer votre compte en cliquant sur le lien :',
REGARDS: "Cordialement,<br>L'équipe Movin' In",
ACCOUNT_ACTIVATION_TECHNICAL_ISSUE: 'Problème technique! Veuillez cliquer sur renvoyer pour valider votre e-mail.',
ACCOUNT_ACTIVATION_LINK_EXPIRED: 'Votre lien de validation a peut-être expiré. Veuillez cliquer sur renvoyer pour valider votre e-mail.',
ACCOUNT_ACTIVATION_LINK_ERROR: "Nous n'avons pas pu trouver d'utilisateur correspondant à cette adresse e-mail. Veuillez vous inscrire.",
ACCOUNT_ACTIVATION_SUCCESS: 'Votre compte a été validé avec succès.',
ACCOUNT_ACTIVATION_RESEND_ERROR: "Nous n'avons pas pu trouver d'utilisateur correspondant à cette adresse e-mail. Assurez-vous que votre e-mail est correct.",
ACCOUNT_ACTIVATION_ACCOUNT_VERIFIED: 'Ce compte a déjà été validé. Veuillez vous connecter.',
ACCOUNT_ACTIVATION_EMAIL_SENT_PART_1: 'Un email de validation a été envoyé à',
ACCOUNT_ACTIVATION_EMAIL_SENT_PART_2: ". Il expirera au bout d'un jour. Si vous n'avez pas reçu d'e-mail de validation, cliquez sur renvoyer.",
PASSWORD_RESET_SUBJECT: 'Réinitialisation du mot de passe',
PASSWORD_RESET_LINK: 'Veuillez réinitialiser votre mot de passe en cliquant sur le lien :',
BOOKING_CONFIRMED_SUBJECT_PART1: 'Votre réservation',
BOOKING_CONFIRMED_SUBJECT_PART2: 'a été confirmée.',
BOOKING_CONFIRMED_PART1: 'Votre réservation',
BOOKING_CONFIRMED_PART2: 'a bien été confirmée et le paiement a bien été effectué.',
BOOKING_CONFIRMED_PART3: ' Veuillez vous rendre à notre agence ',
BOOKING_CONFIRMED_PART4: ' ',
BOOKING_CONFIRMED_PART5: ' on ',
BOOKING_CONFIRMED_PART6: ' (local time) to pick up your keys ',
BOOKING_CONFIRMED_PART5: ' le ',
BOOKING_CONFIRMED_PART6: ' (heure locale) pour récupérer vos clés ',
BOOKING_CONFIRMED_PART7: '.',
BOOKING_CONFIRMED_PART8: 'Please bring your ID and warranty check with you.',
BOOKING_CONFIRMED_PART9: 'You must drop-off the keys to our agency ',
BOOKING_CONFIRMED_PART8: "Veuillez apporter avec vous votre pièce d'identité et le chèque de garantie.",
BOOKING_CONFIRMED_PART9: 'Vous devez rendre les clés à notre agence ',
BOOKING_CONFIRMED_PART10: ' ',
BOOKING_CONFIRMED_PART11: ' on ',
BOOKING_CONFIRMED_PART12: ' (local time).',
BOOKING_CONFIRMED_PART13: 'Please respect the time.',
BOOKING_CONFIRMED_PART14: 'You can follow your booking on: ',
BOOKING_NOTIFICATION: 'paid the booking',
CANCEL_BOOKING_NOTIFICATION: 'made a request to cancel the booking',
BOOKING_UPDATED_NOTIFICATION_PART1: 'The status of the booking',
BOOKING_UPDATED_NOTIFICATION_PART2: 'was updated.',
PROPERTY_IMAGE_REQUIRED: 'Le champ image ne peut pas être vide: ',
PROPERTY_IMAGE_NOT_FOUND: 'Le fichier image est introuvable : ',
BOOKING_CONFIRMED_PART11: ' le ',
BOOKING_CONFIRMED_PART12: ' (heure locale).',
BOOKING_CONFIRMED_PART13: 'Veuillez respecter les horaires.',
BOOKING_CONFIRMED_PART14: 'Vous pouvez suivre votre réservation sur : ',
BOOKING_PAY_LATER_NOTIFICATION: 'a confirmé (payer plus tard) la réservation',
BOOKING_PAID_NOTIFICATION: 'a payé la réservation',
CANCEL_BOOKING_NOTIFICATION: "a fait une demande d'annulation de la réservation",
BOOKING_UPDATED_NOTIFICATION_PART1: 'Le statut de la réservation',
BOOKING_UPDATED_NOTIFICATION_PART2: 'a été mis à jour.',
PROPERTY_IMAGE_REQUIRED: "Property's image field can't be blank: ",
PROPERTY_IMAGE_NOT_FOUND: 'Image file not found: ',
}
3 changes: 2 additions & 1 deletion api/src/lang/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const fr = {
BOOKING_CONFIRMED_PART12: ' (heure locale).',
BOOKING_CONFIRMED_PART13: 'Veuillez respecter les horaires.',
BOOKING_CONFIRMED_PART14: 'Vous pouvez suivre votre réservation sur : ',
BOOKING_NOTIFICATION: 'a payé la réservation',
BOOKING_PAY_LATER_NOTIFICATION: 'a confirmé (payer plus tard) la réservation',
BOOKING_PAID_NOTIFICATION: 'a payé la réservation',
CANCEL_BOOKING_NOTIFICATION: "a fait une demande d'annulation de la réservation",
BOOKING_UPDATED_NOTIFICATION_PART1: 'Le statut de la réservation',
BOOKING_UPDATED_NOTIFICATION_PART2: 'a été mis à jour.',
Expand Down

0 comments on commit 3f5e0d5

Please sign in to comment.