Commit 49b9429e authored by 任国军's avatar 任国军

add studentWorks

parent 3d38437b
Pipeline #21640 passed with stage
in 3 seconds
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5StudentWorks = app.classModel.define('course_v5_student_works', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
class_id: INTEGER,
video_url: STRING,
cover_image: STRING,
description: STRING,
sub_title: STRING,
status: INTEGER,
is_deleted: INTEGER,
sort: INTEGER,
created_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_v5_student_works',
});
return CourseV5StudentWorks;
};
......@@ -87,6 +87,9 @@ class InstitutionSubService extends Service {
// 机构数据
const institution = await ctx.classModel.V5.CourseV5Institution.findOne({ where: { id: classInfo.institution_id } });
// 学员成果
const studentWorks = await ctx.classModel.V5.CourseV5StudentWorks.findAll({ where: { class_id: id, status: 1, is_deleted: 0 }, order: [[ 'sort', 'asc' ]], attributes: [ 'id', 'name', 'sub_title', 'description', 'video_url', 'cover_image' ] });
const columns = [];
for (const v of classColumns) {
if (!ctx.isEmpty(columnList[v.column_id])) {
......@@ -103,6 +106,7 @@ class InstitutionSubService extends Service {
}
classInfo.columns = columns;
classInfo.student_works = studentWorks;
classInfo.institution_name = ctx.isEmpty(institution) ? '' : institution.name;
classInfo.institution_description = ctx.isEmpty(institution) ? '' : institution.description;
......@@ -110,15 +114,30 @@ class InstitutionSubService extends Service {
}
// 用户收藏课程列表
async getUserCollectedClasses(input) {
async getUserCollectedClassList(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const page = Number(input.page) || 1;
const page_size = Number(input.page_size) || 10;
const offset = (page - 1) * page_size;
const attributes = [ 'id', 'institution_id', 'name', 'logo', 'age', 'price', 'price_type', 'mode', 'time', 'class_amount', 'multi_classes', 'cycle', 'description', 'sort' ];
const filter = { where: { status: 1, is_deleted: 0 }, order: [[ 'sort', 'asc' ], [ 'id', 'desc' ]], page_size, offset, attributes };
const userCollection = await ctx.classModel.V5.CourseUserCollection.findAll({ where: { user_uuid: userUuid, is_deleted: 0, type: 2 }, raw: true });
const classIds = R.pluck('type_id', userCollection);
input.classIds = classIds;
const ret = await this.getClasses(input);
const classList = await ctx.classModel.V5.CourseV5Class.findAndCountAll(filter);
// 用户收藏的课程
const userCollection = await ctx.classModel.V5.CourseUserCollection.findAll({ where: { user_uuid: ctx.userUuid, is_deleted: 0, type: 3 }, raw: true });
const collectedIds = R.pluck('type_id', userCollection);
for (const i in classList.rows) {
classList.rows[i].is_collected = collectedIds.includes(classList.rows[i].id) ? 1 : 0;
}
const ret = {
list: classList.rows,
total_count: classList.count,
page,
page_size,
};
return ret;
}
......
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