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:
@@ -37,7 +37,6 @@ const {
|
||||
} = require("../../models/courses/courses.associations");
|
||||
|
||||
const mdl_Users = require("../../models/users/users.mdl");
|
||||
const { mdl_PlanLessons, mdl_TierPlans } = require("../../models/tiers/tier.associations");
|
||||
|
||||
const notDeleted = { deletedAt: null };
|
||||
const onlyDeleted = { deletedAt: { [Op.not]: null } };
|
||||
@@ -189,28 +188,12 @@ exports.getLessonsBySubscription = async (req, res) => {
|
||||
const rows = await Lesson.findAll({
|
||||
where: { ...notDeleted, subscription: slug },
|
||||
attributes: ['lesson_id', 'title', 'description', 'subscription'],
|
||||
include: [{
|
||||
model: mdl_PlanLessons,
|
||||
as: 'planLesson',
|
||||
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 lesson
|
||||
// belongs to at most one plan (UNIQUE constraint on plan_lessons.lesson_id).
|
||||
const data = rows.map((l) => {
|
||||
const plain = l.toJSON();
|
||||
const assigned_plan = plain.planLesson?.plan ?? null;
|
||||
delete plain.planLesson;
|
||||
return { ...plain, assigned_plan };
|
||||
});
|
||||
// A lesson 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((l) => l.toJSON());
|
||||
|
||||
return R.success(res, 'Lessons retrieved.', data);
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user