Fixed WikiTree API not always returning the Spouses field

This commit is contained in:
Przemek Wiech
2021-09-18 22:15:00 +02:00
parent 4c788bc72f
commit 04a7a6b224

View File

@@ -55,7 +55,7 @@ interface Person {
FirstName: string; FirstName: string;
LastNameAtBirth: string; LastNameAtBirth: string;
RealName: string; RealName: string;
Spouses: {[key: number]: Person}; Spouses?: {[key: number]: Person};
Children: {[key: number]: Person}; Children: {[key: number]: Person};
Mother: number; Mother: number;
Father: number; Father: number;
@@ -250,7 +250,9 @@ export async function loadWikiTree(
); );
} }
const spouseKeys = Object.values(firstPerson[0].Spouses).map((s) => s.Name); const spouseKeys = Object.values(firstPerson[0].Spouses || {}).map(
(s) => s.Name,
);
const ancestors = await Promise.all( const ancestors = await Promise.all(
[key] [key]
.concat(spouseKeys) .concat(spouseKeys)
@@ -317,7 +319,7 @@ export async function loadWikiTree(
const people = await getRelatives(toFetch, handleCors); const people = await getRelatives(toFetch, handleCors);
everyone.push(...people); everyone.push(...people);
const allSpouses = people.flatMap((person) => const allSpouses = people.flatMap((person) =>
Object.values(person.Spouses), Object.values(person.Spouses || {}),
); );
everyone.push(...allSpouses); everyone.push(...allSpouses);
// Fetch all children. // Fetch all children.