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
00ee89c5
Commit
00ee89c5
authored
Jul 07, 2022
by
Yoon, Daeki
😅
Browse files
User 모델에 스키마 toJSON 옵션 설정으로 비밀번호 반환하지 않게 적용
parent
81cba2c9
Changes
1
Show whitespace changes
Inline
Side-by-side
src/models/user.model.ts
View file @
00ee89c5
import
{
model
,
Schema
,
Types
}
from
"
mongoose
"
;
import
{
model
,
Schema
,
Types
,
version
}
from
"
mongoose
"
;
export
interface
IUser
{
export
interface
IUser
{
email
:
string
;
email
:
string
;
...
@@ -12,9 +12,10 @@ const validateEmail = (email: string) => {
...
@@ -12,9 +12,10 @@ const validateEmail = (email: string) => {
return
re
.
test
(
email
);
return
re
.
test
(
email
);
};
};
const
schema
=
new
Schema
<
IUser
>
({
const
schema
=
new
Schema
<
IUser
>
(
{
email
:
{
email
:
{
type
:
String
,
//mongoose type
인 String
으로 일반적인 string
과는 겉으로는 대문자 차이
type
:
String
,
//mongoose type인 String으로 일반적인 string과는 겉으로는 대문자 차이
rquired
:
true
,
rquired
:
true
,
unique
:
true
,
unique
:
true
,
validate
:
[
validateEmail
,
"
이메일을 입력해주세요
"
],
validate
:
[
validateEmail
,
"
이메일을 입력해주세요
"
],
...
@@ -22,6 +23,15 @@ const schema = new Schema<IUser>({
...
@@ -22,6 +23,15 @@ const schema = new Schema<IUser>({
name
:
{
type
:
String
},
name
:
{
type
:
String
},
password
:
{
type
:
String
,
required
:
true
,
select
:
false
},
password
:
{
type
:
String
,
required
:
true
,
select
:
false
},
role
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Role
"
},
role
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Role
"
},
});
},
{
toJSON
:
{
versionKey
:
false
,
transform
(
doc
,
ret
,
options
)
{
delete
ret
.
password
;
},
},
}
);
export
default
model
<
IUser
>
(
"
User
"
,
schema
);
export
default
model
<
IUser
>
(
"
User
"
,
schema
);
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