-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure lib and make some progress
- Loading branch information
Showing
37 changed files
with
484 additions
and
448 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
import { PARLIAMENT_BASE_URL } from "@lib/constants"; | ||
import serializeAbsence from "./parsers/absence"; | ||
|
||
interface Query { | ||
id: string; | ||
parliamentYears: string[]; | ||
} | ||
|
||
export default async function getAbsence({ | ||
id, | ||
parliamentYears, | ||
}: Query): Promise<number | null> { | ||
const query = new URLSearchParams({ | ||
iid: id, | ||
rm: parliamentYears.join(","), | ||
utformat: "json", | ||
gruppering: "namn", | ||
}); | ||
|
||
const response = await fetch( | ||
`${PARLIAMENT_BASE_URL}/voteringlista/?${query}`, | ||
{ | ||
next: { revalidate: 60 * 60 * 24 }, | ||
}, | ||
); | ||
const data = await response.json(); | ||
return serializeAbsence(data); | ||
} |
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,46 @@ | ||
import type { MemberDetailedResponse } from "./types"; | ||
import getAbsence from "./get-absence"; | ||
import getMember from "./get-member"; | ||
import { getCurrentMandatePeriod } from "../parliament/get-current-mandate-period"; | ||
|
||
export default async function getMemberWithAbsence( | ||
id: string, | ||
): Promise<MemberDetailedResponse | null> { | ||
// Get latest parliament year and mandate period | ||
const mandatePeriod = await getCurrentMandatePeriod(); | ||
|
||
const memberPromise = getMember(id); | ||
const absenceParliamentYearPromise = getAbsence({ | ||
id, | ||
parliamentYears: [mandatePeriod.latestParliamentYear], | ||
}); | ||
const absenceMandatePeriodPromise = getAbsence({ | ||
id, | ||
parliamentYears: mandatePeriod.parliamentYears, | ||
}); | ||
|
||
const [memberData, absenceParliamentYear, absenceMandatePeriod] = | ||
await Promise.all([ | ||
memberPromise, | ||
absenceParliamentYearPromise, | ||
absenceMandatePeriodPromise, | ||
]); | ||
|
||
if (!memberData) { | ||
return null; | ||
} | ||
|
||
return { | ||
...memberData, | ||
absence: { | ||
mandatePeriod: { | ||
value: absenceMandatePeriod, | ||
description: mandatePeriod.period, | ||
}, | ||
parliamentYear: { | ||
value: absenceParliamentYear, | ||
description: mandatePeriod.latestParliamentYear, | ||
}, | ||
}, | ||
}; | ||
} |
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,12 @@ | ||
import { PARLIAMENT_BASE_URL } from "@lib/constants"; | ||
import type { MemberResponse } from "./types"; | ||
import { parseMember } from "./parsers/member"; | ||
import type { PersonListSingle } from "../parliament/types"; | ||
|
||
export default async function getMember(id: string): Promise<MemberResponse> { | ||
const response = await fetch(`${PARLIAMENT_BASE_URL}/person/${id}/json`, { | ||
next: { revalidate: 60 * 60 * 24 }, | ||
}); | ||
const data: PersonListSingle = await response.json(); | ||
return parseMember(data.personlista.person); | ||
} |
Oops, something went wrong.