-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d3bd85
commit 3dd810c
Showing
7 changed files
with
3,244 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import organisations from "../organisations.json" | ||
|
||
export type Organisation = (typeof organisations)[number] | ||
|
||
export default function getOrganisation(id: string) { | ||
return organisations.find((organisation) => organisation.id === id) | ||
} |
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 |
---|---|---|
@@ -1,18 +1,40 @@ | ||
import json from "../startups.json" | ||
import getOrganisation, { type Organisation } from "./get-organisation" | ||
|
||
type Startup = Extract<(typeof json)["data"][number], { attributes: any }> | ||
export type Startup = Extract< | ||
(typeof json)["data"][number], | ||
{ attributes: any } | ||
> & { | ||
attributes: { organisation: Organisation } | ||
} | ||
|
||
export default function getStartup(id: string): Startup { | ||
const { data: startups } = json | ||
const data = json.data as Startup[] | ||
|
||
return ( | ||
startups | ||
.filter( | ||
(startup) => | ||
data | ||
.reduce((startups, startup) => { | ||
if ( | ||
startup.id === id && | ||
startup.type === "startup" && | ||
startup.relationships.incubator.data.id === "sgmas" | ||
) | ||
) { | ||
const { | ||
attributes: { | ||
sponsors: [sponsor, ...rest], | ||
}, | ||
} = startup | ||
const organisation = getOrganisation( | ||
sponsor.replace("/organisations/", "") | ||
) | ||
if (organisation) { | ||
startup.attributes.organisation = organisation | ||
} | ||
startups.push(startup) | ||
} | ||
|
||
return startups | ||
}, [] as Startup[]) | ||
.pop() || ({ attributes: {} } as Startup) | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,33 @@ | ||
import json from "./startups.json" | ||
import { Startup } from "./[id]/get-startup" | ||
import getOrganisation from "./[id]/get-organisation" | ||
|
||
export type Startup = (typeof json.data)[number] | ||
|
||
export default function getStartups() { | ||
const { data } = json | ||
export default function getStartups(): Startup[] { | ||
const data = json.data as Startup[] | ||
const excludedPhases = ["transfer", "alumni"] | ||
|
||
return data.reduce( | ||
(startups, startup) => { | ||
const { | ||
attributes: { phases }, | ||
} = startup | ||
return data.reduce((startups, startup) => { | ||
const { | ||
attributes: { | ||
phases, | ||
sponsors: [sponsor, ...rest], | ||
}, | ||
} = startup | ||
|
||
if ( | ||
startup.type === "startup" && | ||
startup.relationships.incubator.data.id === "sgmas" && | ||
!phases.some((phase) => excludedPhases.includes(phase.name)) | ||
) { | ||
startups.push(startup) | ||
if ( | ||
startup.type === "startup" && | ||
startup.relationships.incubator.data.id === "sgmas" && | ||
!phases.some((phase) => excludedPhases.includes(phase.name)) | ||
) { | ||
const organisation = getOrganisation( | ||
sponsor.replace("/organisations/", "") | ||
) | ||
if (organisation) { | ||
startup.attributes.organisation = organisation | ||
} | ||
startups.push(startup) | ||
} | ||
|
||
return startups | ||
}, | ||
[] as typeof json.data | ||
) | ||
return startups | ||
}, [] as Startup[]) | ||
} |
Oops, something went wrong.