beautified

This commit is contained in:
xfarrow
2024-03-04 16:49:36 +01:00
parent 3ea41c82d4
commit d9c3f6f55a
18 changed files with 427 additions and 300 deletions

View File

@ -22,4 +22,4 @@ const knexInstance = require('knex')({
}
});
module.exports = knexInstance;
module.exports = knexInstance;

View File

@ -13,7 +13,7 @@
const jwt = require('jsonwebtoken');
function generateToken (person_id) {
function generateToken(person_id) {
// The payload the JWT will carry within itself
const payload = {
person_id
@ -26,16 +26,20 @@ function generateToken (person_id) {
}
// Middlware
function verifyToken (req, res, next) {
function verifyToken(req, res, next) {
const token = req.headers.authorization;
if (!token) {
return res.status(401).send({ error: 'No token provided' });
return res.status(401).send({
error: 'No token provided'
});
}
jwt.verify(token, process.env.JWT_SECRET_KEY, (err, decoded) => {
if (err) {
return res.status(401).send({ error: 'Failed to authenticate token' });
return res.status(401).send({
error: 'Failed to authenticate token'
});
}
// If the token is valid, store the decoded data in the request object
@ -48,4 +52,4 @@ function verifyToken (req, res, next) {
module.exports = {
generateToken,
verifyToken
};
};

View File

@ -16,7 +16,7 @@
* @param {*} email email to validate
* @returns true or false
*/
function validateEmail (email) {
function validateEmail(email) {
const regex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
return regex.test(email);
}
@ -27,7 +27,7 @@ function validateEmail (email) {
* @param {*} dateString the date to validate
* @returns true or false
*/
function isPostgresDateFormatValid (dateString) {
function isPostgresDateFormatValid(dateString) {
const regex = /^\d{4}-\d{2}-\d{2}$/;
return regex.test(dateString);
}
@ -35,4 +35,4 @@ function isPostgresDateFormatValid (dateString) {
module.exports = {
validateEmail,
isPostgresDateFormatValid
};
};