Skip to content

Commit

Permalink
Validate optimizer tiers
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Oct 20, 2024
1 parent 3d294bd commit 70b3776
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api/routes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,27 @@ export function validateLoadout(metricPrefix: string, loadout: Loadout, appId: s
message: 'Item ID is invalid',
};
}
for (const constraint of loadout.parameters?.statConstraints ?? []) {
for (const tier of [constraint.minTier, constraint.maxTier]) {
if (tier === undefined) {
continue;
}
if (!Number.isInteger(tier)) {
metrics.increment(`${metricPrefix}.validation.tierValueNotInteger.count`);
return {
status: 'InvalidArgument',
message: 'Loadout Optimizer stat tiers must be integers, not ${tier}',
};
}
if (tier < 0 || tier > 10) {
metrics.increment(`${metricPrefix}.validation.tierValueOutOfRange.count`);
return {
status: 'InvalidArgument',
message: 'Loadout Optimizer stat tiers must be between 0 and 10',
};
}
}
}

return undefined;
}
Expand Down

0 comments on commit 70b3776

Please sign in to comment.