Skip to content

Commit

Permalink
Merge ba18f4e into 2b7043b
Browse files Browse the repository at this point in the history
  • Loading branch information
jean luc tuyishime committed Aug 3, 2019
2 parents 2b7043b + ba18f4e commit e29f086
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/controllers/ReadingStatController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class ReadingStat {
});

return res.status(status.OK).json({
saveStat
message: saveStat
});
}

Expand Down
1 change: 1 addition & 0 deletions src/models/readingstat.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = (sequelize, DataTypes) => {
});
ReadingStat.belongsTo(models.Article, {
foreignKey: 'articleSlug',
targetKey: 'slug',
as: 'article'
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/queries/comments/getAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const getAll = async (data = {}) => dbFindAll(db.Comment, data, null, null, [
{
model: db.User,
attributes: ['firstName', 'lastName', 'username', 'email', 'image'],
as: 'commentAuthor',
as: 'commentAuthor'
}
]);

Expand Down
6 changes: 5 additions & 1 deletion src/queries/readingStats/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import db from '../../models';
*/
export default async (data) => {
let stats = [];
stats = await db.ReadingStat.create(data, { logging: false });
stats = await db.ReadingStat.findOrCreate({
where: data,
defaults: 1,
logging: false
});
return stats;
};
5 changes: 5 additions & 0 deletions src/queries/readingStats/getAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default async (condition = {}) => db.ReadingStat.findAndCountAll({
attributes: {
exclude: ['createdAt', 'updatedAt']
}
},
{
model: db.Article,
as: 'article',
attributes: ['id', 'title', 'description', 'coverUrl', 'readTime']
}
],
order: [['createdAt', 'DESC']]
Expand Down

0 comments on commit e29f086

Please sign in to comment.