Skip to content

Commit

Permalink
Fixed bug formatting date
Browse files Browse the repository at this point in the history
  • Loading branch information
euanmillar committed Jan 10, 2025
1 parent 7f835dd commit 4b52130
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/server/src/esignet-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { logger } from "./logger";
import z from "zod";
import { FastifyReply, FastifyRequest } from "fastify";
import * as jose from "jose";
import { isValid, format, Locale } from 'date-fns';
import { isValid, format, Locale, parse } from 'date-fns';
import { enGB } from 'date-fns/locale/en-GB';
import { fr } from 'date-fns/locale/fr';

Expand Down Expand Up @@ -99,7 +99,6 @@ const generateSignedJwt = async (clientId: string) => {
env.OIDP_CLIENT_PRIVATE_KEY!,
"base64"
)?.toString();
console.log("decodeKey: ", decodeKey)

const jwkObject = JSON.parse(decodeKey);
const privateKey = await jose.importJWK(jwkObject, JWT_ALG);
Expand Down Expand Up @@ -206,7 +205,8 @@ const findAdminStructureLocationWithName = async (name: string) => {
return fhirBundleLocations.entry?.[0].resource?.id;
};

function formatDate(date: Date | number, formatStr = 'PP') {
function formatDate(dateString: string, formatStr = 'PP') {
const date = parse(dateString, 'dd/MM/yyyy', new Date());
if (!isValid(date)) {
return ''
}
Expand All @@ -227,7 +227,7 @@ const pickUserInfo = async (userInfo: OIDPUserInfo) => {
familyName: userInfo.family_name,
gender: userInfo.gender,
...(userInfo.birthdate && {
birthDate: formatDate(new Date(userInfo.birthdate), 'yyyy-MM-dd'),
birthDate: formatDate(userInfo.birthdate, 'yyyy-MM-dd'),
}),
/*stateFhirId,
districtFhirId:
Expand All @@ -249,6 +249,5 @@ export const fetchUserInfo = async (accessToken: string) => {

const response = await request.text();
const decodedResponse = decodeUserInfoResponse(response);

return pickUserInfo(decodedResponse);
};

0 comments on commit 4b52130

Please sign in to comment.