Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Logs
.DS_Store
logs
*.log
npm-debug.log*
Expand Down
4 changes: 3 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
npx lint-staged
npm run lint
npx lint-staged
npm run test:coverage
8 changes: 8 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path');

module.exports = {
config: path.resolve('config', 'db.config.js'),
'seeders-path': path.resolve('database/seeders'),
'models-path': path.resolve('database/models'),
'migrations-path': path.resolve('database/migrations'),
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ You're all set up and ready to start working with the Node.js application. Happy

## What This Repository Offers

This repository provides a Node.js application for demonstrating JWT authentication and authorization. It includes features such as user registration, user login, and authorization process. The application is built using Express.js, JWT for authentication, Sequelize ORM for database interactions, and MySQL for database storage.
This repository provides a Node.js application for demonstrating JWT authentication and authorization. It includes features such as user registration, user login, and authorization process. The application is built using Express.js, JWT for authentication, [Sequelize ORM](https://sequelize.org/docs/v6/other-topics/migrations/) for database interactions, and MySQL for database storage.

- Bootstrap project for creating APIs using Express.js
- Pre-configured ESLint setup for code quality assurance
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import bcrypt from 'bcryptjs';
import jwt from 'jsonwebtoken';
import db from '../models/index.js';
import config from '../config/auth.config.js';
import config from '../../config/auth.config.js';
import { SUCCESS_REGISTRATION, SUCCESS_REGISTRATION_USER_ROLE, USER_NOT_FOUND, INVALID_PASSWORD, HASHED_PASSWORD } from '../utils/constant.js';

const { user: User, role: Role } = db;
Expand Down
2 changes: 1 addition & 1 deletion app/middleware/authJwt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable consistent-return */
/* eslint-disable no-restricted-syntax */
import jwt from 'jsonwebtoken';
import config from '../config/auth.config.js';
import config from '../../config/auth.config.js';
import db from '../models/index.js';

const { user: User } = db;
Expand Down
10 changes: 2 additions & 8 deletions app/models/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import Sequelize from 'sequelize';
import config from '../config/db.config.js';
import config from '../../config/db.config.js';
import createUserModel from './User.js';
import createRoleModel from './Role.js';
import createGuestModel from './Guest.js';

const { DB, USER, PASSWORD, HOST, DIALECT, pool } = config;

const sequelize = new Sequelize(DB, USER, PASSWORD, {
host: HOST,
dialect: DIALECT,
pool
});
const sequelize = new Sequelize({...config});

const db = {
Sequelize,
Expand Down
File renamed without changes.
24 changes: 0 additions & 24 deletions config/config.json

This file was deleted.

11 changes: 5 additions & 6 deletions app/config/db.config.js → config/db.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const config = {
HOST: process.env.DB_HOST,
USER: process.env.DB_USER,
PASSWORD: process.env.DB_PASSWORD,
DB: process.env.DB_NAME,
DIALECT: process.env.DB_DIALECT,
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
dialect: process.env.DB_DIALECT,
pool: {
max: parseInt(process.env.DB_POOL_MAX, 10),
min: parseInt(process.env.DB_POOL_MIN, 10),
acquire: parseInt(process.env.DB_POOL_ACQUIRE, 10),
idle: parseInt(process.env.DB_POOL_IDLE, 10)
}
};

export default config;
13 changes: 5 additions & 8 deletions coverage/lcov.info
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ DA:11,0
DA:12,0
LF:5
LH:0
BRDA:10,0,0,0
BRDA:10,0,1,0
BRF:2
BRF:0
BRH:0
end_of_record
TN:
Expand Down Expand Up @@ -289,11 +287,10 @@ FNF:0
FNH:0
DA:7,0
DA:9,0
DA:15,0
DA:24,0
DA:27,0
DA:31,0
LF:6
DA:18,0
DA:21,0
DA:25,0
LF:5
LH:0
BRF:0
BRH:0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import db from '../app/models/index.js';
import db from '../../app/models/index.js';

db.sequelize.sync()
.then(() => console.log('Database sync complete.'))
Expand Down
27 changes: 0 additions & 27 deletions migrations/20240412074035-create-roles.cjs

This file was deleted.

33 changes: 0 additions & 33 deletions migrations/20240412074035-create-users.cjs

This file was deleted.

44 changes: 0 additions & 44 deletions migrations/20240412074305-create-user-roles.cjs

This file was deleted.

42 changes: 0 additions & 42 deletions models/index.cjs

This file was deleted.

17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
"description": "This repository provides a Node.js application for demonstrating JWT authentication and authorization. It includes features such as user registration, user login, and authorization process. The application is built using Express.js, JWT for authentication, Sequelize ORM for database interactions, and MySQL for database storage.",
"main": "app/server.js",
"type": "module",
"engines": {
"node": ">=20.6.0"
},
"scripts": {
"start": "node --env-file .env app/server.js ",
"dev": "nodemon --env-file .env app/server.js",
"sync-db": "node custom_migration/sync-db.js",
"create-table": "sequelize-cli migration:generate --name create_table",
"sync-db": "node database/custom_migration/sync-db.js",
"create-table": "sequelize-cli migration:generate --name",
"migrate": "sequelize-cli db:migrate",
"migrate:undo": "sequelize-cli db:migrate:undo",
"migrate:undo:all": "sequelize-cli db:migrate:undo:all",
"seed": "sequelize-cli db:seed:all",
"generate:seed": "sequelize-cli seed:generate --name demo-user",
"generate:seed": "sequelize-cli seed:generate --name",
"lint:clear": "rm -rf ~/.eslintcache",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
Expand All @@ -25,6 +28,14 @@
"updateSnapshots": "jest -u --coverage=false"
},
"jest": {
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
},
"collectCoverage": true,
"collectCoverageFrom": [
"app/**/*.js",
Expand Down