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
e73ad6f3
Commit
e73ad6f3
authored
Aug 21, 2023
by
janithGamage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update
Desc : user API's
parent
89ba060e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
108 deletions
+45
-108
Project/Backend/Server_Node/controllers/user.controller.js
Project/Backend/Server_Node/controllers/user.controller.js
+21
-74
Project/Backend/Server_Node/models/user.model.js
Project/Backend/Server_Node/models/user.model.js
+21
-31
Project/Backend/Server_Node/server.js
Project/Backend/Server_Node/server.js
+3
-3
No files found.
Project/Backend/Server_Node/controllers/user.controller.js
View file @
e73ad6f3
...
...
@@ -2,7 +2,6 @@ import bcrypt from 'bcryptjs';
import
jwt
from
'
jsonwebtoken
'
;
import
mongoose
from
'
mongoose
'
;
import
nodemailer
from
"
nodemailer
"
;
import
{
v4
as
uuidv4
}
from
'
uuid
'
;
import
User
from
'
../models/user.model.js
'
;
export
const
signIn
=
async
(
req
,
res
)
=>
{
...
...
@@ -28,89 +27,36 @@ export const signIn = async (req, res) => {
export
const
signUp
=
async
(
req
,
res
)
=>
{
const
{
firstName
,
lastName
,
email
,
contactNumber
,
password
,
confirmPassword
,
type
,
userFirstName
,
userLastName
,
userContactNumber
,
userAddressLine1
,
userAddressLine2
,
userAddressLine3
,
type
}
=
req
.
body
;
try
{
// if (!type) return res.status(400).json({ code: "02", message: "Type Field Required" })
if
(
!
email
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
Email Field Required
"
})
if
(
!
userFirstName
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
User First Name Field Required
"
})
if
(
!
userLastName
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
User Last Name Field Required
"
})
if
(
!
userContactNumber
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
User Contact Number Field Required
"
})
const
existingUser
=
await
User
.
findOne
({
email
})
if
(
existingUser
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
User already exists
"
})
// if (type === "buyer") {
// if (!password) return res.status(400).json({ code: "02", message: "Password Field Required" })
// if (password !== confirmPassword) return res.status(400).json({ code: "02", message: "Passwords do not match" })
// const hashedPassword = await bcrypt.hash(password, 12)
// const userDetails = new User({
// email,
// password: hashedPassword,
// type,
// userDetails: {
// userQNumber: uuidv4(),
// userEmail: email,
// userName: `${userFirstName} ${userLastName}`,
// userContactNumber,
// userAddress: `${userAddressLine1}, ${userAddressLine2}, ${userAddressLine3}`,
// userType: type,
// }
// })
// const userResult = await userDetails.save()
// const token = jwt.sign({ email: userResult.email, id: userResult._id }, 'test', { expiresIn: "1h" })
// res.status(200).json({ code: "01", result: userResult, token })
// } else if (type === "trader") {
// const userDetails = new User({
// email,
// type,
// userDetails: {
// userQNumber: uuidv4(),
// userEmail: email,
// userName: `${userFirstName} ${userLastName}`,
// userContactNumber,
// userAddress: `${userAddressLine1}, ${userAddressLine2}, ${userAddressLine3}`,
// userType: type,
// },
// states: 2
// })
// const userResult = await userDetails.save()
// const token = jwt.sign({ email: userResult.email, id: userResult._id }, 'test', { expiresIn: "1h" })
// res.status(200).json({ code: "01", result: userResult, token })
// }
if
(
!
password
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
Password Field Required
"
})
if
(
password
!==
confirmPassword
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
Passwords do not match
"
})
const
hashedPassword
=
await
bcrypt
.
hash
(
password
,
12
)
if
(
type
===
null
||
typeof
type
==
"
undefined
"
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
Type Field Required
"
})
if
(
email
===
null
||
typeof
email
==
"
undefined
"
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
Email Field Required
"
})
if
(
firstName
===
null
||
typeof
firstName
==
"
undefined
"
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
First Name Field Required
"
})
if
(
lastName
===
null
||
typeof
lastName
==
"
undefined
"
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
Last Name Field Required
"
})
if
(
contactNumber
===
null
||
typeof
contactNumber
==
"
undefined
"
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
Contact Number Field Required
"
})
const
existingUser
=
await
User
.
findOne
({
email
:
email
})
if
(
existingUser
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
User already exist
"
})
if
(
password
===
null
||
typeof
password
==
"
undefined
"
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
Password Field Required
"
})
if
(
password
!==
confirmPassword
)
return
res
.
status
(
400
).
json
({
code
:
"
02
"
,
message
:
"
Password doesn't match
"
})
const
hashPassword
=
await
bcrypt
.
hash
(
password
,
12
)
const
userDetails
=
new
User
({
firstName
,
lastName
,
email
,
password
:
hashedPassword
,
contactNumber
,
type
,
userDetails
:
{
userQNumber
:
uuidv4
(),
userEmail
:
email
,
userName
:
`
${
userFirstName
}
${
userLastName
}
`
,
userContactNumber
,
userAddress
:
`
${
userAddressLine1
}
,
${
userAddressLine2
}
,
${
userAddressLine3
}
`
,
}
password
:
hashPassword
,
})
const
userResult
=
await
userDetails
.
save
()
...
...
@@ -249,3 +195,4 @@ export const deleteUser = async (req, res) => {
res
.
json
({
code
:
"
00
"
,
"
message
"
:
error
.
message
});
}
}
Project/Backend/Server_Node/models/user.model.js
View file @
e73ad6f3
import
mongoose
from
"
mongoose
"
;
const
userSchema
=
mongoose
.
Schema
({
email
:
{
firstName
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
password
:
{
type
:
String
},
type
:
{
lastName
:
{
type
:
String
,
required
:
true
required
:
true
,
},
userDetails
:
{
userQNumber
:
{
email
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
userEmail
:
{
contactNumber
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
userName
:
{
type
:
String
,
required
:
true
},
userContactNumber
:
{
password
:
{
type
:
String
,
required
:
true
},
userAddress
:
{
type
:
String
required
:
true
,
},
userType
:
{
type
:
String
,
default
:
"
N/A
"
,
type
:
{
type
:
String
,
// administrator/ member
required
:
true
},
},
states
:
{
type
:
String
,
default
:
"
1
"
},
createdAt
:
{
type
:
Date
type
:
Date
,
default
:
new
Date
()
},
updatedAt
:
{
type
:
Date
type
:
Date
,
default
:
new
Date
()
}
});
const
User
=
mongoose
.
model
(
"
Users
"
,
userSchema
);
export
default
User
;
Project/Backend/Server_Node/server.js
View file @
e73ad6f3
...
...
@@ -21,10 +21,10 @@ app.get("/", (req, res) => {
});
//implement routes
app
.
use
(
"
/rest_node/user
"
,
userRoutes
);
app
.
use
(
"
/rest_node/ssl
"
,
translateRoutes
);
app
.
use
(
"
/rest_node/user
"
,
userRoutes
);
const
CONNECTION_URL
=
`mongodb+srv://
${
process
.
env
.
DB_USERNAME
}
:
${
process
.
env
.
DB_PASSWORD
}
@
cluster0.dmza8yi
.mongodb.net/?retryWrites=true&w=majority`
;
const
CONNECTION_URL
=
`mongodb+srv://
${
process
.
env
.
DB_USERNAME
}
:
${
process
.
env
.
DB_PASSWORD
}
@
researchmanagement-appl.vzhn4
.mongodb.net/?retryWrites=true&w=majority`
;
const
PORT
=
process
.
env
.
PORT
||
5000
;
mongoose
...
...
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