diff --git a/src/fetch.ts b/src/fetch.ts index 4e19296..cb41dca 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -28,12 +28,20 @@ export const fetchUserIdByName = ({ userName }: { userName: string }) => { }) } -export const fetchUserProfile = ({ userId }: { userId: string }) => { +type fetchUserParams = { userId?: string, userName: string } | { userId: string, userName?: string } + +export const fetchUserProfile = async ({ userId, userName }: fetchUserParams) => { + if(userName && !userId) { + userId = await fetchUserIdByName({ userName }); + } const variables = JSON.stringify({ userID: userId }); return fetchBase({ documentId: ENDPOINTS_DOCUMENT_ID.USER_PROFILE, variables }) } -export const fetchUserThreads = ({ userId }: {userId: string}) => { +export const fetchUserThreads = async ({ userId, userName }: fetchUserParams) => { + if(userName && !userId) { + userId = await fetchUserIdByName({ userName }); + } const variables = JSON.stringify({ userID: userId }); return fetchBase({ documentId: ENDPOINTS_DOCUMENT_ID.USER_THREADS, variables }) } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 5f1e03b..7e191bf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,5 +3,5 @@ import { fetchUserIdByName, fetchUserProfile, fetchUserThreads } from "./fetch"; const midudevId = '8242141302'; -const response = await fetchUserIdByName({ userName: 'midu.dev' }); +const response = await fetchUserThreads({ userName: 'midu.dev' }); console.log(response); \ No newline at end of file