index.ts 1.18 KB
Newer Older
David Schwarzmann's avatar
David Schwarzmann committed
1
import {
2
3
4
    ContentfulClientApi,
    createClient,
    Entry
David Schwarzmann's avatar
David Schwarzmann committed
5
} from 'contentful'
David Schwarzmann's avatar
David Schwarzmann committed
6
7
8
9

const space = process.env.NEXT_PUBLIC_CONTENTFUL_SPACE_ID
const accessToken = process.env.NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN

David Schwarzmann's avatar
David Schwarzmann committed
10
const client: ContentfulClientApi = createClient({
11
12
    space,
    accessToken,
David Schwarzmann's avatar
David Schwarzmann committed
13
14
15
})

export type ServiceType = {
16
17
18
19
  contactInformation: object
  description: object
  developer: object
  documentationURL: string
David Schwarzmann's avatar
David Schwarzmann committed
20
21
  name: string
  shortDescription: object
22
  sourcecodeURL?: string
David Schwarzmann's avatar
David Schwarzmann committed
23
  status: string
24
25
  slug: string
  logo: object
26
  tags?: any[]
David Schwarzmann's avatar
David Schwarzmann committed
27
  tosURL?: string
28
29
30
31
32
33
}

export type Tag = {
  fields: {
    name: string
  }
David Schwarzmann's avatar
David Schwarzmann committed
34
35
}

36
37
38
39
40
41
export type Filter = {
  label: string,
  id: string,
  value: string,
}

David Schwarzmann's avatar
David Schwarzmann committed
42
export async function fetchServices(): Promise<Entry<any>[]> {
43
44
45
46
    const services = await client.getEntries({
        content_type: 'service',
    })
    if (services.items) return services.items
David Schwarzmann's avatar
David Schwarzmann committed
47
48
}

David Schwarzmann's avatar
David Schwarzmann committed
49
export async function fetchService(slug): Promise<Entry<any>> {
50
51
52
53
54
55
    const services = await client.getEntries({
        content_type: 'service',
    })
    return services.items.find(
        (service: Entry<ServiceType>) => service.fields.slug === slug
    )
David Schwarzmann's avatar
David Schwarzmann committed
56
57
58
}

export default { fetchServices, fetchService }