-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Send email docs #2432
Merged
Merged
feat: Send email docs #2432
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
578da76
chore: Move notify to lib
DafyddLlyr 9a11917
chore: Move files to sendEmail module
DafyddLlyr b4c4912
fix: Resolve circular dependency issue
DafyddLlyr 2ac0e08
feat: Break into routes and controller
DafyddLlyr b9543c2
test: Update test cases
DafyddLlyr 3e39070
docs: Add Swagger docs
DafyddLlyr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
api.planx.uk/notify/notify.ts → api.planx.uk/lib/notify/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
api.planx.uk/modules/saveAndReturn/service/resumeApplication.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
sendSinglePaymentEmail, | ||
sendAgentAndPayeeConfirmationEmail, | ||
} from "../../inviteToPay"; | ||
import { sendSingleApplicationEmail } from "../saveAndReturn/service/utils"; | ||
import { ServerError } from "../../errors"; | ||
import { NextFunction } from "express"; | ||
import { | ||
ConfirmationEmail, | ||
PaymentEmail, | ||
SingleApplicationEmail, | ||
} from "./types"; | ||
|
||
export const singleApplicationEmailController: SingleApplicationEmail = async ( | ||
_req, | ||
res, | ||
next, | ||
) => { | ||
const { email, sessionId } = res.locals.parsedReq.body.payload; | ||
const { template } = res.locals.parsedReq.params; | ||
|
||
try { | ||
const response = await sendSingleApplicationEmail({ | ||
template, | ||
email, | ||
sessionId, | ||
}); | ||
return res.json(response); | ||
} catch (error) { | ||
emailErrorHandler(next, error, template); | ||
} | ||
}; | ||
|
||
export const paymentEmailController: PaymentEmail = async (_req, res, next) => { | ||
const { paymentRequestId } = res.locals.parsedReq.body.payload; | ||
const { template } = res.locals.parsedReq.params; | ||
|
||
try { | ||
const response = await sendSinglePaymentEmail({ | ||
template, | ||
paymentRequestId, | ||
}); | ||
return res.json(response); | ||
} catch (error) { | ||
emailErrorHandler(next, error, template); | ||
} | ||
}; | ||
|
||
export const confirmationEmailController: ConfirmationEmail = async ( | ||
_req, | ||
res, | ||
next, | ||
) => { | ||
const { lockedAt, sessionId, email } = res.locals.parsedReq.body.payload; | ||
const { template } = res.locals.parsedReq.params; | ||
|
||
try { | ||
// if the session is locked we can infer that a payment request has been initiated | ||
const paymentRequestInitiated = Boolean(lockedAt); | ||
if (paymentRequestInitiated) { | ||
const response = await sendAgentAndPayeeConfirmationEmail(sessionId); | ||
return res.json(response); | ||
} else { | ||
const response = await sendSingleApplicationEmail({ | ||
template, | ||
email, | ||
sessionId, | ||
}); | ||
return res.json(response); | ||
} | ||
} catch (error) { | ||
emailErrorHandler(next, error, template); | ||
} | ||
}; | ||
|
||
const emailErrorHandler = ( | ||
next: NextFunction, | ||
error: unknown, | ||
template: string, | ||
) => | ||
next( | ||
new ServerError({ | ||
status: error instanceof ServerError ? error.status : undefined, | ||
message: `Failed to send "${template}" email. ${ | ||
(error as Error).message | ||
}`, | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
openapi: 3.1.0 | ||
info: | ||
title: Plan✕ API | ||
version: 0.1.0 | ||
tags: | ||
- name: send email | ||
description: Send templated emails via the GovNotify service | ||
components: | ||
schemas: | ||
SendEmailRequest: | ||
type: object | ||
properties: | ||
payload: | ||
oneOf: | ||
- $ref: "#/components/schemas/SingleApplicationPayload" | ||
- $ref: "#/components/schemas/PaymentPayload" | ||
- $ref: "#/components/schemas/ConfirmationPayload" | ||
SingleApplicationPayload: | ||
type: object | ||
properties: | ||
email: | ||
type: string | ||
format: email | ||
sessionId: | ||
type: string | ||
PaymentPayload: | ||
type: object | ||
properties: | ||
paymentRequestId: | ||
type: string | ||
ConfirmationPayload: | ||
type: object | ||
properties: | ||
sessionId: | ||
type: string | ||
lockedAt: | ||
type: string | ||
format: date-time | ||
nullable: true | ||
email: | ||
type: string | ||
format: email | ||
responses: | ||
SendEmailResponse: | ||
type: object | ||
properties: | ||
message: | ||
type: string | ||
expiryDate: | ||
type: string | ||
format: date-time | ||
nullable: true | ||
paths: | ||
/send-email/{template}: | ||
post: | ||
tags: [send email] | ||
summary: Send an email | ||
parameters: | ||
- name: template | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
description: GovNotify template to use | ||
enum: | ||
[ | ||
"reminder", | ||
"expiry", | ||
"save", | ||
"invite-to-pay", | ||
"invite-to-pay-agent", | ||
"payment-reminder", | ||
"payment-reminder-agent", | ||
"payment-expiry", | ||
"payment-expiry-agent", | ||
"confirmation", | ||
] | ||
requestBody: | ||
description: | | ||
Request body for sending email. | ||
The structure varies based on the template. | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/SendEmailRequest" | ||
responses: | ||
"200": | ||
description: Email sent successfully | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/responses/SendEmailResponse" | ||
"500": | ||
$ref: "#/components/responses/ErrorMessage" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to move this into a shared
utils.ts
as I was hitting an issue with circular dependencies on the build application.