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
8fb026f5
Commit
8fb026f5
authored
Jul 23, 2022
by
Kim, MinGyu
Browse files
Avatar -> fileInfo
parent
0be923a8
Changes
16
Show whitespace changes
Inline
Side-by-side
frontend/src/App.tsx
View file @
8fb026f5
...
...
@@ -2,15 +2,7 @@ import React from "react";
import
{
BrowserRouter
,
Route
,
Routes
}
from
"
react-router-dom
"
;
import
"
tailwindcss/tailwind.css
"
;
import
{
IntoPost
}
from
"
./post/intopost
"
;
import
{
Login
,
Profile
,
RequireAuth
,
Signup
,
Admin
,
ImgRewrite
,
Search
,
}
from
"
./auth
"
;
import
{
Login
,
Profile
,
RequireAuth
,
Signup
,
Admin
,
ImgRewrite
}
from
"
./auth
"
;
import
{
Header
,
Body
}
from
"
./home
"
;
import
{
Board
}
from
"
./board
"
;
import
Posting
from
"
./post/posting
"
;
...
...
@@ -37,7 +29,6 @@ export const App = () => {
<
Route
path
=
"board"
element
=
{
<
Board
/>
}
/>
<
Route
path
=
"post/:postId"
element
=
{
<
IntoPost
/>
}
/>
<
Route
path
=
"edit"
element
=
{
<
EditPost
/>
}
/>
{
/* </Route> */
}
<
Route
path
=
"profile"
element
=
{
...
...
@@ -48,7 +39,6 @@ export const App = () => {
/>
<
Route
path
=
"admin"
element
=
{
<
Admin
/>
}
/>
<
Route
path
=
"rewrite"
element
=
{
<
ImgRewrite
/>
}
/>
<
Route
path
=
"search"
element
=
{
<
Search
/>
}
/>
</
Route
>
</
Route
>
</
Routes
>
...
...
frontend/src/auth/RequireAuth.tsx
View file @
8fb026f5
...
...
@@ -7,9 +7,7 @@ export const RequireAuth: FC<{ children: JSX.Element }> = ({ children }) => {
const
location
=
useLocation
();
if
(
!
user
.
isLoggedIn
)
{
return
(
<
Navigate
to
=
{
"
/login
"
}
state
=
{
{
from
:
location
.
pathname
}
}
replace
/>
);
return
<
Navigate
to
=
{
"
/
"
}
state
=
{
{
from
:
location
.
pathname
}
}
replace
/>;
}
return
children
;
};
frontend/src/auth/admin.tsx
View file @
8fb026f5
import
React
,
{
FormEvent
,
useEffect
,
useState
,
MouseEvent
}
from
"
react
"
;
import
{
Link
}
from
"
react-router-dom
"
;
import
{
mainimgApi
}
from
"
../apis
"
;
import
{
p
icture
}
from
"
../apis/profile.api
"
;
import
{
p
rofileUpload
}
from
"
../apis/profile.api
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
import
{
MainimgType
}
from
"
../types
"
;
import
{
MySlide
}
from
"
./adminslide
"
;
...
...
frontend/src/auth/index.tsx
View file @
8fb026f5
...
...
@@ -4,4 +4,3 @@ export { default as Profile } from "./profile";
export
{
RequireAuth
}
from
"
./RequireAuth
"
;
export
{
default
as
Admin
}
from
"
./admin
"
;
export
{
default
as
ImgRewrite
}
from
"
./imgrewrite
"
;
export
{
default
as
Search
}
from
"
./search
"
;
frontend/src/auth/search.tsx
deleted
100644 → 0
View file @
0be923a8
import
React
from
"
react
"
;
import
{
useLocation
}
from
"
react-router-dom
"
;
export
default
function
Search
()
{
const
a
=
useLocation
().
state
;
return
(
<
div
>
<
div
></
div
>
</
div
>
);
}
frontend/src/types/index.tsx
View file @
8fb026f5
...
...
@@ -31,7 +31,7 @@ export interface SignupUser {
export
interface
Profile
{
_id
:
string
;
email
:
string
;
avatar
:
{
fileInfo
:
{
originalfilename
:
string
;
newfilename
:
string
;
picturepath
:
string
;
...
...
src/app.ts
View file @
8fb026f5
...
...
@@ -12,7 +12,6 @@ app.use(cookieParser());
app
.
use
(
"
/api
"
,
router
);
app
.
use
(
"
/images
"
,
express
.
static
(
path
.
join
(
__dirname
,
"
..
"
,
"
/uploads
"
)));
app
.
use
(
"
/images
"
,
express
.
static
(
path
.
join
(
__dirname
,
"
..
"
,
"
/adminpics
"
)));
app
.
use
((
err
:
any
,
req
:
Request
,
res
:
Response
,
next
:
NextFunction
)
=>
{
console
.
log
(
"
익스프레스 에러:
"
,
err
);
...
...
src/controllers/fileinfo.controller.ts
0 → 100644
View file @
8fb026f5
import
formidable
from
"
formidable
"
;
import
{
asyncWrap
}
from
"
../helpers/asyncWrap
"
;
import
{
TypedRequest
}
from
"
../types
"
;
export
const
uploadFile
=
asyncWrap
(
async
(
reqExp
,
res
,
next
)
=>
{
const
req
=
reqExp
as
TypedRequest
;
const
form
=
formidable
({
multiples
:
false
,
uploadDir
:
"
uploads
"
});
await
new
Promise
((
resolve
,
reject
)
=>
{
form
.
parse
(
req
,
(
err
,
fields
,
files
)
=>
{
if
(
err
)
{
reject
(
err
);
return
;
}
console
.
log
(
"
fields
"
,
fields
);
console
.
log
(
"
files
"
,
files
);
req
.
body
=
fields
;
req
.
files
=
files
;
resolve
(
files
);
});
});
next
();
return
;
});
export
const
uploadFiles
=
asyncWrap
(
async
(
reqExp
,
res
,
next
)
=>
{
const
req
=
reqExp
as
TypedRequest
;
const
form
=
formidable
({
multiples
:
true
,
uploadDir
:
"
uploads
"
});
await
new
Promise
((
resolve
,
reject
)
=>
{
form
.
parse
(
req
,
(
err
,
fields
,
files
)
=>
{
if
(
err
)
{
reject
(
err
);
return
;
}
console
.
log
(
"
fields
"
,
fields
);
console
.
log
(
"
files
"
,
files
);
req
.
body
=
fields
;
req
.
files
=
files
;
resolve
(
files
);
});
});
next
();
return
;
});
src/controllers/index.ts
View file @
8fb026f5
...
...
@@ -3,3 +3,4 @@ export * as postCtrl from "./post.controller";
export
*
as
roleCtrl
from
"
./role.controller
"
;
export
*
as
userCtrl
from
"
./user.controller
"
;
export
*
as
mainimgCtrl
from
"
./mainimg.controller
"
;
export
*
as
fileInfoCtrl
from
"
./fileinfo.controller
"
;
src/controllers/mainimg.controller.ts
View file @
8fb026f5
...
...
@@ -12,7 +12,7 @@ export const createMainimg = asyncWrap(async (reqExp, res) => {
const
{
userId
}
=
req
.
auth
;
const
form
=
formidable
({
uploadDir
:
"
adminpic
s
"
,
uploadDir
:
"
upload
s
"
,
keepExtensions
:
true
,
multiples
:
false
,
});
...
...
src/db/mainimg.db.ts
View file @
8fb026f5
import
{
ObjectId
}
from
"
mongoose
"
;
import
{
Avatar
,
IAvatar
,
Mainimg
,
MainimgType
}
from
"
../models
"
;
import
{
FileInfo
,
IFileInfo
,
Mainimg
,
MainimgType
}
from
"
../models
"
;
export
const
createMainimg
=
async
(
mainimg
:
MainimgType
,
pic
:
I
Avatar
)
=>
{
const
newPic
=
await
Avatar
.
create
({
export
const
createMainimg
=
async
(
mainimg
:
MainimgType
,
pic
:
I
FileInfo
)
=>
{
const
newPic
=
await
FileInfo
.
create
({
originalfilename
:
pic
.
originalfilename
,
newfilename
:
pic
.
newfilename
,
pictureauth
:
pic
.
picturepath
,
...
...
src/models/fileinfo.model.ts
View file @
8fb026f5
import
{
model
,
Schema
}
from
"
mongoose
"
;
export
interface
I
Avatar
{
export
interface
I
FileInfo
{
originalfilename
?:
string
;
newfilename
?:
string
;
picturepath
?:
string
;
nickname
?:
string
;
}
const
Avatar
schema
=
new
Schema
<
I
Avatar
>
({
const
schema
=
new
Schema
<
I
FileInfo
>
({
originalfilename
:
{
type
:
String
,
unique
:
true
},
newfilename
:
{
type
:
String
},
nickname
:
{
type
:
String
},
picturepath
:
{
type
:
String
},
});
export
default
model
<
I
Avatar
>
(
"
Avatar
"
,
Avatar
schema
);
export
default
model
<
I
FileInfo
>
(
"
FileInfo
"
,
schema
);
src/models/index.ts
View file @
8fb026f5
export
{
default
as
User
,
IUser
}
from
"
./user.model
"
;
export
{
default
as
Post
,
PostType
}
from
"
./post.model
"
;
export
{
default
as
Role
}
from
"
./role.model
"
;
export
{
default
as
Avatar
,
IAvatar
}
from
"
./fileinfo.model
"
;
export
{
default
as
FileInfo
,
IFileInfo
}
from
"
./fileinfo.model
"
;
export
{
default
as
Mainimg
,
MainimgType
}
from
"
./mainimg.model
"
;
src/models/mainimg.model.ts
View file @
8fb026f5
...
...
@@ -4,7 +4,7 @@ export interface MainimgType {
theme
:
string
;
city
:
string
;
title
:
string
;
pic
?:
Types
.
ObjectId
;
fileInfo
?:
Types
.
ObjectId
;
}
const
MainimgSchema
=
new
Schema
<
MainimgType
>
({
...
...
@@ -18,7 +18,7 @@ const MainimgSchema = new Schema<MainimgType>({
type
:
String
,
required
:
true
,
},
pic
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Avatar
"
},
fileInfo
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Fileinfo
"
},
});
export
default
model
<
MainimgType
>
(
"
Mainimg
"
,
MainimgSchema
);
src/models/user.model.ts
View file @
8fb026f5
...
...
@@ -5,7 +5,7 @@ export interface IUser {
name
?:
string
;
password
:
string
;
role
?:
Types
.
ObjectId
;
avatar
?:
Types
.
ObjectId
;
fileInfo
?:
Types
.
ObjectId
;
}
const
validateEmail
=
(
email
:
string
)
=>
{
...
...
@@ -22,7 +22,7 @@ const schema = new Schema<IUser>(
validate
:
[
validateEmail
,
"
이메일을 입력해주세요
"
],
},
name
:
{
type
:
String
},
avatar
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Avatar
"
},
fileInfo
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
FileInfo
"
},
password
:
{
type
:
String
,
required
:
true
,
select
:
false
},
role
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Role
"
},
},
...
...
src/routes/user.route.ts
View file @
8fb026f5
import
express
from
"
express
"
;
import
{
userCtrl
,
authCtrl
}
from
"
../controllers
"
;
import
{
userCtrl
,
authCtrl
,
fileInfoCtrl
}
from
"
../controllers
"
;
const
router
=
express
.
Router
();
router
.
route
(
"
/
"
)
.
get
(
authCtrl
.
requireLogin
,
userCtrl
.
getUsers
)
.
post
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
userCtrl
.
createUser
);
.
post
(
authCtrl
.
requireLogin
,
authCtrl
.
hasRole
(
"
admin
"
),
fileInfoCtrl
.
uploadFile
,
userCtrl
.
createUser
);
export
default
router
;
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