-
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
Showing
11 changed files
with
146 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { http } from 'msw'; | ||
import { commonUrl } from '@/mocks'; | ||
import { contentsDatabase } from '@/mocks/fakeDatabase/resources/contents'; | ||
import { IContentsRegisterRequest } from '@/types/contents'; | ||
import getUserInfo from '@/mocks/utils/getUserInfo'; | ||
import CustomResponse from '@/mocks/utils/customResponse'; | ||
|
||
const contentsUrl = (path?: string) => `${commonUrl(`/contents${path ?? ''}`)}`; | ||
|
||
const contentsPostHandler = [ | ||
http.post(`${contentsUrl()}`, async ({ request }) => { | ||
try { | ||
const data = (await request.json()) as IContentsRegisterRequest; | ||
const { email } = getUserInfo(request); | ||
contentsDatabase.Create.write(data, email); | ||
} catch (error: any) { | ||
return CustomResponse({ | ||
code: 500, | ||
message: error, | ||
value: undefined, | ||
}); | ||
} | ||
return CustomResponse({ | ||
code: 200, | ||
message: '컨텐츠 등록 성공!', | ||
value: undefined, | ||
}); | ||
}), | ||
]; | ||
|
||
export default contentsPostHandler; |
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,5 +1,6 @@ | ||
import contentsGetHandler from '@/mocks/contents/contentsGetHandler'; | ||
import contentsPostHandler from '@/mocks/contents/contentsPostHandler'; | ||
|
||
const contentsHandler = [...contentsGetHandler]; | ||
const contentsHandler = [...contentsGetHandler, ...contentsPostHandler]; | ||
|
||
export default contentsHandler; |
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,17 @@ | ||
import { DefaultBodyType, StrictRequest } from 'msw'; | ||
import { crypto } from '@/utils/crypto'; | ||
|
||
export default function getUserInfo(request: StrictRequest<DefaultBodyType>) { | ||
const accessToken = request.headers.get('Authorization'); | ||
if (!accessToken) | ||
return { | ||
email: 'error', | ||
userId: 'error', | ||
}; | ||
const decryptionToken = crypto.decryptionDES(accessToken) ?? ''; | ||
const splitData = decryptionToken.replaceAll('"', '').split('/'); | ||
return { | ||
email: splitData[0], | ||
userId: splitData[1], | ||
}; | ||
} |
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