forked from KG-1510/fullstack-project-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf51b77
commit 26214bd
Showing
15 changed files
with
5,273 additions
and
1,183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
/build | ||
|
||
# misc | ||
config.env | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
Oops, something went wrong.