Skip to content

Commit

Permalink
chore: emails (#128)
Browse files Browse the repository at this point in the history
update email templates
  • Loading branch information
jlangy authored Nov 20, 2023
1 parent b120ccd commit a4511ba
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/pages/api/realms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ValidationError } from 'yup';
import omit from 'lodash.omit';
import pick from 'lodash.pick';
import kebabCase from 'lodash.kebabcase';
import { sendCreateEmail } from 'utils/mailer';

interface ErrorData {
success: boolean;
Expand Down Expand Up @@ -116,7 +117,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
idirUserId: username,
details: pick(newRealm, allowedFormFields),
});

sendCreateEmail(newRealm).catch((err) => console.error(`Error sending email for ${data.realm}`, err));
return res.status(201).json(newRealm);
}
} catch (err: any) {
Expand Down
7 changes: 6 additions & 1 deletion app/pages/api/realms/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
let updaterRole = '';
let isPO = false;
let updatedRealm: any;
let updatingApprovalStatus = false;

try {
const lastUpdatedBy = `${session.user.family_name}, ${session.user.given_name}`;
Expand Down Expand Up @@ -118,6 +119,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
!currentRequest.prNumber &&
!currentRequest.approved
) {
updatingApprovalStatus = true;
await createEvent({
realmId: parseInt(req.query.id as string, 10),
eventCode: EventEnum.REQUEST_APPROVE_SUCCESS,
Expand All @@ -138,6 +140,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
String(updateRequest.approved) === 'false' &&
!currentRequest.prNumber
) {
updatingApprovalStatus = true;
await createEvent({
realmId: parseInt(req.query.id as string, 10),
eventCode: EventEnum.REQUEST_REJECT_SUCCESS,
Expand Down Expand Up @@ -195,7 +198,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
details: getUpdatedProperties(currentRequest, updatedRealm),
});
updatedRealm = !isAdmin ? omit(updatedRealm, adminOnlyFields) : updatedRealm;
sendUpdateEmail(updatedRealm, session);
sendUpdateEmail(updatedRealm, session, updatingApprovalStatus).catch((err) =>
console.error(`Error sending email for ${updatedRealm.realm}`, err),
);
return res.send(updatedRealm);
} catch (err) {
await createEvent({
Expand Down
Loading

0 comments on commit a4511ba

Please sign in to comment.