Skip to content

Commit

Permalink
Version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
samarthbc committed Aug 5, 2024
0 parents commit f2b0c9d
Show file tree
Hide file tree
Showing 132 changed files with 24,148 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
10 changes: 10 additions & 0 deletions Backend/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const mongoose = require('mongoose');
const mongoURL = "mongodb://localhost:27017/FarmConnect?";

// const mongoURL = "mongodb://192.168.0.106:27017/FarmConnect?"; //IP address

const connectToMongo = () => {
mongoose.connect(mongoURL)
};

module.exports = connectToMongo;
31 changes: 31 additions & 0 deletions Backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const connectToMongo = require('./db');
const express = require('express')
const cors = require('cors')
const path = require('path')
const multer = require('multer')

connectToMongo();
const app = express()
const port = 5000

// Enabling cors for all routes
app.use(cors())

// Setting up public as a static folder
app.use(express.static(path.join(__dirname,'public')))

// Available Routes are divided into seperate files for each cateory of routes
app.use('/api/supplierauth', require('./routes/supplierauth'))
app.use('/api/farmerauth', require('./routes/farmerauth'))
app.use('/api/buyerauth', require('./routes/buyerauth'))
app.use('/api/supplieritem', require('./routes/supplieritem'))
app.use('/api/farmeritem', require('./routes/farmeritem'))

// '/' of backend (testing purposes)
app.get("/",(req,res)=>{
res.json("FarmConnect backend is Farming.... Let him cook...")
})

app.listen(port, () => {
console.log(`Listening at http://localhost:${port}`)
})
23 changes: 23 additions & 0 deletions Backend/middleware/fetchbuyer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const jwt = require('jsonwebtoken')

const JWT_SECRET = "ImBatman";

const fetchbuyer = (req,res,next) =>{
let success = false

// Fetching the buyer from auth-token
const token = req.header('auth-token');
if(!token){
return res.status(400).send({error:"Authenticate using a valid token", success});
}

try{
const data = jwt.verify(token, JWT_SECRET);
req.buyer = data.buyer;
next();
}catch(error){
return res.status(401).json({error:error});
}
}

module.exports = fetchbuyer;
23 changes: 23 additions & 0 deletions Backend/middleware/fetchfarmer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const jwt = require('jsonwebtoken')

const JWT_SECRET = "ImBatman";

const fetchfarmer = (req,res,next) =>{
let success = false

// Fetching the farmer from auth-token
const token = req.header('auth-token');
if(!token){
return res.status(400).send({error:"Authenticate using a valid token", success});
}

try{
const data = jwt.verify(token, JWT_SECRET);
req.farmer = data.farmer;
next();
}catch(error){
return res.status(401).json({error:error});
}
}

module.exports = fetchfarmer;
23 changes: 23 additions & 0 deletions Backend/middleware/fetchsupplier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const jwt = require('jsonwebtoken')

const JWT_SECRET = "ImBatman";

const fetchsupplier = (req,res,next) =>{
let success = false

// Fetching the supplier from auth-token
const token = req.header('auth-token');
if(!token){
return res.status(400).send({error:"Authenticate using a valid token", success});
}

try{
const data = jwt.verify(token, JWT_SECRET);
req.supplier = data.supplier;
next();
}catch(error){
return res.status(401).json({error:error});
}
}

module.exports = fetchsupplier;
30 changes: 30 additions & 0 deletions Backend/models/Buyer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

// This is the model for 'buyer'
const BuyerSchema = new Schema({
name: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password:{
type: String,
required: true
},
location:{
type: String,
// required: true
},
profileimg:{
type: String,
default: "pfp_blank.png"
}
});

const Buyer = mongoose.model('buyer', BuyerSchema);
Buyer.createIndexes();
module.exports = Buyer;
36 changes: 36 additions & 0 deletions Backend/models/Farmer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

// This is the model for 'farmer'
const FarmerSchema = new Schema({
name: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password:{
type: String,
required: true
},
location:{
type: String,
// required: true
},
address:{
type: String,
},
phno:{
type:Number,
},
profileimg:{
type: String,
default: "pfp_blank.png"
}
});

const Farmer = mongoose.model('farmer', FarmerSchema);
Farmer.createIndexes();
module.exports = Farmer;
45 changes: 45 additions & 0 deletions Backend/models/FarmerItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

// This is the model for 'farmer items'
const FarmerItemSchema = new Schema({
farmer:{
type:mongoose.Schema.Types.ObjectId,
required:true
},
name:{
type:String,
required:true
},
description:{
type:String,
required:true
},
date:{
type: Date,
default: Date.now()
},
manuDate: {
type: Date,
required: true
},
mrp: {
type: Number,
required: true
},
sp: {
type: Number,
required: true
},
itemImg: {
type: String,
default: "buyershop/default.png"
},
tags: {
type: [String]
}
})

const FarmerItem = mongoose.model('farmeritem', FarmerItemSchema);
FarmerItem.createIndexes();
module.exports = FarmerItem;
36 changes: 36 additions & 0 deletions Backend/models/Supplier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

// This is the model for 'supplier'
const SupplierSchema = new Schema({
name: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password:{
type: String,
required: true
},
location:{
type: String,
// required: true
},
address:{
type: String,
},
phno:{
type:Number,
},
profileimg:{
type: String,
default: "pfp_blank.png"
}
});

const Supplier = mongoose.model('supplier', SupplierSchema);
Supplier.createIndexes();
module.exports = Supplier;
45 changes: 45 additions & 0 deletions Backend/models/SupplierItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

// This is the model for 'supplier items'
const SupplierItemSchema = new Schema({
supplier: {
type: mongoose.Schema.Types.ObjectId,
ref: 'supplier'
},
name: {
type: String,
required: true
},
description: {
type: String,
required: true
},
date:{
type: Date,
default: Date.now()
},
manuDate: {
type: Date,
required: true
},
mrp: {
type: Number,
required: true
},
sp: {
type: Number,
require: true
},
itemImg: {
type: String,
default: "buyershop/default.png"
},
tags: {
type: [String]
}
})

const SupplierItem = mongoose.model('supplieritem', SupplierItemSchema);
SupplierItem.createIndexes();
module.exports = SupplierItem;
Loading

0 comments on commit f2b0c9d

Please sign in to comment.