Skip to content

Commit

Permalink
Refactor fetchUserProfile and fetchUserThreads
Browse files Browse the repository at this point in the history
  • Loading branch information
dvque committed Feb 1, 2024
1 parent e9de633 commit 86a5bbc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 86a5bbc

Please sign in to comment.