Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
travel
Commits
0b091720
Commit
0b091720
authored
Jul 27, 2022
by
Lee Soobeom
Browse files
update debugging
parent
32764f1e
Changes
7
Show whitespace changes
Inline
Side-by-side
frontend/src/board/board.tsx
View file @
0b091720
...
...
@@ -20,7 +20,7 @@ export default function BoardPage() {
const
navigate
=
useNavigate
();
const
{
user
}
=
useAuth
();
console
.
log
(
"
get newPost Info
"
,
newPost
);
//
console.log("get newPost Info", newPost);
const
setNewPosts
=
(
newpost
:
PostType
)
=>
{
const
postArr
=
posts
?.
splice
(
-
1
,
0
,
newPost
);
...
...
frontend/src/post/editpost.tsx
View file @
0b091720
...
...
@@ -39,7 +39,7 @@ export function EditPost() {
const
imgArr
=
new
Array
();
//
console.log("post.file", post.file);
console
.
log
(
"
post.file
"
,
post
.
file
);
const
updateImg2Db
=
async
(
filelist
:
FileList
|
undefined
)
=>
{
const
formdata
=
new
FormData
();
...
...
@@ -49,11 +49,15 @@ export function EditPost() {
formdata
.
append
(
"
city
"
,
user
.
city
);
if
(
filelist
===
undefined
)
{
const
res
=
await
postApi
.
updateImgAndPost
(
user
.
_id
,
formdata
);
return
res
;
}
else
{
for
(
var
i
=
0
;
i
<
filelist
.
length
;
i
++
)
{
formdata
.
append
(
"
picture
"
,
filelist
?.[
i
]);
}
console
.
log
(
"
one file update before
"
);
const
res
=
await
postApi
.
updateImgAndPost
(
user
.
_id
,
formdata
);
console
.
log
(
"
one file update
"
,
res
);
return
res
;
}
};
...
...
@@ -66,7 +70,11 @@ export function EditPost() {
setLoading
(
true
);
const
updateRes
=
await
updateImg2Db
(
file
);
navigate
(
"
/board
"
,
{
replace
:
true
,
state
:
updateRes
});
// console.log("find newfilename", updateRes);
navigate
(
{
pathname
:
`/post/
${
post
.
_id
}
`
},
{
replace
:
true
,
state
:
updateRes
}
);
setSuccess
(
true
);
setError
(
""
);
...
...
frontend/src/post/intopost.tsx
View file @
0b091720
...
...
@@ -9,23 +9,28 @@ export interface PostState {
}
export
function
IntoPost
()
{
const
[
posts
,
setPosts
]
=
useState
<
PostType
>
();
const
location
=
useLocation
()
as
PostState
;
const
post
=
location
.
state
;
const
navigate
=
useNavigate
();
console
.
log
(
"
user info
"
,
post
.
user
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
addSuccess
,
setAddSuccess
]
=
useState
(
false
);
const
[
delSuccess
,
setDelSuccess
]
=
useState
(
false
);
// console.log("post.file", post.file);
useEffect
(()
=>
{
setPosts
(
post
);
},
[]);
const
handleDeleteClick
=
async
(
event
:
MouseEvent
<
HTMLButtonElement
>
)
=>
{
try
{
if
(
confirm
(
"
삭제하시겠습니까?
"
)
==
true
)
{
const
postId
=
event
.
currentTarget
.
id
;
const
res
=
await
postApi
.
deletePost
(
postId
);
navigate
(
"
/board
"
,
{
replace
:
true
}
);
navigate
(
"
/board
"
);
console
.
log
(
"
delete post
"
,
res
);
}
else
{
return
false
;
...
...
@@ -40,41 +45,41 @@ export function IntoPost() {
<
div
className
=
"flex flex-col"
>
<
div
className
=
"flex h-8 gap-x-1 place-content-end place-items-center"
>
<
button
id
=
{
post
.
_id
}
id
=
{
post
s
?
.
_id
}
onClick
=
{
handleDeleteClick
}
className
=
" whitespace-nowrap flex border-2 border-sky-100 place-self-center h-6 w-8 text-xs text-center transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-red-300 duration-300"
>
삭제
</
button
>
<
Link
to
=
"/edit"
state
=
{
post
}
>
<
Link
to
=
"/edit"
state
=
{
post
s
}
>
<
button
className
=
"whitespace-nowrap flex border-2 border-sky-100 place-self-center h-6 w-8 text-xs transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-sky-300 duration-300"
>
수정
</
button
>
</
Link
>
</
div
>
<
div
className
=
"flex h-10 border-t-2 border-sky-500 items-center font-semibold"
>
{
post
.
title
}
{
post
s
?
.
title
}
</
div
>
<
div
className
=
"flex h-10 items-center border-t-2 border-sky-200 md:flex-row justify-between bg-slate-50 text-sm"
>
<
div
className
=
"flex whitespace-nowrap pr-5 "
>
작성자:
{
post
.
user
.
name
}
작성자:
{
post
s
?
.
user
.
name
}
</
div
>
<
div
className
=
"flex divide-x divide-slate-300 "
>
<
div
className
=
"flex basis-1/2 whitespace-nowrap px-2"
>
작성일 :
{
post
.
date
.
slice
(
0
,
10
)
}
작성일 :
{
post
s
?
.
date
.
slice
(
0
,
10
)
}
</
div
>
<
div
className
=
"flex whitespace-nowrap px-2"
>
{
post
.
city
}
</
div
>
<
div
className
=
"flex whitespace-nowrap px-2"
>
{
post
.
theme
}
</
div
>
<
div
className
=
"flex whitespace-nowrap px-2"
>
{
post
s
?
.
city
}
</
div
>
<
div
className
=
"flex whitespace-nowrap px-2"
>
{
post
s
?
.
theme
}
</
div
>
<
div
className
=
"flex whitespace-nowrap px-2"
>
조회수 :
{
post
.
counts
}
조회수 :
{
post
s
?
.
counts
}
</
div
>
</
div
>
</
div
>
<
div
className
=
"flex border-t-2 border-sky-200 h-44 p-2 overflow-auto mb-5 "
>
{
post
.
file
?.
map
((
file
,
i
)
=>
(
{
post
s
?
.
file
?.
map
((
file
,
i
)
=>
(
<
img
key
=
{
i
}
src
=
{
"
http://localhost:3000/images/
"
+
file
.
newfilename
}
...
...
@@ -83,7 +88,7 @@ export function IntoPost() {
/>
))
}
</
div
>
<
div
className
=
"border-b-2 border-sky-500 h-44 mb-10"
>
{
post
.
text
}
</
div
>
<
div
className
=
"border-b-2 border-sky-500 h-44 mb-10"
>
{
post
s
?
.
text
}
</
div
>
</
div
>
);
}
frontend/src/post/posting.tsx
View file @
0b091720
...
...
@@ -24,6 +24,7 @@ export default function Posting() {
user
:
{
_id
:
""
,
name
:
""
,
avatar
:
""
,
},
counts
:
0
,
_id
:
""
,
...
...
frontend/src/types/index.tsx
View file @
0b091720
...
...
@@ -23,6 +23,7 @@ export interface PostType {
user
:
{
_id
:
string
;
name
:
string
;
avatar
:
string
;
};
file
:
[
{
...
...
src/controllers/post.controller.ts
View file @
0b091720
...
...
@@ -197,7 +197,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console
.
log
(
"
check files
"
,
files
);
if
(
files
.
picture
===
undefined
||
files
.
picture
===
null
)
{
const
postRes
2
=
await
postDb
.
updatePostRow
(
const
postRes
1
=
await
postDb
.
updatePostRow
(
{
title
,
text
,
...
...
@@ -207,7 +207,8 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
},
postId
);
console
.
log
(
"
no files update
"
,
postRes2
);
console
.
log
(
"
no files update
"
,
postRes1
);
return
res
.
json
(
postRes1
);
}
else
{
if
(
Array
.
isArray
(
files
.
picture
))
{
const
oldFilesId
=
await
postDb
.
getFilesByPostId
(
postId
);
...
...
@@ -273,18 +274,31 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
}
}
}
console
.
log
(
"
all fileId
"
,
fileIdArr
);
//post정보 + file정보 update
const
postRes2
=
await
postDb
.
updatePostRow
(
{
title
,
text
,
theme
,
city
,
date
:
Date
.
now
(),
file
:
fileIdArr
,
},
postId
);
console
.
log
(
"
plural files update
"
,
postRes2
);
return
res
.
json
(
postRes2
);
}
else
{
const
oldFilesId
=
await
postDb
.
getFilesByPostId
(
postId
);
if
(
!
(
oldFilesId
===
undefined
))
{
for
(
var
i
=
0
;
i
<
oldFilesId
?.
length
;
i
++
)
{
const
name
=
await
postDb
.
getOriginalFileName
(
oldFilesId
[
i
]
);
const
name
=
await
postDb
.
getOriginalFileName
(
oldFilesId
[
0
]);
if
(
!
(
name
===
undefined
))
{
oldSet
.
add
(
name
);
}
}
}
console
.
log
(
"
OldSet
"
,
oldSet
);
const
newFileName
=
files
.
picture
.
originalFilename
;
...
...
@@ -296,6 +310,8 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
//유지, 삭제, 추가 구분하기
const
trdPart
=
SubTract
(
oldSet
,
newSet
);
console
.
log
(
"
add part
"
,
trdPart
.
add
);
//삭제
for
(
var
i
=
0
;
i
<
trdPart
.
drop
.
length
;
i
++
)
{
const
dropRes
=
await
postDb
.
deleteFileByName
(
...
...
@@ -308,9 +324,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
const
originalfilename
=
files
.
picture
.
originalFilename
;
const
newfilename
=
files
.
picture
.
newFilename
;
const
filepath
=
files
.
picture
.
filepath
;
for
(
var
j
=
0
;
j
<
trdPart
.
add
.
length
;
j
++
)
{
const
check
=
trdPart
.
add
[
j
];
if
(
originalfilename
===
check
)
{
if
(
originalfilename
===
trdPart
.
add
[
0
])
{
const
addRes
=
await
postDb
.
createFilesRow
(
originalfilename
,
newfilename
,
...
...
@@ -319,13 +333,11 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
fileIdArr
.
push
(
addRes
.
_id
);
}
}
}
}
console
.
log
(
"
all fileId
"
,
fileIdArr
);
//post정보 + file정보 update
const
postRes
1
=
await
postDb
.
updatePostRow
(
const
postRes
3
=
await
postDb
.
updatePostRow
(
{
title
,
text
,
...
...
@@ -336,6 +348,10 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
},
postId
);
console
.
log
(
"
singular file update
"
,
postRes3
);
return
res
.
json
(
postRes3
);
}
}
}
}
}
...
...
src/db/post.db.ts
View file @
0b091720
...
...
@@ -38,7 +38,6 @@ export const getPosts = async () => {
.
populate
(
"
file
"
)
.
populate
(
"
user
"
)
.
sort
({
date
:
-
1
});
console
.
log
(
"
file nickname
"
,
posts
);
return
posts
;
};
...
...
@@ -64,7 +63,7 @@ export const updatePostRow = async (post: PostType, postId: string) => {
file
:
post
.
file
,
},
{
new
:
true
}
);
).
populate
(
"
file
"
);
return
newPost
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment