Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | 60x 60x 60x 60x 60x 60x 105x 19x 19x 38x 38x 28x 28x 10x 10x 19x 19x 19x 36x 36x 36x 36x 36x 10x 10x 10x 10x 10x 13x 13x 13x 13x 13x 10x 10x 10x 4x 4x 4x 13x 13x 13x 13x 13x 105x | import { capitalize } from "remeda";
import { getProgramTypePluralName } from "shared/constants/programTypeNames";
import { Locale } from "shared/types/locale";
import { getDateAndTime } from "shared/utils/timeFormatter";
import { NotificationTask } from "server/utils/notificationQueue";
export interface EmailMessage {
from: string;
to: string;
subject: string;
text: string;
html?: string;
}
interface EmailTemplate {
subject: string;
text: string;
}
const SUBJECT = "Konsti-arvonnan tulos / Results for Konsti lottery sign-up";
const CANCELLED_DELETED_SUBJECT = "Ohjelma peruttu / Program cancelled";
const SIGNUP_CHANGED_SUBJECT =
"Ohjelman ilmoittautuminen muuttunut / Program sign-up method changed";
const PROGRAM_STARTING_TIME_CHANGED_SUBJECT =
"Ohjelman aika muuttunut / Program time changed";
const SIGNATURE = "Terveisin / Sincerely Konsti";
// Every message says the same thing twice, Finnish first, and signs off the same way. Kept
// here so the order and the blank lines between them cannot drift apart between messages
const buildEmailTemplate = (
subject: string,
bodyFi: string,
bodyEn: string,
): EmailTemplate => ({
subject,
text: `${bodyFi}\n\n${bodyEn}\n\n${SIGNATURE}`,
});
export function getRejectedEmailTemplate(
notification: NotificationTask,
): EmailTemplate {
// One lottery can cover several starting times at once, and naming only the first would point
// at one hour out of the several the attendee was competing across. Both ends carry their date,
// since a span can end on a later day and a bare clock time would read as running backwards.
const { lastProgramItemEndTime, programType } = notification;
const lotteriedLine = (locale: Locale): string => {
const from = getDateAndTime(notification.programItemStartTime, locale);
if (!lastProgramItemEndTime || !programType) {
return locale === Locale.FI
? `Paikat ${from} alkaviin ohjelmanumeroihin arvottiin.`
: `Spots for program items starting at ${from} were randomized.`;
}
// Named the way the event log names it, so the inbox and the log tell one story
const names = capitalize(getProgramTypePluralName(programType, locale));
const until = getDateAndTime(lastProgramItemEndTime, locale);
return locale === Locale.FI
? `${names} välillä ${from} - ${until} arvottiin.`
: `${names} between ${from} and ${until} were lotteried.`;
};
const bodyFi = `Hei ${notification.username}!
${lotteriedLine(Locale.FI)}
Et valitettavasti päässyt arvonnassa yhteenkään ohjelmaan johon ilmoittauduit.`;
const bodyEn = `Hi ${notification.username}!
${lotteriedLine(Locale.EN)}
Unfortunately you did not get a spot in the lottery sign-up.`;
return buildEmailTemplate(SUBJECT, bodyFi, bodyEn);
}
export function getAcceptedEmailTemplate(
programItemTitle: string,
notification: NotificationTask,
): EmailTemplate {
const programStartTimeFi = getDateAndTime(
notification.programItemStartTime,
Locale.FI,
);
const programStartTimeEn = getDateAndTime(
notification.programItemStartTime,
Locale.EN,
);
const bodyFi = `Hei ${notification.username}!
Olet ollut onnekas ja pääsit ohjelmaan ${programItemTitle}.
Ohjelma alkaa ${programStartTimeFi}.`;
const bodyEn = `Hi ${notification.username}!
You got a spot in the program ${programItemTitle}.
The program will start at ${programStartTimeEn}.`;
return buildEmailTemplate(SUBJECT, bodyFi, bodyEn);
}
export function getProgramItemCancelledEmailTemplate(
notification: NotificationTask,
): EmailTemplate {
const programStartTimeFi = getDateAndTime(
notification.programItemStartTime,
Locale.FI,
);
const programStartTimeEn = getDateAndTime(
notification.programItemStartTime,
Locale.EN,
);
const bodyFi = `Hei ${notification.username}!
Ohjelma ${notification.programItemTitle} on peruttu.
Ohjelman piti alkaa ${programStartTimeFi}.`;
const bodyEn = `Hi ${notification.username}!
Program ${notification.programItemTitle} has been cancelled.
Program was supposed to start at ${programStartTimeEn}.`;
return buildEmailTemplate(CANCELLED_DELETED_SUBJECT, bodyFi, bodyEn);
}
export function getProgramItemDeletedEmailTemplate(
notification: NotificationTask,
): EmailTemplate {
const programStartTimeFi = getDateAndTime(
notification.programItemStartTime,
Locale.FI,
);
const programStartTimeEn = getDateAndTime(
notification.programItemStartTime,
Locale.EN,
);
const bodyFi = `Hei ${notification.username}!
Ohjelma ${notification.programItemTitle} on poistettu ohjelmistosta.
Ohjelman piti alkaa ${programStartTimeFi}.`;
const bodyEn = `Hi ${notification.username}!
Program ${notification.programItemTitle} has been removed from the program.
Program was supposed to start at ${programStartTimeEn}.`;
return buildEmailTemplate(CANCELLED_DELETED_SUBJECT, bodyFi, bodyEn);
}
export function getProgramItemNoKonstiSignupEmailTemplate(
notification: NotificationTask,
): EmailTemplate {
const bodyFi = `Hei ${notification.username}!
Ohjelma ${notification.programItemTitle} ei enää käytä Konsti-ilmoittautumista.
Ilmoittautumisesi ohjelmaan on poistettu.`;
const bodyEn = `Hi ${notification.username}!
Program ${notification.programItemTitle} no longer uses Konsti sign-up.
Your sign-up for the program has been removed.`;
return buildEmailTemplate(SIGNUP_CHANGED_SUBJECT, bodyFi, bodyEn);
}
export function getProgramItemNoLotteryEmailTemplate(
notification: NotificationTask,
): EmailTemplate {
const bodyFi = `Hei ${notification.username}!
Ohjelma ${notification.programItemTitle} ei enää käytä arvontailmoittautumista.
Arvontailmoittautumisesi ohjelmaan on poistettu.`;
const bodyEn = `Hi ${notification.username}!
Program ${notification.programItemTitle} no longer uses lottery sign-up.
Your lottery sign-up for the program has been removed.`;
return buildEmailTemplate(SIGNUP_CHANGED_SUBJECT, bodyFi, bodyEn);
}
export function getProgramItemTimeChangedEmailTemplate(
notification: NotificationTask,
): EmailTemplate {
const programStartTimeFi = getDateAndTime(
notification.programItemStartTime,
Locale.FI,
);
const programStartTimeEn = getDateAndTime(
notification.programItemStartTime,
Locale.EN,
);
const bodyFi = `Hei ${notification.username}!
Ohjelman ${notification.programItemTitle} aikataulu on muuttunut.
Ohjelma alkaa nyt ${programStartTimeFi}.`;
const bodyEn = `Hi ${notification.username}!
Program ${notification.programItemTitle} start time has changed.
The program will now start at ${programStartTimeEn}.`;
return buildEmailTemplate(
PROGRAM_STARTING_TIME_CHANGED_SUBJECT,
bodyFi,
bodyEn,
);
}
export function buildEmail(
template: EmailTemplate,
to: string,
from: string,
): EmailMessage {
return {
from,
to,
subject: template.subject,
text: template.text,
html: `<p>${template.text.replaceAll("\n", "<br />")}</p>`,
};
}
|