Skip to content

Commit

Permalink
feat: Save birthday to tribe
Browse files Browse the repository at this point in the history
Tribe should also receive birthdates for users. Adds convenience
function to BrpApi to format birthdates to iso 8601.
  • Loading branch information
joostvanderborg committed Nov 10, 2022
1 parent ba1adb7 commit e53831d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/app/linkuser/BrpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,19 @@ export class BrpApi {
}
return { number: 0, suffix: brpNumber };
}

/**
*
* @param brpDirthDay the birthday as provided by the API (dd-mm-yyyy format)
* @returns iso 8601 'extended' formatted date (YYYY-MM-DD)
*/
iso8601FormattedBirthday(brpDirthDay: string) {
// Ignore incomplete dates.
if (brpDirthDay.length !== 'yyyy-mm-dd'.length) { return undefined; }

const year = brpDirthDay.substring('dd-mm-'.length, 'dd-mm-yyyy'.length);
const month = brpDirthDay.substring('dd-'.length, 'dd-mm'.length);
const day = brpDirthDay.substring(0, 'dd'.length);
return `${year}-${month}-${day}`;
}
}
5 changes: 4 additions & 1 deletion src/app/linkuser/LinkUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class LinkUser {
FirstName: brpData.firstName,
LastName: brpData.lastName,
MiddleName: brpData.middleName,
BirthDate: brpData.iso8601Birthday,
});
await tribeUser.createAddress({
Street: brpData.street,
Expand All @@ -73,8 +74,10 @@ export class LinkUser {
const brpApi = new BrpApi(this.apiClient);
const brpData = await brpApi.getBrpData(bsn.bsn);
const splitNumber = brpApi.houseNumberHelper(brpData?.Persoon?.Adres?.Huisnummer);
const birthday = brpData?.Persoon?.Persoonsgegevens?.Geboortedatum;
const data = {
birthday: brpData?.Persoon?.Persoonsgegevens?.Geboortedatum,
birthday: birthday,
iso8601Birthday: brpApi.iso8601FormattedBirthday(birthday),
firstName: brpData?.Persoon?.Persoonsgegevens?.Voornamen,
lastName: brpData?.Persoon?.Persoonsgegevens?.Geslachtsnaam,
middleName: brpData?.Persoon?.Persoonsgegevens?.Voorvoegsel,
Expand Down
4 changes: 4 additions & 0 deletions src/app/linkuser/PersonRelation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ export interface PersonRelation {
FirstName: string;
LastName?: string;
MiddleName?: string;
/**
* Format: YYYY-MM-DD
*/
BirthDate?: string;
}
10 changes: 10 additions & 0 deletions src/app/linkuser/tests/tribeuser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ describe('Linking flow', () => {
});
});

describe('BRP birthday to YYYY-MM-dd', () => {
test('api can return formatted birthdates', async () => {
const client = new ApiClient();
const api = new BrpApi(client);
expect(api.iso8601FormattedBirthday('01-12-1854')).toBe('1854-12-01');
expect(api.iso8601FormattedBirthday('10-11-2022')).toBe('2022-11-10');
expect(api.iso8601FormattedBirthday('11-2022')).toBeUndefined();
});
});

describe('BRP housenumber', () => {
test('house number', () => {
const client = new ApiClient();
Expand Down

0 comments on commit e53831d

Please sign in to comment.