mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
tier plans improving
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -15,8 +15,11 @@ const VALID_RULE_TYPES = new Set([
|
||||
'course_subscription_access',
|
||||
'required_active_tier',
|
||||
'group_restriction',
|
||||
'item_allowlist',
|
||||
]);
|
||||
|
||||
const VALID_ITEM_TYPES = new Set(['course', 'unit', 'lesson']);
|
||||
|
||||
async function validateRules(rules) {
|
||||
if (!Array.isArray(rules)) return 'access_rules must be an array.';
|
||||
|
||||
@@ -41,6 +44,15 @@ async function validateRules(rules) {
|
||||
if (!Array.isArray(rule.group_ids))
|
||||
return 'group_restriction.group_ids must be an array.';
|
||||
}
|
||||
|
||||
if (rule.type === 'item_allowlist') {
|
||||
if (!VALID_ITEM_TYPES.has(rule.item_type))
|
||||
return `item_allowlist.item_type must be one of: ${[...VALID_ITEM_TYPES].join(', ')}.`;
|
||||
if (!Array.isArray(rule.item_ids) || !rule.item_ids.length)
|
||||
return 'item_allowlist.item_ids must be a non-empty array.';
|
||||
if (rule.item_ids.length > 3)
|
||||
return 'item_allowlist.item_ids must contain at most 3 items.';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user