Ajout de la base de données MySQL

This commit is contained in:
Rampeur
2025-08-13 21:51:07 +02:00
parent be44e4fdf0
commit 49b1a3f6b3
35 changed files with 1579 additions and 37 deletions
+23
View File
@@ -0,0 +1,23 @@
const DB = require('../database');
const { Projects } = DB;
module.exports = class ProjectService {
static async createProject(data) {
return Projects.create(data);
}
static async getProjectsByUserId(userId) {
return Projects.findAll({
where: { userId },
include: [
{
model: DB.Users,
as: 'user',
attributes: ['name', 'email'],
},
],
order: [['createdAt', 'DESC']],
});
}
}
+23
View File
@@ -0,0 +1,23 @@
const DB = require('../database');
const sequelize = require('../database/config/sequelize');
const associate = require('../database/relationships');
// Connect to the database and log a message to the console
const connectDB = async () => {
try {
await sequelize.authenticate();
console.log('Connection has been established successfully🔥');
// Synchronize the database with the models without need of dropping the tables
await DB.sequelize.sync({
force: false,
});
associate(); // Call the associate function to create the relationships between the models
} catch (error) {
console.error('Unable to connect to the database:', error);
process.exit(1); // Exit the process if the connection is not successful
}
};
module.exports = connectDB;
+21
View File
@@ -0,0 +1,21 @@
const DB = require('../database');
const { Users } = DB;
module.exports = class UserService {
static async createUser(data) {
return Users.create(data);
}
static async getAllUsers() {
return Users.findAll({
order: [['createdAt', 'DESC']],
});
}
static async getUserById(id) {
return Users.findByPk(id);
}
}
//module.exports = userService;