diff options
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/MomentService.ts | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index af602dc7..e227bc9e 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -6,7 +6,7 @@ import { MOMENT_TAGS_ENDPOINT, MOMENT_THUMBNAIL_ENDPOINT, } from '../constants'; -import {MomentTagType, MomentType} from '../types'; +import {MomentPostType, MomentTagType, MomentType} from '../types'; import {checkImageUploadStatus} from '../utils'; export const postMoment = async ( @@ -54,11 +54,7 @@ export const postMoment = async ( return undefined; }; -export const loadMoments: ( - userId: string, - token: string, -) => Promise<MomentType[]> = async (userId, token) => { - let moments: MomentType[] = []; +export const loadMoments = async (userId: string, token: string) => { try { const response = await fetch(MOMENTS_ENDPOINT + '?user_id=' + userId, { method: 'GET', @@ -66,19 +62,14 @@ export const loadMoments: ( Authorization: 'Token ' + token, }, }); - const status = response.status; - if (status === 200) { - const data = await response.json(); - moments = data; - } else { - console.log('Could not load moments!'); - return []; + if (response.status === 200) { + const typedData: MomentPostType[] = await response.json(); + return typedData; } } catch (err) { console.log(err); - return []; } - return moments; + return []; }; export const deleteMoment = async (momentId: string) => { |
