Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I_Helmet
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
21_22-J 62
I_Helmet
Commits
372c0ddf
Commit
372c0ddf
authored
Apr 27, 2022
by
Balasuriya D.A.M.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create User Registration API with routes/controllers
parent
5ce68d98
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
3 deletions
+44
-3
IT18021080/Telemedicine-Chat-App/backend/controllers/userControllers.js
...emedicine-Chat-App/backend/controllers/userControllers.js
+40
-0
IT18021080/Telemedicine-Chat-App/backend/models/userModel.js
IT18021080/Telemedicine-Chat-App/backend/models/userModel.js
+2
-2
IT18021080/Telemedicine-Chat-App/backend/routes/userRoutes.js
...021080/Telemedicine-Chat-App/backend/routes/userRoutes.js
+2
-1
No files found.
IT18021080/Telemedicine-Chat-App/backend/controllers/userControllers.js
View file @
372c0ddf
const
asyncHandler
=
require
(
"
express-async-handler
"
);
const
User
=
require
(
"
../models/userModel
"
);
const
registerUser
=
asyncHandler
(
async
(
req
,
res
)
=>
{
const
{
name
,
email
,
password
,
pic
}
=
req
.
body
;
if
(
!
name
||
!
email
||
!
password
)
{
res
.
status
(
400
);
throw
new
Error
(
"
Please Enter all the Feilds
"
);
}
//If user is already exists
const
userExists
=
await
User
.
findOne
({
email
});
// query get from MongoDB
if
(
userExists
)
{
res
.
status
(
400
);
throw
new
Error
(
"
User already exists
"
);
}
//otherwise create new user
//user.create get from MongoDB
const
user
=
await
User
.
create
({
name
,
email
,
password
,
pic
,
});
if
(
user
)
{
res
.
status
(
201
).
json
({
_id
:
user
.
_id
,
name
:
user
.
name
,
email
:
user
.
email
,
pic
:
user
.
pic
,
});
}
else
{
res
.
status
(
400
);
throw
new
Error
(
"
Failed to Create the User
"
);
}
});
module
.
exports
=
{
registerUser
};
\ No newline at end of file
IT18021080/Telemedicine-Chat-App/backend/models/userModel.js
View file @
372c0ddf
...
...
@@ -2,11 +2,11 @@ const mongoose = require("mongoose");
const
userSchema
=
mongoose
.
Schema
({
name
:
{
type
:
String
,
required
:
true
},
email
:
{
type
:
String
,
required
:
true
},
email
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
password
:
{
type
:
String
,
required
:
true
},
pic
:
{
type
:
String
,
required
:
true
,
//required: true, if it is required i can use this reuired as true
default
:
"
https://icon-library.com/images/anonymous-avatar-icon/anonymous-avatar-icon-25.jpg
"
,
},
...
...
IT18021080/Telemedicine-Chat-App/backend/routes/userRoutes.js
View file @
372c0ddf
const
express
=
require
(
"
express
"
);
const
{
registerUser
}
=
require
(
"
../controllers/userControllers
"
);
const
router
=
express
.
Router
();
//router.route("/").post(registerUser)
router
.
route
(
"
/
"
).
post
(
registerUser
);
//router.post("/login",authUser)
module
.
exports
=
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