Skip to content

Commit

Permalink
chore(history): return more details in history object
Browse files Browse the repository at this point in the history
[Finishes #165786011]
  • Loading branch information
Dsalz committed May 3, 2019
1 parent 00f2174 commit c9cbd5f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions server/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../utils';
import { ValidateUser } from '../middlewares';

const { User, History, Article, Follower } = db;
const { User, History, Article, Follower, Tag } = db;

/**
* @description Controller to authenticate users
Expand Down Expand Up @@ -335,21 +335,25 @@ export default class Users {
bio: body.bio || user.bio,
image: body.image || user.image,
username: body.username || user.username,
firstname: body.firstname || user.firstname,
lastname: body.lastname || user.lastnamename,
};

const updateUser = await User.update(values, {
returning: true,
where: { username }
});
const { email, bio, image } = updateUser[1][0];
const { email, bio, image, firstname, lastname } = updateUser[1][0];

response(res).success({
message: 'user updated',
user: {
username: updatingUsername ? body.username : username,
email,
bio,
image
image,
firstname,
lastname
}
});
} catch (err) {
Expand Down Expand Up @@ -394,7 +398,7 @@ export default class Users {
try {
const userHistory = await History.findAll({
where: { userId: req.user.id },
include: [{ model: Article, attributes: ['title', 'slug'] }]
include: [{ model: Article, attributes: ['title', 'slug'], include: [{ model: Tag, attributes: ['name'] }, { model: User, attributes: ['firstname', 'lastname', 'username'] }] }]
});
response(res).success({
history: userHistory
Expand Down

0 comments on commit c9cbd5f

Please sign in to comment.