Skip to content

Commit

Permalink
refactor: Update API functions to use destructured parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
timepresent95 committed Aug 20, 2024
1 parent f587e53 commit 1168662
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/api/my.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ type ResponseGetMy = {
familyCode: string;
} & UserInfo;

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

type ParamPatchMy = {userId: string};

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

type ParamWithdraw = {userId: string};

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

Expand Down
19 changes: 8 additions & 11 deletions src/api/quetion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type ResponseGetQuestion = {
isAnswered: boolean;
} & Question;

async function getQuestion({familyId}: ParamGetQuestion) {
const apiUrl = createUrl(questionApis.getQuestion, {param: {familyId}});
async function getQuestion(param: ParamGetQuestion) {
const apiUrl = createUrl(questionApis.getQuestion, {param});
return await kyInstance.get(apiUrl).json<ResponseGetQuestion>();
}

Expand All @@ -35,9 +35,9 @@ type ResponseGetAnswer = {
answer: Answer[];
};

async function getAnswer({questionHistoryId}: ParamGetAnswer) {
async function getAnswer(param: ParamGetAnswer) {
const apiUrl = createUrl(questionApis.getAnswer, {
param: {questionHistoryId},
param,
});
return await kyInstance.get(apiUrl).json<ResponseGetAnswer>();
}
Expand All @@ -51,11 +51,8 @@ type BodyPatchAnswer = {
answer: string;
};

async function patchAnswer(
{answerId}: ParamPatchAnswer,
body: BodyPatchAnswer,
) {
const apiUrl = createUrl(questionApis.patchAnser, {param: {answerId}});
async function patchAnswer(param: ParamPatchAnswer, body: BodyPatchAnswer) {
const apiUrl = createUrl(questionApis.patchAnser, {param});
return await kyInstance.patch(apiUrl, {json: body}).json();
}

Expand All @@ -67,8 +64,8 @@ type ResponseGetList = {
question: Question[];
};

async function getList({familyId}: ParamGetList) {
const apiUrl = createUrl(questionApis.getList, {param: {familyId}});
async function getList(param: ParamGetList) {
const apiUrl = createUrl(questionApis.getList, {param});
return await kyInstance.get(apiUrl).json<ResponseGetList>();
}

Expand Down

0 comments on commit 1168662

Please sign in to comment.