Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
students
travel
Commits
5135892d
Commit
5135892d
authored
Jul 27, 2022
by
Lee Soobeom
Browse files
debugging
parent
35f8698d
Changes
9
Show whitespace changes
Inline
Side-by-side
frontend/src/board/board.tsx
View file @
5135892d
...
...
@@ -17,7 +17,7 @@ export default function BoardPage() {
const
location
=
useLocation
()
as
Newpost
;
const
newPost
=
location
.
state
;
//
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 @
5135892d
import
React
,
{
FormEvent
,
useState
}
from
"
react
"
;
import
{
useNavigate
,
useLocation
}
from
"
react-router-dom
"
;
import
React
,
{
FormEvent
,
MouseEventHandler
,
useState
}
from
"
react
"
;
import
{
useNavigate
,
useLocation
,
Link
}
from
"
react-router-dom
"
;
import
isLength
from
"
validator/lib/isLength
"
;
import
equals
from
"
validator/lib/equals
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
...
...
@@ -65,8 +65,8 @@ export function EditPost() {
if
(
postingFormMatch
(
user
)
===
true
)
{
setLoading
(
true
);
const
res
=
updateImg2Db
(
file
);
navigate
(
"
/board
"
,
{
replace
:
true
});
const
updateRes
=
await
updateImg2Db
(
file
);
navigate
(
"
/board
"
,
{
replace
:
true
,
state
:
updateRes
});
setSuccess
(
true
);
setError
(
""
);
...
...
@@ -164,6 +164,12 @@ export function EditPost() {
setUser
(
newUser
);
};
const
GoBack
=
()
=>
{
if
(
confirm
(
"
취소하시겠습니까?
"
)
==
true
)
{
navigate
(
-
1
);
}
};
const
oldFileShow
=
(
post
:
PostType
)
=>
{
const
res
=
post
.
file
?.
map
((
file
,
i
)
=>
(
<
img
...
...
@@ -185,6 +191,7 @@ export function EditPost() {
};
return
(
<
div
>
<
form
onSubmit
=
{
reWriteSubmit
}
className
=
"flex flex-col w-full"
>
<
div
className
=
"flex flex-row h-10 gap-x-1 justify-end"
>
<
div
className
=
"place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300"
>
...
...
@@ -270,5 +277,14 @@ export function EditPost() {
/>
</
div
>
</
form
>
<
div
className
=
"flex md:mb-20 justify-center"
>
<
button
onClick
=
{
GoBack
}
className
=
" mt-5 h-12 w-40 text-lg border-2 border-sky-500 place-self-center"
>
취소
</
button
>
</
div
>
</
div
>
);
}
frontend/src/post/intopost.tsx
View file @
5135892d
...
...
@@ -13,6 +13,8 @@ export function IntoPost() {
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
);
...
...
@@ -56,7 +58,7 @@ export function IntoPost() {
<
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
.
slice
(
0
,
8
)
}
작성자:
{
post
.
user
.
name
}
</
div
>
<
div
className
=
"flex divide-x divide-slate-300 "
>
...
...
frontend/src/post/posting.tsx
View file @
5135892d
import
React
,
{
FormEvent
,
useEffect
,
useState
}
from
"
react
"
;
import
{
useNavigate
}
from
"
react-router-dom
"
;
import
{
useNavigate
,
Link
}
from
"
react-router-dom
"
;
import
isLength
from
"
validator/lib/isLength
"
;
import
equals
from
"
validator/lib/equals
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
...
...
@@ -21,11 +21,15 @@ export default function Posting() {
theme
:
""
,
city
:
""
,
date
:
""
,
user
:
""
,
user
:
{
_id
:
""
,
name
:
""
,
},
counts
:
0
,
_id
:
""
,
file
:
[
{
_id
:
""
,
originalfilename
:
""
,
newfilename
:
""
,
picturepath
:
""
,
...
...
@@ -69,12 +73,10 @@ export default function Posting() {
try
{
if
(
confirm
(
"
게시물을 작성하시겠습니까?
"
)
==
true
)
{
setError
(
""
);
// console.log("user data", user);
if
(
postingFormMatch
(
user
,
file
))
{
setLoading
(
true
);
if
(
file
)
{
const
postRes
=
await
sendImg2Db
(
file
);
// console.log("Newpost Info", postRes);
navigate
(
"
/board
"
,
{
replace
:
true
,
state
:
postRes
});
}
setSuccess
(
true
);
...
...
@@ -174,7 +176,14 @@ export default function Posting() {
}
};
const
GoBack
=
()
=>
{
if
(
confirm
(
"
취소하시겠습니까?
"
)
==
true
)
{
navigate
(
-
1
);
}
};
return
(
<
div
>
<
form
onSubmit
=
{
handlePostSubmit
}
className
=
"flex flex-col w-full"
>
<
div
className
=
"flex flex-row gap-x-1 justify-end h-10 "
>
<
div
className
=
"place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300"
>
...
...
@@ -260,5 +269,14 @@ export default function Posting() {
/>
</
div
>
</
form
>
<
div
className
=
"flex md:mb-20 justify-center"
>
<
button
onClick
=
{
GoBack
}
className
=
" mt-5 h-12 w-40 text-lg border-2 border-sky-500 place-self-center"
>
취소
</
button
>
</
div
>
</
div
>
);
}
frontend/src/types/index.tsx
View file @
5135892d
...
...
@@ -20,9 +20,13 @@ export interface PostType {
date
:
string
;
counts
:
number
;
_id
:
string
;
user
:
string
;
user
:
{
_id
:
string
;
name
:
string
;
};
file
:
[
{
_id
:
string
;
originalfilename
:
string
;
newfilename
:
string
;
picturepath
:
string
;
...
...
src/controllers/auth.controller.ts
View file @
5135892d
...
...
@@ -22,6 +22,7 @@ export const authenticate = asyncWrap(
if
(
req
.
auth
)
{
const
{
userId
}
=
req
.
auth
;
const
user
=
req
.
user
;
// const adminId =
if
(
user
&&
user
.
id
===
userId
)
{
return
next
();
}
else
{
...
...
src/controllers/post.controller.ts
View file @
5135892d
...
...
@@ -18,7 +18,7 @@ export const userByPostId = (
next
();
};
export
const
s
ubTract
=
(
oldSet
:
Set
<
string
>
,
newSet
:
Set
<
string
>
)
=>
{
export
const
S
ubTract
=
(
oldSet
:
Set
<
string
>
,
newSet
:
Set
<
string
>
)
=>
{
const
keep
=
new
Array
<
string
>
();
//유지
const
drop
=
new
Array
<
string
>
();
//삭제
const
add
=
new
Array
<
string
>
();
//추가
...
...
@@ -234,7 +234,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console
.
log
(
"
NewSet
"
,
newSet
);
//유지, 삭제, 추가 구분하기
const
trdPart
=
s
ubTract
(
oldSet
,
newSet
);
const
trdPart
=
S
ubTract
(
oldSet
,
newSet
);
console
.
log
(
"
keep
"
,
trdPart
.
keep
);
console
.
log
(
"
drop
"
,
trdPart
.
drop
);
...
...
@@ -294,7 +294,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console
.
log
(
"
NewSet
"
,
newSet
);
//유지, 삭제, 추가 구분하기
const
trdPart
=
s
ubTract
(
oldSet
,
newSet
);
const
trdPart
=
S
ubTract
(
oldSet
,
newSet
);
//삭제
for
(
var
i
=
0
;
i
<
trdPart
.
drop
.
length
;
i
++
)
{
...
...
src/db/post.db.ts
View file @
5135892d
...
...
@@ -34,8 +34,11 @@ export const createFilesRow = async (
//Read
export
const
getPosts
=
async
()
=>
{
const
posts
=
await
Post
.
find
().
populate
(
"
file
"
).
sort
({
date
:
-
1
});
console
.
log
(
posts
);
const
posts
=
await
Post
.
find
()
.
populate
(
"
file
"
)
.
populate
(
"
user
"
)
.
sort
({
date
:
-
1
});
console
.
log
(
"
file nickname
"
,
posts
);
return
posts
;
};
...
...
src/models/fileinfo.model.ts
View file @
5135892d
...
...
@@ -4,13 +4,11 @@ export interface IFileInfo {
originalfilename
:
string
;
newfilename
:
string
;
picturepath
:
string
;
nickname
?:
string
;
}
const
schema
=
new
Schema
<
IFileInfo
>
({
originalfilename
:
{
type
:
String
,
unique
:
true
},
newfilename
:
{
type
:
String
},
nickname
:
{
type
:
String
},
picturepath
:
{
type
:
String
},
});
...
...
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