diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-20 00:15:20 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-20 00:15:20 +0100 |
| commit | fa6adedc42e9c6ec39cc30df16b54900c220b094 (patch) | |
| tree | 6bb498beadaa382245cecb86ce56931580313c6f /src/services/graphql/pages.ts | |
| parent | 2ff898626c5c0abc6b8195224067b992403e313b (diff) | |
refactor: rewrite types and services
I was repeating myself a lot in services. So I rewrited the different
functions to improve readability and I extracted some formatting
functions to put them in utils. I also rewrited/reorganized some types
to keep consistent names.
Diffstat (limited to 'src/services/graphql/pages.ts')
| -rw-r--r-- | src/services/graphql/pages.ts | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/src/services/graphql/pages.ts b/src/services/graphql/pages.ts deleted file mode 100644 index 0781d44..0000000 --- a/src/services/graphql/pages.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { - FetchPageByUriReturn, - GetPageReturn, - Page, - PageResponse, - RawPage, -} from '@ts/types/pages'; -import { gql } from 'graphql-request'; -import { getGraphQLClient } from './client'; - -const fetchPageByUri: FetchPageByUriReturn = async (uri: string) => { - const client = getGraphQLClient(); - const query = gql` - query PageByUri($uri: String!) { - pageBy(uri: $uri) { - contentParts { - afterMore - beforeMore - } - date - modified - title - } - } - `; - - const variables = { uri }; - - try { - const response: PageResponse = await client.request(query, variables); - return response.pageBy; - } catch (error) { - console.error(JSON.stringify(error, undefined, 2)); - process.exit(1); - } -}; - -const getFormattedPage = (page: RawPage) => { - const formattedPage: Page = { - ...page, - content: page.contentParts.afterMore, - intro: page.contentParts.beforeMore, - }; - - return formattedPage; -}; - -export const getCVPage: GetPageReturn = async () => { - const rawCV = await fetchPageByUri('/cv/'); - const formattedCV = getFormattedPage(rawCV); - - return formattedCV; -}; - -export const getLegalNoticePage: GetPageReturn = async () => { - const rawLegalNotice = await fetchPageByUri('/mentions-legales'); - const formattedLegalNotice = getFormattedPage(rawLegalNotice); - - return formattedLegalNotice; -}; |
