Commit bcc5732c authored by 任国军's avatar 任国军

add is_like

parent dac77dcf
Pipeline #18121 passed with stage
in 1 minute 18 seconds
...@@ -659,6 +659,9 @@ class InstitutionSubService extends Service { ...@@ -659,6 +659,9 @@ class InstitutionSubService extends Service {
const articles = await ctx.classModel.V3.CourseArticle.findAndCountAll(filter); const articles = await ctx.classModel.V3.CourseArticle.findAndCountAll(filter);
const ret = []; const ret = [];
//用户点赞列表
const userLikes = await ctx.classModel.V3.CourseLike.findAll({where: {user_uuid: ctx.userUuid, type: 1, is_deleted: 0}});
const userLikeIds = R.pluck('type_id', userLikes);
for (const v of articles.rows) { for (const v of articles.rows) {
ret.push({ ret.push({
id: v.id, id: v.id,
...@@ -672,6 +675,7 @@ class InstitutionSubService extends Service { ...@@ -672,6 +675,7 @@ class InstitutionSubService extends Service {
like_count: v.like_count, like_count: v.like_count,
read_count: v.read_count, read_count: v.read_count,
sort: v.sort, sort: v.sort,
is_like: userLikeIds.includes(v.id) ? 1 : 0,
created_time: v.created_time, created_time: v.created_time,
}); });
} }
...@@ -690,6 +694,9 @@ class InstitutionSubService extends Service { ...@@ -690,6 +694,9 @@ class InstitutionSubService extends Service {
await ctx.classModel.V3.CourseArticle.update({ read_count: sequelize.literal('`read_count` + 1') }, { where: { id } }); await ctx.classModel.V3.CourseArticle.update({ read_count: sequelize.literal('`read_count` + 1') }, { where: { id } });
//用户是否点赞
const userLike = await ctx.classModel.V3.CourseLike.findOne({where: {user_uuid: ctx.userUuid, type: 1, type_id: id, is_deleted: 0}});
const ret = { const ret = {
id: article.id, id: article.id,
type: article.type, type: article.type,
...@@ -702,6 +709,7 @@ class InstitutionSubService extends Service { ...@@ -702,6 +709,7 @@ class InstitutionSubService extends Service {
like_count: article.like_count, like_count: article.like_count,
read_count: article.read_count, read_count: article.read_count,
sort: article.sort, sort: article.sort,
is_like: ctx.isEmpty(userLike) ? 0 : 1,
created_time: article.created_time, created_time: article.created_time,
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment