-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSpecies.ts
38 lines (31 loc) · 1.05 KB
/
getSpecies.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { Asset } from 'contentful';
import type { SpeciesEntry, ContentTypeSpeciesPage } from './types';
import { ContentTypes } from './constants';
import { contentfulDeliveryClient } from './contentful';
import { flattenImageAssetFields } from './flattenAssetFields';
/**
* Queries and returns species page entries from Contentful.
* @returns Species page entries.
*/
const getSpecies = async (): Promise<Array<SpeciesEntry>> => {
const { items } = await contentfulDeliveryClient.getEntries<ContentTypeSpeciesPage>({
content_type: ContentTypes.SpeciesPage,
order: ['fields.name'],
limit: 1000,
});
const data = items.map(({ fields }) => ({
name: fields.name,
slug: fields.slug,
order: fields.order,
suborder: fields.suborder,
family: fields.family,
subfamily: fields.subfamily ?? null,
genus: fields.genus,
species: fields.species,
content: fields.content,
description: fields.description,
image: flattenImageAssetFields(fields.image as Asset),
}));
return data;
};
export default getSpecies;