Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2d0ac8e
Update README.md
SaraTahiri Mar 27, 2024
4909e13
Add CRUD for client entity
SaraTahiri Mar 27, 2024
8cc84b5
Update README.md
SaraTahiri Mar 27, 2024
8120ba4
Modify server.js for client CRUD (pre-normalizing)
SaraTahiri Mar 27, 2024
0e200cc
Add new dependecies
SaraTahiri Mar 27, 2024
57f1e75
Add .gitignore
SaraTahiri Mar 27, 2024
32c095a
Add mail confirmation feat helper
SaraTahiri Mar 27, 2024
a4bc792
Add hashing (bcrypt) and jwt helpers
SaraTahiri Mar 27, 2024
5090ef5
Add client auth and data handling middlewares
SaraTahiri Mar 27, 2024
955a412
Add client routes and controllers
SaraTahiri Mar 27, 2024
7e9b315
Add Mongo user schema
SaraTahiri Mar 27, 2024
4f6026e
Resolve merge conflict
SaraTahiri Mar 27, 2024
f345f63
Updated client controllers
SaraTahiri Mar 28, 2024
6a02fd1
Update and delete profile
SaraTahiri Mar 28, 2024
f4c018a
Update authentification function
SaraTahiri Mar 28, 2024
7d46317
Updated schema version 2
SaraTahiri Mar 28, 2024
f25a15d
Updated database
SaraTahiri Mar 28, 2024
cc3eac2
Add logout function
SaraTahiri Mar 30, 2024
265cdd3
Update the last version of clients controllers
SaraTahiri Mar 31, 2024
7d7469f
Update profile controllers
SaraTahiri Mar 31, 2024
d43bca3
Update function isAutheticated
SaraTahiri Mar 31, 2024
8c8627b
Update validation function
SaraTahiri Mar 31, 2024
e77c39c
Update Clients schema
SaraTahiri Mar 31, 2024
05c0d44
Adding route for orders controllers
SaraTahiri Mar 31, 2024
6edc473
View all orders and details, update, delete and tracking orders
SaraTahiri Mar 31, 2024
a5d643f
Add Orders Schema to Models folder
SaraTahiri Mar 31, 2024
804c87b
Updated order schema
SaraTahiri Apr 2, 2024
b6ee04e
Update clients schema
SaraTahiri Apr 2, 2024
7f334fb
View,Update and delete profile
SaraTahiri Apr 2, 2024
6996d21
View all orders, view details, update, delete and tracking order
SaraTahiri Apr 2, 2024
0fdd90a
View all orders, view details, update, delete and tracking order
SaraTahiri Apr 2, 2024
037c990
View all orders, view details, update, delete and tracking order
SaraTahiri Apr 2, 2024
bca3d73
Add function to verify email
SaraTahiri Apr 15, 2024
16a5d6c
Modify status and response message
SaraTahiri Apr 15, 2024
67f4df5
Modify status and response message
SaraTahiri Apr 15, 2024
1cf8fa4
Add helpers to verify email
SaraTahiri Apr 15, 2024
542e961
Define schema for token
SaraTahiri Apr 15, 2024
5ff2ac5
Add verify, googleId, googleAccessToken to client schema
SaraTahiri Apr 15, 2024
d31e7b9
Add routes for google oauth2.0
SaraTahiri Apr 15, 2024
ca93f66
Add the config file of the server and th database
SaraTahiri Apr 15, 2024
23ee522
Sending config file
SaraTahiri Apr 15, 2024
d21d773
Implement MongoDB connection function
SaraTahiri Apr 15, 2024
248da62
Add dependencies passport and passport-google-oauth20
SaraTahiri Apr 15, 2024
3c3312c
Adding some modification
SaraTahiri Apr 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
106 changes: 106 additions & 0 deletions Controllers/Clients.Controllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const User = require('../Modals/Schema/UserSch')
const Token = require('../Modals/Schema/token')
const {HTTP_STATUS_CODES,RESPONSE_MESSAGES} = require('../config/constants')
const {sendEmail} = require('../Helpers/mailer')
const {sendEmailVerification} = require('../Helpers/mailverify')
const {hashPassword,comparePassword} = require('../Helpers/Hashing')
const {generateToken} = require('../Helpers/JWT')
const crypto = require('crypto')

//Register
exports.registerUser = async (req,res) => {
try{
const {username,email,password,age,clientAddress,country,sex,phoneNumber,bio,verified} = req.body
const user = await User.findOne({email :email})
if(user){
return res.status(HTTP_STATUS_CODES.BAD_REQUEST).json({message: 'User already exists'})
}
const hashedPassword = await hashPassword(password)
const newUser = new User({
username,
email : email,
password : hashedPassword,
age ,
clientAddress,
country ,
sex ,
phoneNumber ,
bio,
verified
})
const result = await newUser.save()
const token = await new Token({
userId : newUser._id,
token : crypto.randomBytes(32).toString("hex")
}).save()
const sendTokenMail = await sendEmailVerification(newUser.email,token.userId,token.token) //function to verify email client
if(sendTokenMail){
sendEmail(newUser.email,newUser.username)
}
res.status(HTTP_STATUS_CODES.OK).send(RESPONSE_MESSAGES.USER_CREATED_SUCCESS)
}catch(error){
res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).send('Server Error');
}
}

//To Verify Email Address
exports.verifyEmail = async (req,res) => {
try{
const token = req.params.token
const userToken = await Token.findOne({
userId : req.params.id,
token : token
})

if(!userToken){
return res.status(HTTP_STATUS_CODES.BAD_REQUEST).send({message: "Your verification link may have expired."})
}else{
const user = await User.findOne({_id : req.params.id})
if(!user){
return res.status(HTTP_STATUS_CODES.UNAUTHORIZED).send({message: "We were enable to find a user for this verification.Signup!"})
}else if(user.verified){
return res.status(HTTP_STATUS_CODES.OK).send({message: "User has been already verified.Please login"})
}else{
const updated = await User.updateOne({verified:true})

if(!updated){
return res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).send({message: "error"})
}else{
return res.status(HTTP_STATUS_CODES.OK).send({message : "Your account has been successfuly verified"})
}
}
}
}catch(error){
res.status(HTTP_STATUS_CODES.BAD_REQUEST).send("An error occurred")
}
}

//Login
exports.userLogin = async (req,res) => {
try{
const {email,password} = req.body
const user = await User.findOne({email})
if(!user){
return res.status(HTTP_STATUS_CODES.BAD_REQUEST).json(RESPONSE_MESSAGES.INVALID_CREDENTIALS)
}

const checked =await comparePassword(password,user.password)
if(!checked) return res.status(HTTP_STATUS_CODES.BAD_REQUEST).json({message:"Incorrect Password"})

const token = await generateToken({user})
res.status(HTTP_STATUS_CODES.OK).cookie('tokenAuth',token).send('User logged successfuly')
}catch(error){
res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).send('Server Error');
}

}

//Logout
exports.userLogout = async (req,res) => {
try{
res.clearCookie('tokenAuth')
res.send("Logout successfuly")
}catch(error){
res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).send('Server Error')
}
}
91 changes: 91 additions & 0 deletions Controllers/Orders.Controllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const Order = require("../Modals/Schema/OrderSchema")
const {HTTP_STATUS_CODES,RESPONSE_MESSAGES} = require('../config/constants')

//View all orders page
exports.allOrders = async (rea,res) => {
try{
const orders = await Order.find({})
res.status(HTTP_STATUS_CODES.OK).json({
message : RESPONSE_MESSAGES.ORDER_CREATED_SUCCESS ,
data : orders
})
}catch(error){
res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).send(RESPONSE_MESSAGES.INTERNAL_SERVER_ERROR)
}
}

//Order details page
exports.orderDetails = async (req,res) => {
try{
const id = req.params.id
const order = await Order.findById(id)
if(!order){
res.status(HTTP_STATUS_CODES.NOT_FOUND).send(RESPONSE_MESSAGES.ORDER_NOT_FOUND)
}
const details = {
Restaurant : order.restaurant ,
Address : order.deliveryAddress ,
Status : order.status ,
Total : order.totalPrice ,
PayementMethod : order.paymentMethod
}
res.status(HTTP_STATUS_CODES.OK).json(details)
}catch(error){
res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).send(RESPONSE_MESSAGES.INTERNAL_SERVER_ERROR)
}
}

//Update order
exports.updateOrder = async (req,res) => {
try {
const id = req.params.id
const updates = req.body

const updatedOrder = await Order.findByIdAndUpdate(id, updates, { new: true });

if (!updatedOrder) {
return res.status(HTTP_STATUS_CODES.NOT_FOUND).json(RESPONSE_MESSAGES.ORDER_NOT_FOUND)
}

res.json({
message: RESPONSE_MESSAGES.ORDER_UPDATED_SUCCESS ,
data: updatedOrder
})
} catch (error) {
res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).json(RESPONSE_MESSAGES.INTERNAL_SERVER_ERROR)
}
}

//Delete Order
exports.deleteOrder = async (req,res) => {
try{
const id = req.params.id

const order = await Order.findByIdAndDelete(id)

if(!order){
res.status(HTTP_STATUS_CODES.NOT_FOUND).json(RESPONSE_MESSAGES.ORDER_NOT_FOUND)
}

res.status(HTTP_STATUS_CODES.OK).json(RESPONSE_MESSAGES.ORDER_CANCELED_SUCCESS)
}catch(error){
res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).json(RESPONSE_MESSAGES.INTERNAL_SERVER_ERROR)
}
}

//Track orders page
exports.trackOrder = async (req,res) => {
try{
const {id} = req.query
const order = await Order.findById(id)
if(!order){
res.status(HTTP_STATUS_CODES.NOT_FOUND).json(RESPONSE_MESSAGES.ORDER_NOT_FOUND)
}
const trackingInfo = {
status : order.status
}
res.status(HTTP_STATUS_CODES.OK).json(trackingInfo)
}catch(error){
res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).send(RESPONSE_MESSAGES.INTERNAL_SERVER_ERROR)
}
}
Loading