-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5cf6fd
commit aaa92b7
Showing
2 changed files
with
100 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,98 @@ | ||
import {kyInstance} from './ky'; | ||
import {questionApis} from './routes'; | ||
|
||
import {AlertToken} from '@/types'; | ||
import {Answer, Question} from '@/types/question'; | ||
import {createUrl} from '@/utils/url'; | ||
|
||
type ParamGetQuestion = { | ||
familyId: string; | ||
}; | ||
|
||
type ResponseGetQuestion = { | ||
questionHistoryId: string; | ||
question: string; | ||
isAnswered: boolean; | ||
}; | ||
} & Question; | ||
|
||
async function getQuestion({familyId}: ParamGetQuestion) { | ||
return (await kyInstance | ||
.get(`question/${familyId}`) | ||
.json()) as ResponseGetQuestion; | ||
const apiUrl = createUrl(questionApis.getQuestion, {param: {familyId}}); | ||
return await kyInstance.get(apiUrl).json<ResponseGetQuestion>(); | ||
} | ||
|
||
type BodyPostAnswer = { | ||
questionHistoryId: number; | ||
emoji: string | null; | ||
answer: string; | ||
}; | ||
|
||
async function postAnswer(body: BodyPostAnswer) { | ||
return await kyInstance.post(questionApis.postAnswer, {json: body}).json(); | ||
} | ||
|
||
type ParamGetAnswer = { | ||
questionHistoryId: number; | ||
}; | ||
|
||
type ResponseGetAnswer = { | ||
answer: Answer[]; | ||
}; | ||
|
||
async function getAnswer({questionHistoryId}: ParamGetAnswer) { | ||
const apiUrl = createUrl(questionApis.getAnswer, { | ||
param: {questionHistoryId}, | ||
}); | ||
return await kyInstance.get(apiUrl).json<ResponseGetAnswer>(); | ||
} | ||
|
||
export {getQuestion}; | ||
export type {ParamGetQuestion, ResponseGetQuestion}; | ||
type ParamPatchAnswer = { | ||
answerId: string; | ||
}; | ||
|
||
type BodyPatchAnswer = { | ||
userId: string; | ||
answer: string; | ||
}; | ||
|
||
async function patchAnswer( | ||
{answerId}: ParamPatchAnswer, | ||
body: BodyPatchAnswer, | ||
) { | ||
const apiUrl = createUrl(questionApis.patchAnser, {param: {answerId}}); | ||
return await kyInstance.patch(apiUrl, {json: body}).json(); | ||
} | ||
|
||
type ParamGetList = { | ||
familyId: string; | ||
}; | ||
|
||
type ResponseGetList = { | ||
question: Question[]; | ||
}; | ||
|
||
async function getList({familyId}: ParamGetList) { | ||
const apiUrl = createUrl(questionApis.getList, {param: {familyId}}); | ||
return await kyInstance.get(apiUrl).json<ResponseGetList>(); | ||
} | ||
|
||
type BodyCheerUp = { | ||
userId: string; | ||
familyId: string; | ||
alertToken: AlertToken; | ||
}; | ||
|
||
async function cheerUp(body: BodyCheerUp) { | ||
return await kyInstance.post(questionApis.cheerUp, {json: body}).json(); | ||
} | ||
|
||
export {getQuestion, postAnswer, getAnswer, patchAnswer, getList, cheerUp}; | ||
export type { | ||
ParamGetQuestion, | ||
ResponseGetQuestion, | ||
BodyPostAnswer, | ||
ParamGetAnswer, | ||
ResponseGetAnswer, | ||
ParamPatchAnswer, | ||
BodyPatchAnswer, | ||
ParamGetList, | ||
ResponseGetList, | ||
BodyCheerUp, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {GoupRole} from './member'; | ||
|
||
export type Question = { | ||
questionHistoryId: number; | ||
question: string; | ||
}; | ||
|
||
export type Answer = { | ||
nickname: string; | ||
groupRole: GoupRole; | ||
emoji: string; | ||
content: string; | ||
createAt: Date; | ||
}; |