mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
client and some admin new
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -36,8 +36,6 @@ const {
|
||||
|
||||
const mdl_Users = require("../../models/users/users.mdl");
|
||||
|
||||
const { mdl_PlanCourses, mdl_TierPlans } = require("../../models/tiers/tier.associations");
|
||||
|
||||
const {
|
||||
excludeAttributes: courseExclude,
|
||||
computedAttributes: courseComputed,
|
||||
@@ -2403,28 +2401,12 @@ exports.getCoursesBySubscription = async (req, res) => {
|
||||
const rows = await Course.findAll({
|
||||
where: { ...notDeleted, subscription: slug },
|
||||
attributes: ['course_id', 'title', 'description', 'subscription'],
|
||||
include: [{
|
||||
model: mdl_PlanCourses,
|
||||
as: 'planCourse',
|
||||
required: false,
|
||||
attributes: ['plan_id'],
|
||||
include: [{
|
||||
model: mdl_TierPlans,
|
||||
as: 'plan',
|
||||
attributes: ['plan_id', 'label'],
|
||||
}],
|
||||
}],
|
||||
order: [['title', 'ASC']],
|
||||
});
|
||||
|
||||
// Flatten so the frontend can just check `assigned_plan` — a course belongs
|
||||
// to at most one plan (UNIQUE constraint on plan_courses.course_id).
|
||||
const data = rows.map((c) => {
|
||||
const plain = c.toJSON();
|
||||
const assigned_plan = plain.planCourse?.plan ?? null;
|
||||
delete plain.planCourse;
|
||||
return { ...plain, assigned_plan };
|
||||
});
|
||||
// A course may belong to any number of other plans (Tier Plans v2, silent
|
||||
// duplication across bundles is intentional) — no conflict to report here.
|
||||
const data = rows.map((c) => c.toJSON());
|
||||
|
||||
return R.success(res, 'Courses retrieved.', data);
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user