Skip to content

Commit

Permalink
feat: add startup sponsor (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-van-woerkens authored Aug 31, 2023
1 parent 9d3bd85 commit 3dd810c
Show file tree
Hide file tree
Showing 7 changed files with 3,244 additions and 38 deletions.
7 changes: 7 additions & 0 deletions src/app/startups/[id]/get-organisation.ts
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)
}
34 changes: 28 additions & 6 deletions src/app/startups/[id]/get-startup.ts
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)
)
}
8 changes: 8 additions & 0 deletions src/app/startups/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export default async function StartupPage({
pitch,
phases,
contact,
sponsors,
stats_url,
repository,
organisation,
accessibility_status,
content_url_encoded_markdown,
},
Expand Down Expand Up @@ -79,6 +81,12 @@ export default async function StartupPage({
<div>
<b>accessibility status</b>: {accessibility_status}
</div>
<div>
<b>sponsors</b>: {sponsors}
</div>
<div>
<b>organisation</b>: {organisation.name} ({organisation.acronym})
</div>
<div>
{phases.map((phase, i) => (
<div key={i}>
Expand Down
44 changes: 25 additions & 19 deletions src/app/startups/get-startups.ts
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[])
}
Loading

0 comments on commit 3dd810c

Please sign in to comment.