Skip to content

Commit

Permalink
feat(data-access): add get haqq whitepaper method
Browse files Browse the repository at this point in the history
  • Loading branch information
hadzhehsen authored and kioqq committed Feb 13, 2024
1 parent 37ff893 commit 4d92ebc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
33 changes: 14 additions & 19 deletions apps/haqq-website/utils/get-whitepaper.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import { cache } from 'react';
import { getIslamicWhitepaperData } from '@haqq/data-access-falconer';
import { getHaqqWhitepaperData } from '@haqq/data-access-falconer';
import { REVALIDATE_TIME } from '../constants';

export const revalidate = REVALIDATE_TIME;

export const getWhitepaperContentFromFalconer = cache(
async (locale?: string) => {
try {
const data = await getIslamicWhitepaperData(
{
next: {
revalidate,
},
},
locale ?? 'en',
);
export const getWhitepaperContentFromFalconer = cache(async () => {
try {
const data = await getHaqqWhitepaperData({
next: {
revalidate,
},
});

return data;
} catch (error) {
console.error(error);
}
return data;
} catch (error) {
console.error(error);
}

return '';
},
);
return '';
});
1 change: 1 addition & 0 deletions libs/data-access/falconer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './lib/haqq/get-haqq-partners';
export * from './lib/haqq/get-haqq-blog-posts';
export * from './lib/haqq/get-haqq-privacy-policy';
export * from './lib/haqq/get-haqq-price';
export * from './lib/haqq/get-haqq-whitepaper';
export * from './lib/islamic/get-islamic-members';
export * from './lib/islamic/get-islamic-whitepaper';
export * from './lib/islamic/get-islamic-news';
Expand Down
21 changes: 21 additions & 0 deletions libs/data-access/falconer/src/lib/haqq/get-haqq-whitepaper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FALCONER_ENDPOINT } from '../../constants';
import { FalconerRequestInit } from '../../types';

export async function getHaqqWhitepaperData(
options: Partial<FalconerRequestInit>,

Check warning on line 5 in libs/data-access/falconer/src/lib/haqq/get-haqq-whitepaper.ts

View check run for this annotation

Codecov / codecov/patch

libs/data-access/falconer/src/lib/haqq/get-haqq-whitepaper.ts#L3-L5

Added lines #L3 - L5 were not covered by tests
) {
const requestUrl = new URL('/haqq/wp', FALCONER_ENDPOINT);

const response = await fetch(requestUrl, {

Check warning on line 9 in libs/data-access/falconer/src/lib/haqq/get-haqq-whitepaper.ts

View check run for this annotation

Codecov / codecov/patch

libs/data-access/falconer/src/lib/haqq/get-haqq-whitepaper.ts#L9

Added line #L9 was not covered by tests
method: 'GET',
...options,
});

Check warning on line 12 in libs/data-access/falconer/src/lib/haqq/get-haqq-whitepaper.ts

View check run for this annotation

Codecov / codecov/patch

libs/data-access/falconer/src/lib/haqq/get-haqq-whitepaper.ts#L11-L12

Added lines #L11 - L12 were not covered by tests

if (!response.ok) {
throw new Error('Whitepaper fetch failed');
}

const responseJson = await response.json();

return responseJson.wp as string;
}

0 comments on commit 4d92ebc

Please sign in to comment.