Skip to content

Commit

Permalink
✨ updatePost의 변수명 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
khj0426 committed Oct 1, 2023
1 parent 7941056 commit 5ffe6bf
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/app/api/posts/update/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,21 @@ import type Post from '@/types/post'
export async function PUT(request: Request) {
const channelId = Environment.channelId()
const { CHANNEL_ID } = POST_CONSTANT
const dislikeChannelId = Environment.dislikeChannelID()

const { token } = useServerCookie()

const updatePost = async (
formData: FormData,
channelId: string,
postId?: string,
mapping_ID: string,
): Promise<Post> => {
if (formData.has(CHANNEL_ID)) {
formData.delete(CHANNEL_ID)
}
formData.delete(CHANNEL_ID)
formData.append(CHANNEL_ID, channelId)
if (postId) {
formData.delete('postId')
formData.set('postId', postId)
if (mapping_ID) {
const getTitleField = JSON.parse(formData.get('title') as string)
getTitleField.mapping_ID = mapping_ID
formData.set('title', JSON.stringify(getTitleField))
}

const { data } = await apiServer.put('/posts/update', formData, {
headers: {
Authorization: 'Bearer ' + token,
Expand All @@ -41,11 +38,8 @@ export async function PUT(request: Request) {
const mapping_ID = JSON.parse(
formData.get('title')?.toString() || '',
).mapping_ID
const updatePostRes = await updatePost(formData, dislikeChannelId).then(
async () => {
return await updatePost(formData, channelId, mapping_ID)
},
)

const updatePostRes = await updatePost(formData, channelId, mapping_ID)
return NextResponse.json(updatePostRes)
} catch (error: any) {
return NextResponse.json(
Expand Down

0 comments on commit 5ffe6bf

Please sign in to comment.