Skip to content

Commit 9251f08

Browse files
committed
WIP
1 parent 86867df commit 9251f08

33 files changed

Lines changed: 485 additions & 97 deletions

File tree

.claude/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Read(//Users/ian/Code/combat-command-components/src/components/Wizard/**)",
5+
"Read(//Users/ian/Code/combat-command-components/**)",
6+
"Bash(npm run lint:*)"
7+
],
8+
"additionalDirectories": [
9+
"/Users/ian/Code/combat-command-components/src/components/Wizard"
10+
]
11+
}
12+
}

convex/_generated/api.d.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import type * as _model_common_tournamentPairingConfig from "../_model/common/to
4242
import type * as _model_common_tournamentStatus from "../_model/common/tournamentStatus.js";
4343
import type * as _model_common_types from "../_model/common/types.js";
4444
import type * as _model_files_index from "../_model/files/index.js";
45+
import type * as _model_files_queries_getFileMetadata from "../_model/files/queries/getFileMetadata.js";
4546
import type * as _model_files_queries_getFileUrl from "../_model/files/queries/getFileUrl.js";
4647
import type * as _model_friendships__helpers_deepenFriendship from "../_model/friendships/_helpers/deepenFriendship.js";
4748
import type * as _model_friendships_index from "../_model/friendships/index.js";
@@ -81,8 +82,10 @@ import type * as _model_leagues_queries_getLeagues from "../_model/leagues/queri
8182
import type * as _model_leagues_table from "../_model/leagues/table.js";
8283
import type * as _model_leagues_types from "../_model/leagues/types.js";
8384
import type * as _model_lists__helpers_deepenList from "../_model/lists/_helpers/deepenList.js";
85+
import type * as _model_lists_actions_extractListData from "../_model/lists/actions/extractListData.js";
86+
import type * as _model_lists_actions_importList from "../_model/lists/actions/importList.js";
8487
import type * as _model_lists_index from "../_model/lists/index.js";
85-
import type * as _model_lists_mutations_importListData from "../_model/lists/mutations/importListData.js";
88+
import type * as _model_lists_mutations_createList from "../_model/lists/mutations/createList.js";
8689
import type * as _model_lists_queries_getList from "../_model/lists/queries/getList.js";
8790
import type * as _model_lists_table from "../_model/lists/table.js";
8891
import type * as _model_matchResultComments__helpers_deepenMatchResultComment from "../_model/matchResultComments/_helpers/deepenMatchResultComment.js";
@@ -132,6 +135,7 @@ import type * as _model_tournamentCompetitors_mutations_createTournamentCompetit
132135
import type * as _model_tournamentCompetitors_mutations_deleteTournamentCompetitor from "../_model/tournamentCompetitors/mutations/deleteTournamentCompetitor.js";
133136
import type * as _model_tournamentCompetitors_mutations_toggleTournamentCompetitorActive from "../_model/tournamentCompetitors/mutations/toggleTournamentCompetitorActive.js";
134137
import type * as _model_tournamentCompetitors_mutations_updateTournamentCompetitor from "../_model/tournamentCompetitors/mutations/updateTournamentCompetitor.js";
138+
import type * as _model_tournamentCompetitors_queries_getAvailableTournamentCompetitorActions from "../_model/tournamentCompetitors/queries/getAvailableTournamentCompetitorActions.js";
135139
import type * as _model_tournamentCompetitors_queries_getTournamentCompetitor from "../_model/tournamentCompetitors/queries/getTournamentCompetitor.js";
136140
import type * as _model_tournamentCompetitors_queries_getTournamentCompetitors from "../_model/tournamentCompetitors/queries/getTournamentCompetitors.js";
137141
import type * as _model_tournamentCompetitors_queries_getTournamentCompetitorsByTournament from "../_model/tournamentCompetitors/queries/getTournamentCompetitorsByTournament.js";
@@ -356,6 +360,7 @@ declare const fullApi: ApiFromModules<{
356360
"_model/common/tournamentStatus": typeof _model_common_tournamentStatus;
357361
"_model/common/types": typeof _model_common_types;
358362
"_model/files/index": typeof _model_files_index;
363+
"_model/files/queries/getFileMetadata": typeof _model_files_queries_getFileMetadata;
359364
"_model/files/queries/getFileUrl": typeof _model_files_queries_getFileUrl;
360365
"_model/friendships/_helpers/deepenFriendship": typeof _model_friendships__helpers_deepenFriendship;
361366
"_model/friendships/index": typeof _model_friendships_index;
@@ -395,8 +400,10 @@ declare const fullApi: ApiFromModules<{
395400
"_model/leagues/table": typeof _model_leagues_table;
396401
"_model/leagues/types": typeof _model_leagues_types;
397402
"_model/lists/_helpers/deepenList": typeof _model_lists__helpers_deepenList;
403+
"_model/lists/actions/extractListData": typeof _model_lists_actions_extractListData;
404+
"_model/lists/actions/importList": typeof _model_lists_actions_importList;
398405
"_model/lists/index": typeof _model_lists_index;
399-
"_model/lists/mutations/importListData": typeof _model_lists_mutations_importListData;
406+
"_model/lists/mutations/createList": typeof _model_lists_mutations_createList;
400407
"_model/lists/queries/getList": typeof _model_lists_queries_getList;
401408
"_model/lists/table": typeof _model_lists_table;
402409
"_model/matchResultComments/_helpers/deepenMatchResultComment": typeof _model_matchResultComments__helpers_deepenMatchResultComment;
@@ -446,6 +453,7 @@ declare const fullApi: ApiFromModules<{
446453
"_model/tournamentCompetitors/mutations/deleteTournamentCompetitor": typeof _model_tournamentCompetitors_mutations_deleteTournamentCompetitor;
447454
"_model/tournamentCompetitors/mutations/toggleTournamentCompetitorActive": typeof _model_tournamentCompetitors_mutations_toggleTournamentCompetitorActive;
448455
"_model/tournamentCompetitors/mutations/updateTournamentCompetitor": typeof _model_tournamentCompetitors_mutations_updateTournamentCompetitor;
456+
"_model/tournamentCompetitors/queries/getAvailableTournamentCompetitorActions": typeof _model_tournamentCompetitors_queries_getAvailableTournamentCompetitorActions;
449457
"_model/tournamentCompetitors/queries/getTournamentCompetitor": typeof _model_tournamentCompetitors_queries_getTournamentCompetitor;
450458
"_model/tournamentCompetitors/queries/getTournamentCompetitors": typeof _model_tournamentCompetitors_queries_getTournamentCompetitors;
451459
"_model/tournamentCompetitors/queries/getTournamentCompetitorsByTournament": typeof _model_tournamentCompetitors_queries_getTournamentCompetitorsByTournament;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { GenericDatabaseReader } from 'convex/server';
2+
import { ConvexError, GenericId } from 'convex/values';
3+
4+
import {
5+
DataModel,
6+
Doc,
7+
TableNames,
8+
} from '../../../_generated/dataModel';
9+
10+
/**
11+
* Fetches a document by ID, throwing a `ConvexError` if it doesn't exist.
12+
*
13+
* @param ctx - A context object with a database reader.
14+
* @param id - The ID of the document to fetch.
15+
* @returns The document.
16+
* @throws {ConvexError} If no document exists with the given ID.
17+
*/
18+
export const getDocStrict = async <T extends TableNames>(
19+
ctx: { db: GenericDatabaseReader<DataModel> },
20+
id: GenericId<T>,
21+
): Promise<Doc<T>> => {
22+
const doc = await ctx.db.get(id);
23+
if (!doc) {
24+
throw new ConvexError({ message: `Document not found: ${id}`, code: 'DOCUMENT_NOT_FOUND' });
25+
}
26+
return doc;
27+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { GenericDoc } from '@convex-dev/auth/server';
2+
import { SystemDataModel } from 'convex/server';
3+
import {
4+
ConvexError,
5+
Infer,
6+
v,
7+
} from 'convex/values';
8+
9+
import { QueryCtx } from '../../../_generated/server';
10+
import { getErrorMessage } from '../../common/errors';
11+
12+
export const getFileMetadataArgs = v.object({
13+
id: v.id('_storage'),
14+
});
15+
16+
export const getFileMetadata = async (
17+
ctx: QueryCtx,
18+
args: Infer<typeof getFileMetadataArgs>,
19+
): Promise<GenericDoc<SystemDataModel,'_storage'> | null> => {
20+
const fileMetadata = await ctx.db.system.get(args.id);
21+
if (!fileMetadata) {
22+
throw new ConvexError(getErrorMessage('FILE_NOT_FOUND'));
23+
}
24+
return fileMetadata;
25+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { getAuthUserId } from '@convex-dev/auth/server';
2+
3+
import { Doc } from '../../../_generated/dataModel';
4+
import { QueryCtx } from '../../../_generated/server';
5+
import { getDocStrict } from '../../common/_helpers/getDocStrict';
6+
import { checkUsersAreTeammates } from '../../tournamentCompetitors/_helpers/checkUsersAreTeammates';
7+
import { checkUserIsTournamentOrganizer } from '../../tournamentOrganizers';
8+
9+
export const checkListVisibility = async (
10+
ctx: QueryCtx,
11+
doc: Doc<'lists'>,
12+
): Promise<boolean> => {
13+
const userId = await getAuthUserId(ctx);
14+
const tournamentRegistration = await getDocStrict(ctx, doc.tournamentRegistrationId);
15+
const tournament = await getDocStrict(ctx, tournamentRegistration.tournamentId);
16+
const isOrganizer = await checkUserIsTournamentOrganizer(ctx, tournament._id, userId);
17+
const isTeammate = await checkUsersAreTeammates(ctx, tournamentRegistration.userId, userId);
18+
19+
if (isOrganizer || isTeammate || tournament.listsRevealed) {
20+
return true;
21+
}
22+
23+
return false;
24+
};

convex/_model/lists/_helpers/deepenList.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { GameSystem } from '@ianpaschal/combat-command-game-systems/common';
2-
import { ConvexError } from 'convex/values';
1+
/* eslint-disable arrow-body-style */
2+
// import { GameSystem } from '@ianpaschal/combat-command-game-systems/common';
3+
// import { ConvexError } from 'convex/values';
34

45
import { Doc } from '../../../_generated/dataModel';
56
import { QueryCtx } from '../../../_generated/server';
6-
import { getErrorMessage } from '../../common/errors';
7-
import { FlamesOfWarV4 } from '../../gameSystems';
7+
// import { getErrorMessage } from '../../common/errors';
8+
// import { FlamesOfWarV4 } from '../../gameSystems';
89

910
/* eslint-disable @typescript-eslint/explicit-function-return-type */
1011
/**
@@ -19,19 +20,26 @@ import { FlamesOfWarV4 } from '../../gameSystems';
1920
*/
2021
export const deepenList = async (
2122
ctx: QueryCtx,
22-
list: Doc<'lists'>,
23+
doc: Doc<'lists'>,
2324
) => {
24-
// TODO-250: Add Team Yankee support here.
25-
if (list.gameSystem === GameSystem.FlamesOfWarV4) {
26-
return {
27-
...list,
28-
data: FlamesOfWarV4.deepenListData(list.data),
29-
};
30-
}
31-
32-
// If no matcher found, throw an error:
33-
throw new ConvexError(getErrorMessage('CANNOT_ADD_ANOTHER_PLAYER'));
25+
// // TODO-250: Add Team Yankee support here.
26+
// if (list.gameSystem === GameSystem.FlamesOfWarV4) {
27+
// return {
28+
// ...list,
29+
// data: FlamesOfWarV4.deepenListData(list.data),
30+
// };
31+
// }
32+
33+
// if (list.gameSystem === GameSystem.TeamYankeeV2) {
34+
// return {
35+
// ...list,
36+
// data: TeamYankeeV2.deepenListData(list.data),
37+
// };
38+
// }
3439

40+
// // If no matcher found, throw an error:
41+
// throw new ConvexError(getErrorMessage('CANNOT_ADD_ANOTHER_PLAYER'));
42+
return doc;
3543
};
3644

3745
/**

convex/_model/gameSystems/battlefront/flamesOfWarV4/_helpers/deepenListData.ts renamed to convex/_model/lists/gameSystems/battlefront/flamesOfWarV4/_helpers/deepenListData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { factions, forceDiagrams } from '@ianpaschal/combat-command-game-systems/flamesOfWarV4';
22

3-
import { Doc } from '../../../../../_generated/dataModel';
3+
import { Doc } from '../../../../../../_generated/dataModel';
44

55
export type DeepFowV4ListData = ReturnType<typeof deepenListData>;
66

convex/_model/gameSystems/battlefront/flamesOfWarV4/_model/listData.ts renamed to convex/_model/lists/gameSystems/battlefront/flamesOfWarV4/_model/listData.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { ForceDiagram, Unit } from '@ianpaschal/combat-command-game-systems/flamesOfWarV4';
22
import { Infer, v } from 'convex/values';
33

4-
import { getStaticEnumConvexValidator } from '../../../../common/_helpers/getStaticEnumConvexValidator';
4+
import { getStaticEnumConvexValidator } from '../../../../../common/_helpers/getStaticEnumConvexValidator';
55

66
const forceDiagram = getStaticEnumConvexValidator(ForceDiagram);
77
const unit = getStaticEnumConvexValidator(Unit);
88

99
export const listData = v.object({
10-
tournamentRegistrationId: v.optional(v.id('tournamentRegistrations')),
1110
meta: v.object({
1211
forceDiagram,
1312
pointsLimit: v.number(),

convex/_model/gameSystems/battlefront/flamesOfWarV4/index.ts renamed to convex/_model/lists/gameSystems/battlefront/flamesOfWarV4/index.ts

File renamed without changes.

0 commit comments

Comments
 (0)