Skip to content

Commit

Permalink
feat: add my api
Browse files Browse the repository at this point in the history
  • Loading branch information
timepresent95 committed Aug 20, 2024
1 parent 7357758 commit 1034917
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/api/my.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {kyInstance} from './ky';
import {myApis} from './routes';

import {UserInfo} from '@/types';
import {createUrl} from '@/utils/url';

type ParamGetMy = {userId: string};

type ResponseGetMy = {
family: UserInfo[];
familyCode: string;
} & UserInfo;

async function getMy({userId}: ParamGetMy) {
const apiUrl = createUrl(myApis.getMy, {param: {userId}});
return await kyInstance.get(apiUrl).json<ResponseGetMy>();
}

type ParamPatchMy = {userId: string};

async function patchMy({userId}: ParamPatchMy) {
const apiUrl = createUrl(myApis.patchMy, {param: {userId}});
return await kyInstance.patch(apiUrl).json<ResponseGetMy>();
}

type ParamWithdraw = {userId: string};

async function withdraw({userId}: ParamWithdraw) {
const apiUrl = createUrl(myApis.withdraw, {param: {userId}});
return await kyInstance.delete(apiUrl).json<ResponseGetMy>();
}

export {getMy, patchMy, withdraw};
export type {ParamGetMy, ParamPatchMy, ParamWithdraw, ResponseGetMy};
2 changes: 1 addition & 1 deletion src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const questionApis = {
};

export const myApis = {
my: 'user/:user-id',
getMy: 'user/:user-id',
patchMy: 'user/:user-id',
withdraw: 'user/:user-id',
};
Expand Down

0 comments on commit 1034917

Please sign in to comment.