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
survey
Commits
5c9540ec
Commit
5c9540ec
authored
Jul 08, 2022
by
Yoon, Daeki
😅
Browse files
유저 만들 때 역할 항목 추가
parent
83e41a01
Changes
1
Show whitespace changes
Inline
Side-by-side
src/db/user.db.ts
View file @
5c9540ec
import
bcrypt
from
"
bcryptjs
"
;
import
bcrypt
from
"
bcryptjs
"
;
import
{
IUser
,
User
}
from
"
../models
"
;
import
{
IUser
,
Role
,
User
}
from
"
../models
"
;
export
const
createUser
=
async
(
user
:
IUser
)
=>
{
export
const
createUser
=
async
(
user
:
IUser
)
=>
{
// 비밀번호 암호화
// 비밀번호 암호화
const
hash
=
await
bcrypt
.
hash
(
user
.
password
,
10
);
const
hash
=
await
bcrypt
.
hash
(
user
.
password
,
10
);
const
newUser
=
await
User
.
create
({
email
:
user
.
email
,
password
:
hash
});
// 사용자 역할 추가: 기본값은 "user"
return
newUser
;
let
userRole
=
null
;
if
(
user
.
role
)
{
userRole
=
await
Role
.
findById
(
user
.
role
);
}
else
{
userRole
=
await
Role
.
findOne
({
name
:
"
user
"
});
}
const
newUser
=
new
User
({
email
:
user
.
email
,
password
:
hash
,
role
:
userRole
,
isNew
:
true
,
});
const
retUser
=
await
newUser
.
save
();
return
retUser
;
};
};
export
const
deleteUserById
=
async
(
userId
:
string
)
=>
{
export
const
deleteUserById
=
async
(
userId
:
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