Mise à jour et ajout de controllers, routes, services et utilities

This commit is contained in:
2025-11-30 17:54:01 +01:00
parent bcf107cd1f
commit 9355431730
36 changed files with 978 additions and 842 deletions
+12 -2
View File
@@ -63,7 +63,10 @@ const ArticleModel = () => {
);
Article.beforeValidate((article) => {
article.slug = slug(`${article.title}`) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
if (!article.slug) {
//article.slug = slug(`${article.title}`) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
article.slug = slug(`${article.title}`);
}
});
Article.prototype.toJSONFor = function () {
@@ -72,7 +75,14 @@ const ArticleModel = () => {
slug: this.slug,
title: this.title,
description: this.description,
body: this.body
body: this.body,
favorited: this.dataValues.favorited,
favoritesCount: this.dataValues.favoritesCount,
tagList: this.dataValues.tagList,
articleTags: this.dataValues.articleTags,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.dataValues.author
};
};
-65
View File
@@ -1,65 +0,0 @@
var DataTypes = require("sequelize").DataTypes;
var _Article = require("./Article");
var _ArticleTag = require("./ArticleTag");
var _Comment = require("./Comment");
var _Favorite = require("./Favorite");
var _Follower = require("./Follower");
var _Tag = require("./Tag");
var _TagList = require("./TagList");
var _User = require("./User");
function initModels(sequelize) {
var Article = _Article(sequelize, DataTypes);
var ArticleTag = _ArticleTag(sequelize, DataTypes);
var Comment = _Comment(sequelize, DataTypes);
var Favorite = _Favorite(sequelize, DataTypes);
var Follower = _Follower(sequelize, DataTypes);
var Tag = _Tag(sequelize, DataTypes);
var TagList = _TagList(sequelize, DataTypes);
var User = _User(sequelize, DataTypes);
Article.belongsToMany(Tag, { as: 'tagNameTags', through: ArticleTag, foreignKey: "articleId", otherKey: "tagName" });
Article.belongsToMany(Tag, { as: 'tagNameTagTagLists', through: TagList, foreignKey: "articleId", otherKey: "tagName" });
Article.belongsToMany(User, { as: 'userIdUsers', through: Favorite, foreignKey: "articleId", otherKey: "userId" });
Tag.belongsToMany(Article, { as: 'articleIdArticles', through: ArticleTag, foreignKey: "tagName", otherKey: "articleId" });
Tag.belongsToMany(Article, { as: 'articleIdArticleTagLists', through: TagList, foreignKey: "tagName", otherKey: "articleId" });
User.belongsToMany(Article, { as: 'articleIdArticleFavorites', through: Favorite, foreignKey: "userId", otherKey: "articleId" });
User.belongsToMany(User, { as: 'followerIdUsers', through: Follower, foreignKey: "userId", otherKey: "followerId" });
User.belongsToMany(User, { as: 'userIdUserFollowers', through: Follower, foreignKey: "followerId", otherKey: "userId" });
ArticleTag.belongsTo(Article, { as: "article", foreignKey: "articleId"});
Article.hasMany(ArticleTag, { as: "articleTags", foreignKey: "articleId"});
Comment.belongsTo(Article, { as: "article", foreignKey: "articleId"});
Article.hasMany(Comment, { as: "comments", foreignKey: "articleId"});
Favorite.belongsTo(Article, { as: "article", foreignKey: "articleId"});
Article.hasMany(Favorite, { as: "favorites", foreignKey: "articleId"});
TagList.belongsTo(Article, { as: "article", foreignKey: "articleId"});
Article.hasMany(TagList, { as: "tagLists", foreignKey: "articleId"});
ArticleTag.belongsTo(Tag, { as: "tagNameTag", foreignKey: "tagName"});
Tag.hasMany(ArticleTag, { as: "articleTags", foreignKey: "tagName"});
TagList.belongsTo(Tag, { as: "tagNameTag", foreignKey: "tagName"});
Tag.hasMany(TagList, { as: "tagLists", foreignKey: "tagName"});
Article.belongsTo(User, { as: "author", foreignKey: "authorId"});
User.hasMany(Article, { as: "articles", foreignKey: "authorId"});
Comment.belongsTo(User, { as: "author", foreignKey: "authorId"});
User.hasMany(Comment, { as: "comments", foreignKey: "authorId"});
Favorite.belongsTo(User, { as: "user", foreignKey: "userId"});
User.hasMany(Favorite, { as: "favorites", foreignKey: "userId"});
Follower.belongsTo(User, { as: "user", foreignKey: "userId"});
User.hasMany(Follower, { as: "followers", foreignKey: "userId"});
Follower.belongsTo(User, { as: "follower", foreignKey: "followerId"});
User.hasMany(Follower, { as: "followerFollowers", foreignKey: "followerId"});
return {
Article,
ArticleTag,
Comment,
Favorite,
Follower,
Tag,
TagList,
User
};
}
module.exports = initModels;
module.exports.initModels = initModels;
module.exports.default = initModels;