Skip to content

Commit

Permalink
partner id
Browse files Browse the repository at this point in the history
  • Loading branch information
jtgi committed Sep 20, 2024
1 parent 66055c5 commit 4a65a9f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/routes/api.partners.channels.$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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,
};
}

0 comments on commit 4a65a9f

Please sign in to comment.