-
Notifications
You must be signed in to change notification settings - Fork 5
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 #75 from buildingu/chore-fix-logout
Chore fix logout
- Loading branch information
Showing
15 changed files
with
4,591 additions
and
6,110 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,60 +1,83 @@ | ||
const dbConfig = require("../config/db.config")["development"]; | ||
const { Sequelize, DataTypes } = require("sequelize"); | ||
|
||
const sequelize = new Sequelize(dbConfig.db, dbConfig.user, dbConfig.password, { | ||
host: dbConfig.host, | ||
dialect: "mysql", | ||
port: dbConfig.port, | ||
}); | ||
|
||
const User = require("./User")(sequelize, DataTypes); | ||
const FeedbackRequest = require("./Feedbackrequest")(sequelize, DataTypes); | ||
const Feedbacks = require("./Feedbacks")(sequelize, DataTypes); | ||
const Otptoken = require("./Otptoken")(sequelize, DataTypes); | ||
const ExerciseInfo = require("./ExerciseInfo")(sequelize, DataTypes); | ||
|
||
|
||
//This was poorly desgined. Should spent more time fixing this | ||
User.hasMany(FeedbackRequest, { foreignKey: "userId" }); | ||
FeedbackRequest.belongsTo(User, { foreignKey: "userId" }); | ||
|
||
FeedbackRequest.belongsTo(User, { as: "mentor", foreignKey: "mentorId" }); | ||
User.hasMany(FeedbackRequest, { | ||
as: "mentoredRequests", | ||
foreignKey: "mentorId", | ||
}); | ||
|
||
FeedbackRequest.hasMany(Feedbacks, { foreignKey: "feedbackRequestId" }); | ||
Feedbacks.belongsTo(FeedbackRequest, { foreignKey: "feedbackRequestId" }); | ||
User.hasMany(Feedbacks, { foreignKey: 'userId' }); | ||
ExerciseInfo.belongsTo(User, { foreignKey: "userId" }); | ||
User.hasMany(ExerciseInfo, { foreignKey: "userId" }); | ||
|
||
async function syncDatabase() { | ||
try { | ||
await sequelize.sync({}); | ||
console.log("Database synchronized."); | ||
} catch (error) { | ||
console.error("Error syncing database:", error); | ||
} | ||
} | ||
|
||
(async () => { | ||
try { | ||
await sequelize.authenticate(); | ||
console.log("Connection has been established successfully."); | ||
syncDatabase(); | ||
} catch (error) { | ||
console.error("Unable to connect to the database:", error); | ||
} | ||
})(); | ||
|
||
// Export models | ||
module.exports = { | ||
sequelize, | ||
User, | ||
FeedbackRequest, | ||
Feedbacks, | ||
Otptoken, | ||
ExerciseInfo, | ||
}; | ||
const dbConfig = require("../config/db.config")["development"]; | ||
const { Sequelize, DataTypes } = require("sequelize"); | ||
|
||
const sequelize = new Sequelize(dbConfig.db, dbConfig.user, dbConfig.password, { | ||
host: dbConfig.host, | ||
dialect: "mysql", | ||
port: dbConfig.port, | ||
}); | ||
|
||
const User = require("./User")(sequelize, DataTypes); | ||
const FeedbackRequest = require("./Feedbackrequest")(sequelize, DataTypes); | ||
const Feedbacks = require("./Feedbacks")(sequelize, DataTypes); | ||
const Otptoken = require("./Otptoken")(sequelize, DataTypes); | ||
const ExerciseInfo = require("./ExerciseInfo")(sequelize, DataTypes); | ||
|
||
|
||
//This was poorly desgined. Should spent more time fixing this | ||
User.hasMany(FeedbackRequest, { foreignKey: "userId" }); | ||
FeedbackRequest.belongsTo(User, { foreignKey: "userId" }); | ||
|
||
FeedbackRequest.belongsTo(User, { as: "mentor", foreignKey: "mentorId" }); | ||
User.hasMany(FeedbackRequest, { | ||
as: "mentoredRequests", | ||
foreignKey: "mentorId", | ||
}); | ||
|
||
FeedbackRequest.hasMany(Feedbacks, { foreignKey: "feedbackRequestId" }); | ||
Feedbacks.belongsTo(FeedbackRequest, { foreignKey: "feedbackRequestId" }); | ||
User.hasMany(Feedbacks, { foreignKey: 'userId' }); | ||
ExerciseInfo.belongsTo(User, { foreignKey: "userId" }); | ||
User.hasMany(ExerciseInfo, { foreignKey: "userId" }); | ||
|
||
async function syncDatabase() { | ||
try { | ||
await sequelize.sync({}); | ||
console.log("Database synchronized."); | ||
} catch (error) { | ||
console.error("Error syncing database:", error); | ||
} | ||
} | ||
|
||
async function ensureDatabaseExists() { | ||
try { | ||
const dbName = process.env.DB_NAME; | ||
|
||
const [results] = await sequelize.query(`SHOW DATABASES LIKE '${dbName}'`); | ||
|
||
if (results.length === 0) { | ||
// Database doesn't exist, so create it | ||
await sequelize.query(`CREATE DATABASE ${dbName}`); | ||
console.log(`Database '${dbName}' created successfully.`); | ||
} else { | ||
console.log(`Database '${dbName}' already exists.`); | ||
} | ||
} catch (error) { | ||
console.error('Error ensuring database existence:', error); | ||
} finally { | ||
await sequelize.close(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
(async () => { | ||
try { | ||
await sequelize.authenticate(); | ||
console.log("Connection has been established successfully."); | ||
syncDatabase(); | ||
} catch (error) { | ||
console.error("Unable to connect to the database:", error); | ||
} | ||
})(); | ||
|
||
// Export models | ||
module.exports = { | ||
sequelize, | ||
User, | ||
FeedbackRequest, | ||
Feedbacks, | ||
Otptoken, | ||
ExerciseInfo, | ||
}; |
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 @@ | ||
services: | ||
mariadb: | ||
image: mariadb:10.4.32 | ||
container_name: local-mariadb | ||
ports: | ||
- "3306:3306" | ||
environment: | ||
MYSQL_ALLOW_EMPTY_PASSWORD: "yes" # No password | ||
volumes: | ||
- mariadb_data:/var/lib/mysql | ||
|
||
redis-stack: | ||
image: redis/redis-stack:latest | ||
container_name: redis-stack | ||
ports: | ||
- "6380:6379" | ||
|
||
redis-stack-server: | ||
image: redis/redis-stack-server:latest | ||
container_name: redis-stack-server | ||
ports: | ||
- "6379:6379" | ||
|
||
volumes: | ||
mariadb_data: | ||
driver: local |
Oops, something went wrong.