-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from woowacourse-teams/develop
v1.1.1
- Loading branch information
Showing
112 changed files
with
1,414 additions
and
505 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
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
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
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
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
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
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
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,37 @@ | ||
import { AxiosError } from 'axios'; | ||
|
||
import { arrayOfAll, checkType, hasOwnProperties, isNumber, isObject, isString } from '@utils'; | ||
|
||
import { type ApiLogin, type ApiRefresh } from '@api/auth'; | ||
|
||
type LoginKeys = keyof ApiLogin['post']['responseData']; | ||
|
||
const arrayOfAllLoginKeys = arrayOfAll<LoginKeys>(); | ||
|
||
export const checkLogin = (data: unknown): ApiLogin['post']['responseData'] => { | ||
if (!isObject(data)) throw new AxiosError(`Login does not have correct type: object`); | ||
|
||
const keys = arrayOfAllLoginKeys(['accessToken', 'expiredTime']); | ||
if (!hasOwnProperties(data, keys)) throw new AxiosError('Login does not have some properties'); | ||
|
||
return { | ||
accessToken: checkType(data.accessToken, isString), | ||
expiredTime: checkType(data.expiredTime, isNumber), | ||
}; | ||
}; | ||
|
||
type RefreshKeys = keyof ApiRefresh['get']['responseData']; | ||
|
||
const arrayOfAllRefreshKeys = arrayOfAll<RefreshKeys>(); | ||
|
||
export const checkRefresh = (data: unknown): ApiRefresh['get']['responseData'] => { | ||
if (!isObject(data)) throw new AxiosError(`Refresh does not have correct type: object`); | ||
|
||
const keys = arrayOfAllRefreshKeys(['accessToken', 'expiredTime']); | ||
if (!hasOwnProperties(data, keys)) throw new AxiosError('Refresh does not have some properties'); | ||
|
||
return { | ||
accessToken: checkType(data.accessToken, isString), | ||
expiredTime: checkType(data.expiredTime, isNumber), | ||
}; | ||
}; |
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
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
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,66 @@ | ||
import { AxiosError } from 'axios'; | ||
|
||
import { arrayOfAll, checkType, hasOwnProperties, isArray, isDateYMD, isNumber, isObject, isString } from '@utils'; | ||
|
||
import type { CommunityArticle } from '@custom-types'; | ||
|
||
import { type ApiCommunityArticle, type ApiCommunityArticles } from '@api/community'; | ||
import { checkMember } from '@api/member/typeChecker'; | ||
|
||
type CommunityArticleKeys = keyof ApiCommunityArticle['get']['responseData']; | ||
|
||
const arrayOfAllCommunityArticleKeys = arrayOfAll<CommunityArticleKeys>(); | ||
|
||
export const checkCommunityArticle = (data: unknown): ApiCommunityArticle['get']['responseData'] => { | ||
if (!isObject(data)) throw new AxiosError(`CommunityArticle does not have correct type: object`); | ||
|
||
const keys = arrayOfAllCommunityArticleKeys(['id', 'author', 'title', 'content', 'createdDate', 'lastModifiedDate']); | ||
if (!hasOwnProperties(data, keys)) throw new AxiosError('CommunityArticle does not have some properties'); | ||
|
||
return { | ||
id: checkType(data.id, isNumber), | ||
author: checkMember(data.author), | ||
title: checkType(data.title, isString), | ||
content: checkType(data.content, isString), | ||
createdDate: checkType(data.createdDate, isDateYMD), | ||
lastModifiedDate: checkType(data.lastModifiedDate, isDateYMD), | ||
}; | ||
}; | ||
|
||
type Article = Omit<CommunityArticle, 'content'>; | ||
type ArticleKeys = keyof Article; | ||
|
||
const arrayOfAllArticleKeys = arrayOfAll<ArticleKeys>(); | ||
|
||
const checkArticle = (data: unknown): Article => { | ||
if (!isObject(data)) throw new AxiosError(`CommunityArticles-Article does not have correct type: object`); | ||
|
||
const keys = arrayOfAllArticleKeys(['id', 'author', 'title', 'createdDate', 'lastModifiedDate']); | ||
if (!hasOwnProperties(data, keys)) throw new AxiosError('CommunityArticles-Article does not have some properties'); | ||
|
||
return { | ||
id: checkType(data.id, isNumber), | ||
author: checkMember(data.author), | ||
title: checkType(data.title, isString), | ||
createdDate: checkType(data.createdDate, isDateYMD), | ||
lastModifiedDate: checkType(data.lastModifiedDate, isDateYMD), | ||
}; | ||
}; | ||
|
||
type CommunityArticlesKeys = keyof ApiCommunityArticles['get']['responseData']; | ||
|
||
const arrayOfAllCommunityArticlesKeys = arrayOfAll<CommunityArticlesKeys>(); | ||
|
||
export const checkCommunityArticles = (data: unknown): ApiCommunityArticles['get']['responseData'] => { | ||
if (!isObject(data)) throw new AxiosError(`CommunityArticles does not have correct type: object`); | ||
|
||
const keys = arrayOfAllCommunityArticlesKeys(['articles', 'currentPage', 'lastPage', 'totalCount']); | ||
if (!hasOwnProperties(data, keys)) throw new AxiosError('CommunityArticles does not have some properties'); | ||
|
||
return { | ||
articles: checkType(data.articles, isArray).map(article => checkArticle(article)), | ||
currentPage: checkType(data.currentPage, isNumber) + 1, | ||
lastPage: checkType(data.lastPage, isNumber), | ||
totalCount: checkType(data.totalCount, isNumber), | ||
}; | ||
}; |
Oops, something went wrong.