Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-029
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2023-029
2023-029
Commits
302c6bba
Commit
302c6bba
authored
Aug 26, 2023
by
janithgamage1.ed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: update
desc : user API config
parent
69453655
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
49 deletions
+6
-49
Project/Backend/Server_Node/controllers/user.controller.js
Project/Backend/Server_Node/controllers/user.controller.js
+5
-48
Project/Backend/Server_Node/routes/user.routes.js
Project/Backend/Server_Node/routes/user.routes.js
+1
-1
No files found.
Project/Backend/Server_Node/controllers/user.controller.js
View file @
302c6bba
import
bcrypt
from
'
bcryptjs
'
;
import
jwt
from
'
jsonwebtoken
'
;
import
mongoose
from
'
mongoose
'
;
import
nodemailer
from
"
nodemailer
"
;
import
User
from
'
../models/user.model.js
'
;
export
const
signIn
=
async
(
req
,
res
)
=>
{
...
...
@@ -128,53 +127,11 @@ export const updateUser = async (req, res) => {
return
res
.
status
(
404
).
json
({
code
:
"
02
"
,
message
:
`No User for this id:
${
id
}
`
});
}
if
(
data
.
type
==
"
buyer
"
||
data
.
type
==
"
admin
"
)
{
const
updateUser
=
{
...
data
,
_id
:
id
}
await
User
.
findByIdAndUpdate
(
id
,
updateUser
,
{
new
:
true
})
res
.
status
(
200
);
res
.
json
({
code
:
"
01
"
,
result
:
updateUser
})
}
else
if
(
data
.
type
==
"
trader
"
)
{
var
password
=
Math
.
random
().
toString
(
36
).
slice
(
-
8
);
const
hashPassword
=
await
bcrypt
.
hash
(
password
,
12
)
const
updateUser
=
{
...
data
,
password
:
hashPassword
,
_id
:
id
}
await
User
.
findByIdAndUpdate
(
id
,
updateUser
,
{
new
:
true
})
//call email service
let
transporter
=
nodemailer
.
createTransport
({
service
:
'
gmail
'
,
auth
:
{
type
:
'
OAuth2
'
,
user
:
process
.
env
.
MAIL_USERNAME
,
pass
:
process
.
env
.
MAIL_PASSWORD
,
clientId
:
process
.
env
.
OAUTH_CLIENTID
,
clientSecret
:
process
.
env
.
OAUTH_CLIENT_SECRET
,
refreshToken
:
process
.
env
.
OAUTH_REFRESH_TOKEN
}
});
let
mailOptions
=
{
from
:
"
janithgamage1.ed@gmail.com
"
,
to
:
updateUser
.
email
,
subject
:
'
Shop House Project
'
,
text
:
`You are Successfully Approved, you're username:
${
updateUser
.
email
}
, you're password :
${
password
}
`
};
transporter
.
sendMail
(
mailOptions
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
log
(
"
Error
"
+
err
);
}
else
{
console
.
log
(
"
Email sent successfully
"
);
}
});
res
.
status
(
200
);
res
.
json
({
code
:
"
01
"
,
result
:
updateUser
})
}
const
updateUser
=
{
...
data
,
_id
:
id
}
await
User
.
findByIdAndUpdate
(
id
,
updateUser
,
{
new
:
true
})
res
.
status
(
200
);
res
.
json
({
code
:
"
01
"
,
result
:
updateUser
})
}
catch
(
error
)
{
...
...
Project/Backend/Server_Node/routes/user.routes.js
View file @
302c6bba
...
...
@@ -7,7 +7,7 @@ router.post('/sign-in', signIn)
router
.
post
(
'
/sign-up
'
,
signUp
)
router
.
get
(
'
/all
'
,
getUsers
);
router
.
get
(
'
/:id
'
,
getUser
);
router
.
get
(
'
/
test
/:userType
'
,
getUserAccordingToType
);
router
.
get
(
'
/
all/type
/:userType
'
,
getUserAccordingToType
);
router
.
put
(
'
/:id
'
,
updateUser
);
router
.
delete
(
'
/:id
'
,
deleteUser
);
...
...
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