diff --git a/app/routes/api.partners.channels.$id.tsx b/app/routes/api.partners.channels.$id.tsx index b1b8f82..0e135fe 100644 --- a/app/routes/api.partners.channels.$id.tsx +++ b/app/routes/api.partners.channels.$id.tsx @@ -2,6 +2,7 @@ import { json, LoaderFunctionArgs } from "@remix-run/node"; import invariant from "tiny-invariant"; import { requirePartnerApiKey } from "~/lib/utils.server"; import { db } from "~/lib/db.server"; +import { Rule, ruleDefinitions } from "~/lib/validations.server"; export async function loader({ request, params }: LoaderFunctionArgs) { await requirePartnerApiKey({ request }); @@ -45,7 +46,28 @@ export async function loader({ request, params }: LoaderFunctionArgs) { slowModeHours, excludeCohosts, excludeUsers: excludeUsernamesParsed, + membershipRequirements: filterUserRules(inclusionRuleSetParsed?.ruleParsed), inclusionRuleSet: inclusionRuleSetParsed?.ruleParsed, exclusionRuleSet: exclusionRuleSetParsed?.ruleParsed, }); } + +function filterUserRules(rule: Rule | undefined) { + if (!rule || !rule.conditions) { + return rule; + } + + const userScopedRules: Rule[] = []; + + for (const cond of rule.conditions) { + const ruleDef = ruleDefinitions[cond.name]; + if (ruleDef.checkType === "user") { + userScopedRules.push(cond); + } + } + + return { + ...rule, + conditions: userScopedRules, + }; +}