-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from TeaghanEveleigh/master
Refactored: altered endpoints
- Loading branch information
Showing
13 changed files
with
277 additions
and
71 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 |
---|---|---|
|
@@ -21,4 +21,5 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.env | ||
.env | ||
.crt |
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,84 @@ | ||
|
||
|
||
|
||
please note that as it stands the application runs on local host port 4000 so for any endpoints must start with the following | ||
|
||
REQUIRES VERIFICATION : if the user is not logged in and has a verified token they can not use this endpoint | ||
the frontend should first login/signup and get the token and only then make requests | ||
|
||
http://localhost:4000 | ||
|
||
Endpoints for application | ||
|
||
|
||
USER Endpoints : for this the convention is /user/{the desired endpoint} | ||
|
||
|
||
http://localhost:4000/user | ||
|
||
|
||
Post Requests : | ||
|
||
Login : | ||
|
||
- logs the user in and returns verification token in the response , this token is used for validation | ||
|
||
endpoint - http://localhost:4000/user/login | ||
|
||
Request body - [email , password ] | ||
|
||
|
||
Signup : | ||
|
||
- signs user in creating an account if account already exists it sends back unsuccesfull along with the message | ||
and returns verification token in the response , this token is used for validation | ||
|
||
endpoint - http://localhost:4000/user/signup | ||
|
||
Request body - [email , password ] | ||
|
||
|
||
Get Requests : | ||
|
||
|
||
REQUIRES VERIFICATION | ||
|
||
Balance : | ||
|
||
endpoint - http://localhost:4000/user/balance | ||
|
||
-Balance gets the users balance but please note this is an endpoint that REQUIRES VERIFICATION so if the user is not logged in and has a verified token they can not use this endpoint | ||
the frontend should first login/signup and get the token and only then make requests | ||
|
||
|
||
|
||
http://localhost:4000/transactions | ||
|
||
|
||
REQUIRES VERIFICATION | ||
|
||
Post requests : | ||
|
||
endpoint - http://localhost:4000/transactions/makeTransaction | ||
|
||
Request body - [ amount,title,description ] | ||
|
||
-the endpoint makes a transaction and adds it to the table of transactions it assigns it to our user , it automatically updates the specified users balance to account for the new transaction | ||
|
||
|
||
|
||
|
||
|
||
REQUIRES VERIFICATION | ||
|
||
Get requests : | ||
|
||
endpoint - http://localhost:4000/transactions/getTransactionByPage | ||
|
||
Params : pagenumber = x | ||
|
||
- for this you just need to in the request params assign a value pagenumber , this will return the users transactions. It bassicly just works in the way you would expect | ||
if you do the pagenumber =1 you get the first ten transactions // frontend peeps please let me know if you want to change the number of requests | ||
|
||
|
||
|
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,25 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIEQTCCAqmgAwIBAgIUKo2BX+ykzxZslXAlxKniKTUO1Z0wDQYJKoZIhvcNAQEM | ||
BQAwOjE4MDYGA1UEAwwvZjdlNjkyMmYtYjc1Mi00ZWQzLWJhMjUtZTI1YjAwNjU0 | ||
YTE3IFByb2plY3QgQ0EwHhcNMjQwODA0MjMzMjU0WhcNMzQwODAyMjMzMjU0WjA6 | ||
MTgwNgYDVQQDDC9mN2U2OTIyZi1iNzUyLTRlZDMtYmEyNS1lMjViMDA2NTRhMTcg | ||
UHJvamVjdCBDQTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAKSXRMAi | ||
unkpsnRzCFavjmxpRNj+amFYjvem6rQIWe+YLtqw24Mk326iWv6fVCgESV0APWnM | ||
vHp4HawWCqnpt3KVf6xTmAfNAbazODJZZTg3HHKidQSU4z/7cUUJdrneskjthYAD | ||
4IxqE555PIWDMoFwq1/W14DihLRmuzdDOCaxH4EKfhSOjzxwyM/tQjVvauhpuAFy | ||
TgnmBp8scue96F6hKTBccgBzA4xBT8lcj5KvCjLY6Fn2lQCU+Z0KPtqC97OWnu0l | ||
/uiAzK6Ciu0hHRNQ+vo+Epj+Xeg+mcerg4TuZlJWCFatEfPmwBcpzXkkmkrUI/Qu | ||
pjvlkYLX/R2MWTH/oG4zLbmpPQHVF8CXDxvfCpwcJCbO96VAy4sHKfwaX96Rbtge | ||
urrFtvYQSI8REEnkIT/3zt9PxusL/caqNX0roW79qhCJ4D0BMaSMk1gkNl1fomJA | ||
l1h7HsL+UGiYxOCyppmuVuiu3gtle76RGz/ZaKbCOiK0/GkxEa/8eTVBLwIDAQAB | ||
oz8wPTAdBgNVHQ4EFgQUCboAowy7OHOkydNbBfuQ/iH23cUwDwYDVR0TBAgwBgEB | ||
/wIBADALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEMBQADggGBAHmiS7RSqL8JaH9L | ||
vbASqpSsFHTXCNkcy5qXbC12+srSX2NKvXDoA0Bp85kWnupuk4rmR6J7CQNl2Utk | ||
hCaCxl5IpJ6IjqEdxoemnRrGRtGwHA68LUj3PofbWklxSgzkxXTkY1gKnTnUomj+ | ||
PLyM2B4afe3yngB9gDxvePfFdu2K9ij1qA9UJL3ffuDSsStE4o0f/qHDf7i3L+9g | ||
JDPx+fkxnv0Eco5vsPh9MigsMQvlfYLgeg69lcsI5jyqf6SKElaQaIF05PrqFk5L | ||
cbWKnZYeNPH32DwowVHeTjzbKLybq4nMzhyhBbXkIkHgN2ib5cmUm6lEjyUUbKgG | ||
ZoVF2/mYNB/Z/VobXDbWXZNHKAnoPISz2nVnGhMXw2CArBNd8fYmj+khe4IeVrcz | ||
2Haa/SEbiknxymB3w2yIsMZMcv4PpPZ7OsZq98/IYmg6a7eEg+kyMVSi+a9O0syy | ||
nxM1F7OXJD5zfups8JOOPLrlApyKmVdv/9iUq6DRn5V526+Jtg== | ||
-----END CERTIFICATE----- |
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,18 @@ | ||
const cors = require('cors'); | ||
|
||
const allowedOrigins = ['http://localhost:4000']; // Add your allowed origins here | ||
|
||
const corsOptions = { | ||
origin: function (origin, callback) { | ||
if (!origin || allowedOrigins.indexOf(origin) !== -1) { | ||
callback(null, true); | ||
} else { | ||
callback(new Error('Not allowed by CORS')); | ||
} | ||
}, | ||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], | ||
allowedHeaders: ['Content-Type', 'Authorization'], | ||
credentials: true, | ||
}; | ||
|
||
module.exports = cors(corsOptions); |
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
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,27 @@ | ||
|
||
const {getUserTransactionsByPage , makeTransaction} = require('../services/transactionService') | ||
const jwt = require('jsonwebtoken'); | ||
|
||
exports.transaction = async (req, res) => { | ||
const {amount,title,description} = req.body; | ||
const userID = req.user.id; | ||
try { | ||
await makeTransaction(userID , amount , title , description ); | ||
res.send({ success: true }); | ||
} catch (error) { | ||
console.error('Error making transactions', error); | ||
res.status(500).send({ success: false, error: error.message }); | ||
} | ||
} | ||
|
||
exports.transactions = async(req , res) =>{ | ||
const {pageNumber} = req.params; | ||
const userID = req.user.id; | ||
try{ | ||
const result = await getUserTransactionsByPage(userID , pageNumber); | ||
res.status(200).send({sucess : true , result : result}) | ||
}catch{ | ||
console.error('Error when getting transactions' , error); | ||
res.status(500).send({ success: false, error: error.message }); | ||
} | ||
} |
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
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,12 @@ | ||
const express = require('express'); | ||
const {isAuthenticated} = require('../middleware/autMiddleware') | ||
const router = express.Router(); | ||
const jwt = require('jsonwebtoken'); | ||
const {getUserTransactionsByPage , makeTransaction} = require('../services/transactionService') | ||
const transactionController = require('../controllers/transactionsController') | ||
|
||
|
||
router.post('/makeTransaction', isAuthenticated, transactionController.transaction); | ||
router.get('/getTransactionByPage/:pageNumber' , isAuthenticated , transactionController.transactions); | ||
|
||
module.exports = router; |
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,26 @@ | ||
const express = require('express'); | ||
const {isAuthenticated} = require('../middleware/autMiddleware') | ||
const router = express.Router(); | ||
const jwt = require('jsonwebtoken'); | ||
const usersController = require('../controllers/usersController'); | ||
|
||
// router.post('/checkEmailExists', async (req, res) => { | ||
// const email = req.body.email; | ||
// const emailExists = await checkEmailExists(email); | ||
// res.send({ emailExists }); | ||
// }); | ||
|
||
// router.post('/checkPasswordCorrect', async (req, res) => { | ||
// const email = req.body.email; | ||
// const password = req.body.password; | ||
// const passwordCorrect = await checkPasswordCorrect(email, password); | ||
// res.send({ passwordCorrect }); | ||
// }); | ||
|
||
router.post('/login', usersController.login); | ||
router.post('/signup', usersController.signup); | ||
router.get('/balance', isAuthenticated, usersController.balance); | ||
|
||
|
||
|
||
module.exports = router; |
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
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
Oops, something went wrong.