Skip to content

Commit

Permalink
✨ add:MVC
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay-Satish-01 committed Apr 7, 2022
1 parent bf51b77 commit 26214bd
Show file tree
Hide file tree
Showing 15 changed files with 5,273 additions and 1,183 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/build

# misc
config.env
.DS_Store
.env.local
.env.development.local
Expand Down
10 changes: 10 additions & 0 deletions Controllers/Auth/AuthLogin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require('express');
const StudentData = require('../../Model/StudentData');

exports.postLogin = async (req, res) => {
const email = req.body.email;
// const password = req.body.password;

const data = await StudentData.findOne({ where: { email: email } });
const password = data.password;
};
24 changes: 24 additions & 0 deletions Controllers/Auth/AuthRegister.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const express = require('express');
const StudentData = require('../../Model/StudentData');

exports.postRegister = async (req, res) => {
const id = req.body.id;
const name = req.body.name;
const email = req.body.email;
const password = req.body.password;
const image = req.body.image;
const year = req.body.year;
const branch = req.body.branch;
const spl = req.body.spl;

await StudentData.create({
id,
name,
email,
password,
image,
year,
branch,
spl,
});
};
8 changes: 8 additions & 0 deletions Controllers/Transaction/TransactionGet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const express = require('express');

const TransactionGetController = async (req, res, next) => {
const { details } = req.body;
console.log(details);
res.send('details got');
};
module.exports = TransactionGetController;
6 changes: 6 additions & 0 deletions Controllers/Transaction/TransactionPost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const express = require('express');

const TransactionPostController = async (req, res, next) => {
res.send('get transaction');
};
module.exports = TransactionPostController;
40 changes: 40 additions & 0 deletions Model/StudentData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { Sequelize, DataTypes } = require('sequelize');

const sequelize = require('../Utilities/Database');

const StudentData = sequelize.define('studentdata', {
id: {
type: DataTypes.STRING,
required: true,
autoIncrement: true,
allowNull: false,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
required: true,
},
email: {
type: DataTypes.STRING,
required: true,
},
password: {
type: DataTypes.STRING,
required: true,
},
image: {
type: DataTypes.STRING,
},
year: {
type: DataTypes.INTEGER,
required: true,
},
branch: {
type: DataTypes.STRING,
required: true,
},
spl: {
type: DataTypes.STRING,
},
});
module.exports = StudentData;
33 changes: 33 additions & 0 deletions Model/TransactionData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { Sequelize, DataTypes } = require('sequelize');

const sequelize = require('../Utilities/Database');

const TransactionData = sequelize.define('transactiondata', {
tx_id: {
type: DataTypes.STRING,
required: true,
autoIncrement: true,
allowNull: false,
primaryKey: true,
},
tx_name: {
type: DataTypes.STRING,
required: true,
},
due_date: {
type: DataTypes.DATE,
},
amount: {
type: DataTypes.INTEGER,
required: true,
},

status: {
type: DataTypes.INTEGER,
required: true,
},
paid_on: {
type: DataTypes.DATE,
},
});
module.exports = TransactionData;
13 changes: 13 additions & 0 deletions Utilities/Database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Sequelize = require('sequelize').Sequelize;

const sequelize = new Sequelize(
process.env.DATABASE,
'root',
process.env.DBPASS,
{
dialect: 'mysql',
host: 'localhost',
}
);

module.exports = sequelize;
28 changes: 28 additions & 0 deletions Utilities/JWT_Auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const jwt = require('jsonwebtoken');

const GenerateJWT = function (data) {
var user = { userData: data };
payload = user;
token = jwt.sign(payload, process.env.TOKEN_SECRET, {
expiresIn: '30d',
});
return token;
};
const getUserData = (token) => {
return jwt.verify(token, process.env.TOKEN_SECRET).userData;
};
const verifyHeaderToken = () => {
const token = req.headers.token;
if (token.length < 1) {
jwt.verify(token, process.env.TOKEN_SECRET, (err, decode) => {
JSON.stringify(decoded.userData);

req.headers.userData = decoded.userData;
next();
});
}
};
module.exports = {
GenerateJWT,
getUserData,
};
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const express = require("express");
const mysql = require("mysql");

const express = require('express');
const mysql = require('mysql');
const TransactionRoutes = require('./routes/TransactionRoutes');
const dotenv = require('dotenv');
const cors = require('cors');
dotenv.config({ path: 'config.env' });
const app = express();

app.get("/transactions", (req, res) => {
res.send("Transaction GET")
app.use(cors());
app.use(express.json());
app.get('/', (req, res) => {
res.send('Home');
});

app.use('/transac', TransactionRoutes);

app.listen(3001, () => {
console.log("✅ Server is started at port: 3001");
console.log('✅ Server is started at port: 3001');
});
Loading

0 comments on commit 26214bd

Please sign in to comment.