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:
@@ -41,7 +41,6 @@ const CompletionRequirement = require("../../models/courses/completion_requireme
|
||||
const { VALID_ENTITY_TYPES } = require("../../utils/courses/completion_requirements.registry");
|
||||
|
||||
const mdl_Users = require("../../models/users/users.mdl");
|
||||
const { mdl_PlanUnits, mdl_TierPlans } = require("../../models/tiers/tier.associations");
|
||||
|
||||
const notDeleted = { deletedAt: null };
|
||||
const onlyDeleted = { deletedAt: { [Op.not]: null } };
|
||||
@@ -192,28 +191,12 @@ exports.getUnitsBySubscription = async (req, res) => {
|
||||
const rows = await Unit.findAll({
|
||||
where: { ...notDeleted, subscription: slug },
|
||||
attributes: ['unit_id', 'title', 'description', 'subscription'],
|
||||
include: [{
|
||||
model: mdl_PlanUnits,
|
||||
as: 'planUnit',
|
||||
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 unit belongs
|
||||
// to at most one plan (UNIQUE constraint on plan_units.unit_id).
|
||||
const data = rows.map((u) => {
|
||||
const plain = u.toJSON();
|
||||
const assigned_plan = plain.planUnit?.plan ?? null;
|
||||
delete plain.planUnit;
|
||||
return { ...plain, assigned_plan };
|
||||
});
|
||||
// A unit 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((u) => u.toJSON());
|
||||
|
||||
return R.success(res, 'Units retrieved.', data);
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user