Refactoring et ajout de routes Hero Wars
This commit is contained in:
+10
-6
@@ -1,29 +1,33 @@
|
||||
const appendTagList = (articleTags, article) => {
|
||||
const tagList = articleTags.map((tag) => tag.name);
|
||||
const tagList = articleTags.map((tag) => tag.tagName);
|
||||
|
||||
if (!article) return tagList;
|
||||
delete article.dataValues.tagLists;
|
||||
delete article.dataValues.tagLists; //articleTags
|
||||
article.dataValues.tagList = tagList;
|
||||
};
|
||||
|
||||
const appendFavorites = async (loggedUser, article) => {
|
||||
const favorited = await article.hasUser(loggedUser ? loggedUser : null);
|
||||
console.log("article: ", article);
|
||||
//const favorited = await article.hasUser(loggedUser ? loggedUser : null);
|
||||
const favorited = await article.hasUserIdUsers(loggedUser ? loggedUser : null);
|
||||
article.dataValues.favorited = loggedUser ? favorited : false;
|
||||
|
||||
const favoritesCount = await article.countUsers();
|
||||
//const favoritesCount = await article.countUsers();
|
||||
const favoritesCount = await article.countFavorites();
|
||||
article.dataValues.favoritesCount = favoritesCount;
|
||||
};
|
||||
|
||||
const appendFollowers = async (loggedUser, toAppend) => {
|
||||
if (toAppend?.author) {
|
||||
const author = await toAppend.getAuthor();
|
||||
const following = await author.hasFollower(loggedUser ? loggedUser : null);
|
||||
//const following = await author.hasFollower(loggedUser ? loggedUser : null);
|
||||
const following = await author.hasFollowerIdUsers(loggedUser ? loggedUser : null);
|
||||
toAppend.author.dataValues.following = loggedUser ? following : false;
|
||||
|
||||
const followersCount = await author.countFollowers();
|
||||
toAppend.author.dataValues.followersCount = followersCount;
|
||||
} else {
|
||||
const following = await toAppend.hasFollower(
|
||||
const following = await toAppend.hasFollowerIdUsers(
|
||||
loggedUser ? loggedUser : null
|
||||
);
|
||||
toAppend.dataValues.following = loggedUser ? following : false;
|
||||
|
||||
Reference in New Issue
Block a user