📦 NEW: Profil dernières citations proposées

This commit is contained in:
Divlo
2020-04-22 22:01:18 +02:00
parent 43add978b6
commit 032ef566c7
8 changed files with 84 additions and 53 deletions

View File

@ -14,6 +14,7 @@ const Favorites = require('..
const Functions = require('../models/functions');
const Categories = require('../models/categories');
const Comments = require('../models/comments');
const Quotes = require('../models/quotes');
const deleteFilesNameStartWith = require('../assets/utils/deleteFilesNameStartWith');
async function handleEditUser(res, { name, email, biography, isPublicEmail }, userId, logoName) {
@ -221,16 +222,18 @@ exports.getUserInfo = async (req, res, next) => {
where: { userId: user.id },
include: [
{ model: Functions, attributes: { exclude: ["updatedAt", "utilizationForm", "article", "isOnline"] }, include: { model: Categories, attributes: ["name", "color"] } }
]
],
order: [['createdAt', 'DESC']],
limit: 5
});
const favoritesArray = favorites.map((favorite) => favorite.function);
const comments = await Comments.findAll({
limit: 10,
where: { userId: user.id },
include: [
{ model: Functions, attributes: { exclude: ["updatedAt", "utilizationForm", "article", "isOnline"] } }
],
order: [['createdAt', 'DESC']]
order: [['createdAt', 'DESC']],
limit: 5
});
const commentsArray = comments.map((commentObject) => {
return {
@ -240,6 +243,14 @@ exports.getUserInfo = async (req, res, next) => {
function: commentObject.function.dataValues
};
});
const quotesArray = await Quotes.findAll({
where: { userId: user.id },
attributes: {
exclude: ["updatedAt", "createdAt", "isValidated", "userId", "id"]
},
order: [['createdAt', 'DESC']],
limit: 5,
});
const userObject = {
// Si Public Email
... (user.isPublicEmail) && { email: user.email },
@ -249,7 +260,8 @@ exports.getUserInfo = async (req, res, next) => {
logo: user.logo,
createdAt: user.createdAt,
favoritesArray,
commentsArray
commentsArray,
quotesArray
};
return res.status(200).json(userObject);
} catch (error) {