Skip to content

Commit

Permalink
Merge pull request #1 from PsionicGeek/master
Browse files Browse the repository at this point in the history
new commit
  • Loading branch information
Divyanshu-Sethi authored Jan 9, 2024
2 parents 944bfa0 + e3df4b3 commit 148e71b
Show file tree
Hide file tree
Showing 164 changed files with 7,511 additions and 8,376 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules/
node_modules
.env
5 changes: 0 additions & 5 deletions .idea/.gitignore

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/backend-food-ordering-system.iml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

66 changes: 21 additions & 45 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,30 @@
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var adminRouter = require('./routes/admin');

var app = express();
//=======================================================================================================================
const express = require('express')
const mongoose = require('mongoose')
const dotenv = require('dotenv')
dotenv.config({ path: './env' })
//==========================================================================================================================
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(logger('dev'));
const app = express()
const dotenv = require('dotenv');
const userRouter = require("./routes/user")
dotenv.config({path : '.env'})

//=================================================================================
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
const adminRouter = require('./routes/admin')


//==================================================================================

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/admin', adminRouter);
app.use('/user', userRouter);


//=================================================================================
//CONNECT TO DATABASE

// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});

// error handler
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});
//====================================================================================================================
//CONNECTION WITH THE DATABASE
mongoose.connect(process.env.DB_URL, { useNewUrlParser: true, useUnifiedTopology: true })
mongoose.connect( "mongodb://localhost:27017/TastyDB")
.then(() => { console.log('CONNECTED TO DATABASE :)') })
.catch((err) => { console.log('CONNECTION TO DATABASE FAILED :(', err) })


//==========================================================================================================================
module.exports = app;
//===========================================================================
app.listen(8000, ()=>{
console.log('Server Started at port 8000')
})
90 changes: 0 additions & 90 deletions bin/www

This file was deleted.

48 changes: 48 additions & 0 deletions controllers/userController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const asyncHandler = require("express-async-handler");
const User = require("../models/userSchema");
const jwt = require("jsonwebtoken");
const bcrypt = require('bcrypt');

// controllers/authController.js
const signup = async (req, res) => {
try {
const { username, email, mobileNumber, address, password } = req.body;

// Check if user with the given email or mobile number already exists
const existingUser = await User.findOne({ $or: [{ email }, { mobileNumber }] });

if (existingUser) {
return res.status(400).json({ message: 'User with this email or mobile number already exists' });
}

// Hash the password
const hashedPassword = await bcrypt.hash(password, 10);

// Create a new user
const newUser = new User({
username,
email,
mobileNumber,
address,
password: hashedPassword, // Save the hashed password
});

// Save the user to the database
await newUser.save();

res.status(201).json({ message: 'User registered successfully' });
} catch (error) {
console.error(error);
res.status(500).json({ message: 'Internal Server Error' });
}
};


const signin= (req, res) =>{
console.log("hello");
res.send("Hello")
};
module.exports = authController = {
signup,
signin
};
38 changes: 38 additions & 0 deletions middleware/tokenMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const jwt = require("jsonwebtoken");

const requireSign = (req, res, next)=>{
if(req.headers.authorization){
const token = req.headers.authorization.split(" ")[1];
const user = jwt.verify(token, process.env.JWT_SECRET);
req.user=user;
} else {
return res
.status(401)
.json({error:"authorization required"});
}
next();
};

const userMiddleware = (req, res, next) =>{
if (req.user.isAdmin==true){
return res
.status(401)
.json({error:"User Acess Denied"})
}
next();
};

const adminMiddleware = (req, res, next) => {
if(req.user.isAdmin==false){
return res
.status(401)
.json({error:"Not authorised as an admin"})
}
next();
}

module.exports = commonMiddleware = {
requireSign,
userMiddleware,
adminMiddleware
};
23 changes: 4 additions & 19 deletions models/categorySchema.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@

//"category": {
// "id": 1,
// "name": "CategorySchema 1",
// "description": "CategorySchema 1 description",
// "image": "image.jpg",
// "created_at": "2016-11-22T15:28:52.000Z",
// "updated_at": "2016-11-22T15:28:52.000Z",
// "deleted_at": null
//
//
// },

const mongoose = require('mongoose');
const Schema= mongoose.Schema({
const Schema = mongoose.Schema({
name:{
type:String,
required:true
},
description:{
type:String,
required:true
required : true
},
image:{
data:Buffer,
contentType:String,
type : String,
required:true
},
created_at:{
Expand All @@ -39,6 +25,5 @@ const Schema= mongoose.Schema({
default:null
},
});

const Category = mongoose.model('CategorySchema',Schema);
const Category = mongoose.model('Category',Schema);
module.exports = Category;
15 changes: 0 additions & 15 deletions models/dishesSchema.js → models/dishSchema.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
//"dishes": {
// "id": 1,
// "name": "Dish 1",
// "description": "Dish 1 description",
// "image": "image.jpg",
// "price": 10,
// "created_at": "2016-11-22T15:28:52.000Z",
// "updated_at": "2016-11-22T15:28:52.000Z",
// "deleted_at": null,
// "category_id": 1,
// "in_stock": true,
// "ingredients": ["ingredient 1", "ingredient 2", "ingredient 3"]
// },
//

const mongoose = require('mongoose');
const Category = require('./categorySchema.js')

Expand Down
27 changes: 1 addition & 26 deletions models/orderSchema.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
//"orders": {
// "id": 1,
// "status": 1,
// "created_at": "2016-11-22T15:28:52.000Z",
// "updated_at": "2016-11-22T15:28:52.000Z",
// "deleted_at": null,
// "user_id": 1,
// "total": 10,
// "dishes": [
// {
// "dish_id": 1,
// "quantity": 1
// }
// ]
// },
// "status": {
// "1": "pending",
// "2": "in progress",
// "3": "ready",
// "4": "delivered",
// "5": "cancelled"
//
//
// },

const mongoose = require('mongoose');
const User = require('./userSchema')
const Dish = require('./dishesSchema')
const Dish = require('./dishSchema')
const Schema= mongoose.Schema({
status:{
type:Number,
Expand Down
Loading

0 comments on commit 148e71b

Please sign in to comment.