-
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 send to module * chore: Consolidate existing docs * chore: Move to subfolders * feat: Document and add validation layer to create send events endpoint * test: Update test import refs * feat: Donwload application files * fix: Linting after rebase
- Loading branch information
1 parent
ec449ba
commit a706501
Showing
23 changed files
with
560 additions
and
445 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
8 changes: 4 additions & 4 deletions
8
api.planx.uk/send/bops.test.ts → api.planx.uk/modules/send/bops/bops.test.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,59 @@ | ||
import { | ||
CombinedResponse, | ||
createScheduledEvent, | ||
} from "../../../lib/hasura/metadata"; | ||
import { CreateSendEventsController } from "./types"; | ||
|
||
// Create "One-off Scheduled Events" in Hasura from Send component for selected destinations | ||
const createSendEvents: CreateSendEventsController = async ( | ||
_req, | ||
res, | ||
next, | ||
) => { | ||
const { email, uniform, bops } = res.locals.parsedReq.body; | ||
const { sessionId } = res.locals.parsedReq.params; | ||
|
||
try { | ||
const now = new Date(); | ||
const combinedResponse: CombinedResponse = {}; | ||
|
||
if (email) { | ||
const emailSubmissionEvent = await createScheduledEvent({ | ||
webhook: `{{HASURA_PLANX_API_URL}}/email-submission/${email.localAuthority}`, | ||
schedule_at: now, | ||
payload: email.body, | ||
comment: `email_submission_${sessionId}`, | ||
}); | ||
combinedResponse["email"] = emailSubmissionEvent; | ||
} | ||
|
||
if (bops) { | ||
const bopsEvent = await createScheduledEvent({ | ||
webhook: `{{HASURA_PLANX_API_URL}}/bops/${bops.localAuthority}`, | ||
schedule_at: new Date(now.getTime() + 30 * 1000), | ||
payload: bops.body, | ||
comment: `bops_submission_${sessionId}`, | ||
}); | ||
combinedResponse["bops"] = bopsEvent; | ||
} | ||
|
||
if (uniform) { | ||
const uniformEvent = await createScheduledEvent({ | ||
webhook: `{{HASURA_PLANX_API_URL}}/uniform/${uniform.localAuthority}`, | ||
schedule_at: new Date(now.getTime() + 60 * 1000), | ||
payload: uniform.body, | ||
comment: `uniform_submission_${sessionId}`, | ||
}); | ||
combinedResponse["uniform"] = uniformEvent; | ||
} | ||
|
||
return res.json(combinedResponse); | ||
} catch (error) { | ||
return next({ | ||
error, | ||
message: `Failed to create send event(s) for session ${sessionId}. Error: ${error}`, | ||
}); | ||
} | ||
}; | ||
|
||
export { createSendEvents }; |
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,26 @@ | ||
import { z } from "zod"; | ||
import { CombinedResponse } from "../../../lib/hasura/metadata"; | ||
import { ValidatedRequestHandler } from "../../../shared/middleware/validate"; | ||
|
||
const eventSchema = z.object({ | ||
localAuthority: z.string(), | ||
body: z.object({ | ||
sessionId: z.string().uuid(), | ||
}), | ||
}); | ||
|
||
export const combinedEventsPayloadSchema = z.object({ | ||
body: z.object({ | ||
email: eventSchema.optional(), | ||
bops: eventSchema.optional(), | ||
uniform: eventSchema.optional(), | ||
}), | ||
params: z.object({ | ||
sessionId: z.string().uuid(), | ||
}), | ||
}); | ||
|
||
export type CreateSendEventsController = ValidatedRequestHandler< | ||
typeof combinedEventsPayloadSchema, | ||
CombinedResponse | ||
>; |
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,138 @@ | ||
info: | ||
title: Plan✕ API | ||
version: 0.1.0 | ||
tags: | ||
- name: send | ||
components: | ||
schemas: | ||
EventSchema: | ||
type: object | ||
properties: | ||
localAuthority: | ||
type: string | ||
body: | ||
type: object | ||
properties: | ||
sessionId: | ||
type: string | ||
format: uuid | ||
required: | ||
- localAuthority | ||
- body | ||
paths: | ||
/bops/{localAuthority}: | ||
post: | ||
summary: Submits an application to the Back Office Planning System (BOPS) | ||
description: Submits an application to the Back Office Planning System (BOPS) | ||
tags: | ||
- send | ||
parameters: | ||
- $ref: "#/components/parameters/localAuthority" | ||
security: | ||
- hasuraAuth: [] | ||
requestBody: | ||
description: This endpoint is only called via Hasura's scheduled event webhook, so body is wrapped in a `payload` key | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/SessionPayload" | ||
/email-submission/{localAuthority}: | ||
post: | ||
summary: Sends an application by email using GOV.UK Notify | ||
description: Send an application by email using GOV.UK Notify. The email body includes a link to download the application files. | ||
tags: | ||
- send | ||
parameters: | ||
- $ref: "#/components/parameters/localAuthority" | ||
security: | ||
- hasuraAuth: [] | ||
requestBody: | ||
description: This endpoint is only called via Hasura's scheduled event webhook, so body is wrapped in a `payload` key | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/SessionPayload" | ||
/uniform/{localAuthority}: | ||
post: | ||
summary: Submits an application to Uniform | ||
description: Submits an application to Uniform | ||
tags: | ||
- send | ||
parameters: | ||
- $ref: "#/components/parameters/localAuthority" | ||
security: | ||
- hasuraAuth: [] | ||
requestBody: | ||
description: This endpoint is only called via Hasura's scheduled event webhook, so body is wrapped in a `payload` key | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/SessionPayload" | ||
/create-send-events/{sessionId}: | ||
post: | ||
summary: Create send events | ||
description: Create "One-off Scheduled Events" in Hasura from Send component for selected destinations | ||
tags: | ||
- send | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
email: | ||
$ref: "#/components/schemas/EventSchema" | ||
bops: | ||
$ref: "#/components/schemas/EventSchema" | ||
uniform: | ||
$ref: "#/components/schemas/EventSchema" | ||
required: | ||
- bops | ||
- uniform | ||
parameters: | ||
- in: query | ||
name: sessionId | ||
required: true | ||
schema: | ||
type: string | ||
format: uuid | ||
/download-application-files/{sessionId}: | ||
get: | ||
summary: Download application files | ||
description: Download application files via a link send to a team's "send to email" email address | ||
tags: | ||
- send | ||
parameters: | ||
- in: path | ||
name: sessionId | ||
required: true | ||
schema: | ||
type: string | ||
format: uuid | ||
- in: query | ||
name: sessionId | ||
required: true | ||
schema: | ||
type: string | ||
format: uuid | ||
- in: query | ||
name: email | ||
required: true | ||
schema: | ||
type: string | ||
format: email | ||
- in: query | ||
name: localAuthority | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
"200": | ||
$ref: "#/components/responses/DownloadFile" | ||
"500": | ||
$ref: "#/components/responses/ErrorMessage" |
Oops, something went wrong.