Skip to content

Commit

Permalink
Merge pull request #75 from buildingu/chore-fix-logout
Browse files Browse the repository at this point in the history
Chore fix logout
  • Loading branch information
gbudjeakp authored Jan 19, 2025
2 parents 2e526ce + 1984b87 commit ba64d43
Show file tree
Hide file tree
Showing 15 changed files with 4,591 additions and 6,110 deletions.
930 changes: 458 additions & 472 deletions Controllers/feedbackController.js

Large diffs are not rendered by default.

556 changes: 278 additions & 278 deletions Controllers/userController.js

Large diffs are not rendered by default.

143 changes: 83 additions & 60 deletions Models/index.js
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,
};
26 changes: 26 additions & 0 deletions docker-compose.yml
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
Loading

0 comments on commit ba64d43

Please sign in to comment.