-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: Move notify to lib * chore: Move files to sendEmail module * fix: Resolve circular dependency issue * feat: Break into routes and controller * test: Update test cases * docs: Add Swagger docs
- Loading branch information
1 parent
8ce1579
commit a083beb
Showing
21 changed files
with
555 additions
and
379 deletions.
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.