Skip to content

Commit

Permalink
feat: confirm the registration on death too
Browse files Browse the repository at this point in the history
  • Loading branch information
naftis committed Dec 11, 2024
1 parent 338eeca commit 25253c1
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/server/src/webhooks/opencrvs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getTrackingId,
} from "../types/fhir";
import * as opencrvs from "../opencrvs-api";
import { generateRegistrationNumber } from "../registration-number";

export const opencrvsRecordSchema = z
.object({
Expand Down Expand Up @@ -69,9 +70,32 @@ export const opencrvsHandler = async (

if (eventType === EVENT_TYPE.DEATH) {
const nid = getDeceasedNid(request.body);
await mosip.postDeathRecord({
const response = await mosip.postDeathRecord({
nid,
});
const registrationNumber = generateRegistrationNumber(trackingId);

let comment: string;
if (response.status === 404) {
comment = `NID "${nid}" not found`;
} else if (response.status === 409) {
comment = `NID "${nid}" already deactivated`;
} else if (response.ok) {
comment = `NID "${nid}" deactivated`;
} else {
throw new Error(
`NID deactivation failed in MOSIP. Response: ${response.statusText}`
);
}

await opencrvs.confirmRegistration(
{
id: eventId,
registrationNumber,
comment,
},
{ headers: { Authorization: `Bearer ${token}` } }
);
}

return reply.code(202).send();
Expand Down

0 comments on commit 25253c1

Please sign in to comment.