Commit 79b5cdbf authored by 任国军's avatar 任国军

back classList add filter

parent fecc68d4
Pipeline #24798 passed with stage
in 4 seconds
...@@ -71,8 +71,9 @@ class BackController extends Controller { ...@@ -71,8 +71,9 @@ class BackController extends Controller {
// 获取课程列表 // 获取课程列表
async getClassList() { async getClassList() {
const { ctx, service } = this; const { ctx, service } = this;
const queryParams = ctx.request.query;
const ret = await service.course.back.getClassList(); const ret = await service.course.back.getClassList(queryParams);
ctx.success(ret); ctx.success(ret);
} }
} }
......
...@@ -237,16 +237,23 @@ class BackService extends Service { ...@@ -237,16 +237,23 @@ class BackService extends Service {
// 获取机构和课程 // 获取机构和课程
async getClassList() { async getClassList(input) {
const { ctx } = this; const { ctx } = this;
const userUuid = ctx.userUuid; const userUuid = ctx.userUuid;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const offset = (page - 1) * limit;
const userInfo = await ctx.classModel.CourseBackUser.findOne({ where: { id: userUuid, is_deleted: 0 } }); const userInfo = await ctx.classModel.CourseBackUser.findOne({ where: { id: userUuid, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) { if (ctx.isEmpty(userInfo)) {
ctx.failed('用户异常'); ctx.failed('用户异常');
} }
const filter = userInfo.is_admin === 0 ? { where: { id: userInfo.institution_id, status: 1, is_deleted: 0 }, attributes: [ 'id', 'name' ], raw: true } : { where: { status: 1, is_deleted: 0 }, attributes: [ 'id', 'name' ] }; const filter = userInfo.is_admin === 0 ? { where: { id: userInfo.institution_id, status: 1, is_deleted: 0 }, attributes: [ 'id', 'name' ], limit, offset, raw: true } : { where: { status: 1, is_deleted: 0 }, limit, offset, attributes: [ 'id', 'name' ] };
if (!ctx.isEmpty(input.institution_name)) {
filter.where.name = { $like: `%${input.institution_name}%` };
}
const institutionList = await ctx.classModel.V5.CourseV5Institution.findAll(filter); const institutionList = await ctx.classModel.V5.CourseV5Institution.findAll(filter);
if (ctx.isEmpty(institutionList)) { if (ctx.isEmpty(institutionList)) {
return { return {
......
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