diff --git a/backend/README.md b/backend/README.md index 1e7187bd846659ef0198106e5558395862001f4f..66d7b81d6b9ec1a6bfa8f66c83b2f7520e9330fc 100644 --- a/backend/README.md +++ b/backend/README.md @@ -19,28 +19,9 @@ sequelize db:migrate ``` npm start ``` +To run test, run +``` +npm test +``` 6. Do work. Any changes in the backend will be automatically updated. No more turning the server on and off again! :) -7. Good luck have fun! - -## File Structure -``` -backend -+-- src -| +-- config -| | +-- config.js (Secret key & expiration JWT. Add Role string here when adding new role.) -| | +-- db.config.js (Database and Sequelize config) -| | +-- env.js (Wrapper for env variables) -| | -| +-- controller -| | +-- *Controller.js (Add your controllers here) -| | -| +-- model -| | +-- *.model.js (Add models here and follow the name convention) -| | -| +-- router -| | +-- router.js (Routing goes here) -| | +-- verifyJwtToken.js (Middleware functions involving JWT token should go here) -| | +-- verifySignUp.js (Middleware functions involving Sign Up) -| +-- app.js -+-- .env.example (Example of .env file. Please copy this to .env and set it to your env) -``` \ No newline at end of file +7. Good luck have fun! \ No newline at end of file diff --git a/backend/app.js b/backend/app.js index 35230aacb8fa21394932c083f6d14aa10ca474be..7cd146414b9b128b1187f0671c37b16268e7c384 100644 --- a/backend/app.js +++ b/backend/app.js @@ -9,13 +9,6 @@ app.use(morgan('combined')) app.use(bodyParser.json()) app.use(cors()) -const db = require('./config/db.config.js'); -const Role = db.role; - -db.sequelize.sync().then(() => { - console.log('Syncing Database...'); -}); - var routes = require('./router/router') routes(app) diff --git a/backend/config/env.js b/backend/config/env.js deleted file mode 100644 index 8505c1ca604938c12257f078f70ab9c3ca84145a..0000000000000000000000000000000000000000 --- a/backend/config/env.js +++ /dev/null @@ -1,15 +0,0 @@ -const env = { - database: 'jabar_innov_monev_2', - username: "postgres", - password: "hue", - host: "localhost", - dialect: "postgres", - pool: { - max: 5, - min: 0, - acquire: 30000, - idle: 10000 - } - }; - - module.exports = env; \ No newline at end of file diff --git a/backend/controller/authController.js b/backend/controller/authController.js index dfc509fcc88ed66948477447cafa9b5193728c79..e9bfcb4b56c71e63e5e6fa2c2f407c18620f08cc 100644 --- a/backend/controller/authController.js +++ b/backend/controller/authController.js @@ -1,9 +1,10 @@ -const db = require('../config/db.config.js'); const config = require('../config/app.config.js'); +const models = require('../models'); +const User = models.user; +const Role = models.role; var jwt = require('jsonwebtoken'); var bcrypt = require('bcryptjs'); -const User = db.user; -const Role = db.role; + exports.signup = (req, res) => { console.log("Processing func -> signup"); diff --git a/backend/controller/testController.js b/backend/controller/testController.js index 49bf8e9859b4e1b76fb438729973088780a5e282..a1752d6cf3827e5101b180170a63279446a7ec6d 100644 --- a/backend/controller/testController.js +++ b/backend/controller/testController.js @@ -1,7 +1,7 @@ -const db = require('../config/db.config.js'); -const config = require('../config/app.config.js'); -const User = db.user; -const Role = db.role; +const models = require('../models'); +const User = models.user; +const Role = models.role; + exports.memberContent = (req, res) => { User.findOne({ diff --git a/backend/models/index.js b/backend/models/index.js index d22fdb5e903f2f4949e9758614a1a6aa9c1dfea3..c1a3d6d5dfaa489bb63d4bc54f7bcad2e67baf36 100644 --- a/backend/models/index.js +++ b/backend/models/index.js @@ -5,7 +5,7 @@ const path = require('path'); const Sequelize = require('sequelize'); const basename = path.basename(__filename); const env = process.env.NODE_ENV || 'development'; -const config = require(__dirname + '/../config/app.config.json')[env]; +const config = require(__dirname + '/../config/config.json')[env]; const db = {}; let sequelize; diff --git a/backend/models/user.js b/backend/models/user.js index 64cb4824f3d795d29950c689302be4bc9bd9b557..93a0213c96ea87f5229c267fad3f88d595e48e73 100644 --- a/backend/models/user.js +++ b/backend/models/user.js @@ -7,7 +7,7 @@ module.exports = (sequelize, DataTypes) => { username: DataTypes.STRING }, {}); user.associate = function(models) { - models.user.belongsTo(models.Role); + models.user.belongsTo(models.role); }; return user; }; \ No newline at end of file diff --git a/backend/router/verifyJwtToken.js b/backend/router/verifyJwtToken.js index 1a04e8d994402330db2460d310fdf4207b52ac2c..c2b079eb13d5558598bff119294ff26331b2358b 100644 --- a/backend/router/verifyJwtToken.js +++ b/backend/router/verifyJwtToken.js @@ -1,8 +1,7 @@ const jwt = require('jsonwebtoken'); const config = require('../config/app.config.js'); -const db = require('../config/db.config.js'); -const User = db.user; -const Role = db.role; +const models = require('../models'); +const User = models.user; verifyToken = (req, res, next) => { let token = req.headers['x-access-token']; diff --git a/backend/router/verifySignUp.js b/backend/router/verifySignUp.js index 957209f79496ebfafca4f85587fc446ad0f69179..e6727cb61a9c5ebb45f09c7b89cfc7b090af7137 100644 --- a/backend/router/verifySignUp.js +++ b/backend/router/verifySignUp.js @@ -1,7 +1,7 @@ -const db = require('../config/db.config.js'); -const config = require('../config/app.config.js'); -const ROLEs = config.ROLEs; -const User = db.user; +const models = require('../models'); +const User = models.user; +const app_config = require('../config/app.config'); +const ROLEs = app_config.ROLEs; checkDuplicateUserNameOrEmail = (req, res, next) => { User.findOne({ diff --git a/backend/test/user_test.js b/backend/test/user_test.js index d0bd5151600b96ca27f8b4e4e0f5c753ef976c36..84588a65db30406b564ffc3b19a5651f4fd7d73a 100644 --- a/backend/test/user_test.js +++ b/backend/test/user_test.js @@ -2,10 +2,8 @@ process.NODE_ENV = "test"; let chai = require('chai') let chaiHttp = require('chai-http') -let db = require('../config/db.config.js'); -let config = require('../config/app.config.js'); -let User = db.user; -let Role = db.role; +const models = require('../models'); +const User = models.user; let app = require('../app.js') let should = chai.should(); let expect = chai.expect; @@ -20,7 +18,6 @@ describe('Users', () => { }); done(); }); - describe('User Sign Up', ()=>{ it('Sign user up', (done) =>{ let user = {