-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initial informant verification * fix: change field value to be "verified" on success * feat: add handler for approval action * chore: bump up version --------- Co-authored-by: Tameem Bin Haider <haidertameem@gmail.com>
- Loading branch information
1 parent
b6ba27c
commit ba137ef
Showing
14 changed files
with
194 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,70 @@ | ||
import type * as Hapi from "@hapi/hapi"; | ||
import fetch from "node-fetch"; | ||
|
||
/** | ||
* Replaces event registration handler in country config | ||
*/ | ||
export const mosipRegistrationHandler = ({ url }: { url: string }) => | ||
(async (request: Hapi.Request, h: Hapi.ResponseToolkit) => { | ||
const OPENCRVS_MOSIP_GATEWAY_URL = new URL("./webhooks/opencrvs", url); | ||
const MOSIP_API_REGISTRATION_EVENT_URL = new URL( | ||
"./events/registration", | ||
url, | ||
); | ||
|
||
const response = await fetch(OPENCRVS_MOSIP_GATEWAY_URL, { | ||
const response = await fetch(MOSIP_API_REGISTRATION_EVENT_URL, { | ||
method: "POST", | ||
body: JSON.stringify(request.payload), | ||
headers: request.headers, | ||
headers: { | ||
...request.headers, | ||
"content-type": "application/json", | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
return h | ||
.response({ | ||
error: "OpenCRVS-MOSIP gateway did not return a 200", | ||
error: "OpenCRVS-MOSIP event registration route did not return a 200", | ||
response: await response.text(), | ||
}) | ||
.code(500); | ||
} | ||
|
||
return h.response({ success: true }).code(200); | ||
}) satisfies Hapi.ServerRoute["handler"]; | ||
|
||
/** | ||
* Replaces `/events/{event}/actions/sent-notification-for-review` handler in country config | ||
*/ | ||
export const mosipRegistrationForReviewHandler = ({ url }: { url: string }) => | ||
(async (request: Hapi.Request, h: Hapi.ResponseToolkit) => { | ||
// Corresponds to `packages/mosip-api` /events/review -route | ||
const MOSIP_API_REVIEW_EVENT_URL = new URL("./events/review", url); | ||
|
||
console.info(request.headers); | ||
|
||
const response = await fetch(MOSIP_API_REVIEW_EVENT_URL, { | ||
method: "POST", | ||
body: JSON.stringify(request.payload), | ||
headers: { | ||
...request.headers, | ||
"content-type": "application/json", | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
return h | ||
.response({ | ||
error: "OpenCRVS-MOSIP event review route did not return a 200", | ||
response: await response.text(), | ||
}) | ||
.code(500); | ||
} | ||
|
||
return h.response({ success: true }).code(200); | ||
}) satisfies Hapi.ServerRoute["handler"]; | ||
|
||
/** | ||
* Replaces `/events/{event}/actions/sent-for-approval` handler in country config | ||
* Currently the same as `/events/{event}/actions/sent-notification-for-review` | ||
*/ | ||
export const mosipRegistrationForApprovalHandler = mosipRegistrationForReviewHandler |
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
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,38 @@ | ||
import { FastifyRequest, FastifyReply } from "fastify"; | ||
import { getComposition, getInformantType } from "../types/fhir"; | ||
import { updateField } from "../opencrvs-api"; | ||
|
||
type OpenCRVSRequest = FastifyRequest<{ | ||
Body: fhir3.Bundle; | ||
}>; | ||
|
||
export const reviewEventHandler = async ( | ||
request: OpenCRVSRequest, | ||
reply: FastifyReply, | ||
) => { | ||
const informantType = getInformantType(request.body); | ||
const { id: eventId } = getComposition(request.body); | ||
|
||
if (!request.headers.authorization) { | ||
return reply.code(401).send({ error: "Authorization header is missing" }); | ||
} | ||
|
||
const token = request.headers.authorization.split(" ")[1]; | ||
if (!token) { | ||
return reply | ||
.code(401) | ||
.send({ error: "Token is missing in Authorization header" }); | ||
} | ||
|
||
// Initial test of the verification, we will verify only other informants than mother and father | ||
if (informantType !== "mother" && informantType !== "father") { | ||
await updateField( | ||
eventId, | ||
`birth.informant.informant-view-group.verified`, | ||
'verified', | ||
{ headers: { Authorization: `Bearer ${token}` } }, | ||
); | ||
} | ||
|
||
return reply.code(200).send({ success: true }); | ||
}; |
File renamed without changes.
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