Skip to content

Commit 034ff8e

Browse files
committed
Fix results page rankings
1 parent 5b0a3dc commit 034ff8e

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

features/results/game-results.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { GameCategory, PageVersion } from "@prisma/client";
33
import db from "../../infra/db.js";
44
import { materializeGamePage } from "../games/page.helpers.js";
55
import {
6-
ODA_GAME_CATEGORY,
76
OVERALL_RATING_CATEGORY_NAME,
87
REGULAR_GAME_CATEGORY,
8+
isAllowedJamRater,
99
} from "../games/policies.js";
1010

1111
type ResultCategory = {
@@ -49,6 +49,25 @@ function ratingBelongsToResultVersion(
4949
: ratingVersion === version;
5050
}
5151

52+
function isAllowedResultRater(
53+
rating: {
54+
user: {
55+
teams: Array<{
56+
game: {
57+
published: boolean;
58+
jamId?: number | null;
59+
category?: GameCategory | null;
60+
} | null;
61+
}>;
62+
};
63+
},
64+
jamId: number,
65+
) {
66+
return rating.user.teams.some((team) => {
67+
return isAllowedJamRater(team.game, jamId);
68+
});
69+
}
70+
5271
function gameSortCategoryName(sort?: string) {
5372
switch (sort) {
5473
case "GAMEPLAY":
@@ -210,6 +229,8 @@ export async function loadGameResults({
210229
game: {
211230
select: {
212231
published: true,
232+
jamId: true,
233+
category: true,
213234
},
214235
},
215236
},
@@ -268,7 +289,7 @@ export async function loadGameResults({
268289
const categoryRatings = filteredRatings.filter(
269290
(rating) =>
270291
rating.categoryId === ratingCategory.id &&
271-
rating.user.teams.filter((team) => team.game?.published).length > 0,
292+
isAllowedResultRater(rating, game.jamId),
272293
);
273294

274295
const averageScore =

0 commit comments

Comments
 (0)