Utilisation simultanée de mongodb et mysql

This commit is contained in:
Rampeur
2025-08-14 18:22:05 +02:00
parent 49b1a3f6b3
commit 8a011af73a
40 changed files with 3003 additions and 152 deletions
+26 -18
View File
@@ -1,23 +1,31 @@
const DB = require('../database');
const { Projects } = DB;
const { Article } = DB;
module.exports = class ProjectService {
static async createProject(data) {
return Projects.create(data);
}
class ArticleService {
static async createArticle(data) {
return Article.create(data);
}
static async getProjectsByUserId(userId) {
return Projects.findAll({
where: { userId },
include: [
{
model: DB.Users,
as: 'user',
attributes: ['name', 'email'],
},
],
order: [['createdAt', 'DESC']],
});
}
static async getAllArticles() {
return Article.findAll({
order: [['createdAt', 'DESC']],
});
}
static async getArticlesByUserId(authorId) {
return Article.findAll({
where: { authorId },
include: [
{
model: DB.User,
as: 'author',
attributes: ['username', 'email'],
},
],
order: [['createdAt', 'DESC']],
});
}
}
module.exports = ArticleService;
+17
View File
@@ -0,0 +1,17 @@
const DB = require('../database');
const { Comment } = DB;
class CommentService {
static async createComment(data) {
return Comment.create(data);
}
static async getAllComments() {
return Comment.findAll({
order: [['createdAt', 'DESC']],
});
}
}
module.exports = CommentService;
+5
View File
@@ -0,0 +1,5 @@
exports.ArticleService = require('./article.service');
exports.CommentService = require('./comment.service');
exports.TagService = require('./tag.service');
exports.UserService = require('./user.service');
+19
View File
@@ -0,0 +1,19 @@
const DB = require('../database');
const { Tag } = DB;
class TagService {
static async createTag(data) {
return Tag.create(data);
}
static async getAllTags() {
return Tag.findAll({
attributes: ["name"],
order: [['createdAt', 'DESC']],
});
}
}
module.exports = TagService;
+10 -6
View File
@@ -1,21 +1,25 @@
const DB = require('../database');
const { Users } = DB;
const { User } = DB;
module.exports = class UserService {
class UserService {
static async createUser(data) {
return Users.create(data);
return User.create(data);
}
static async getAllUsers() {
return Users.findAll({
return User.findAll({
order: [['createdAt', 'DESC']],
});
}
static async getUserById(id) {
return Users.findByPk(id);
return User.findByPk(id);
}
static async getUserByEmail(email) {
return User.findOne(email);
}
}
//module.exports = userService;
module.exports = UserService;