diff --git a/packages/kcms/src/team/main.ts b/packages/kcms/src/team/main.ts index 8e1ad61f..c2d026ae 100644 --- a/packages/kcms/src/team/main.ts +++ b/packages/kcms/src/team/main.ts @@ -19,6 +19,11 @@ import { TeamID } from './models/team.js'; import { apiReference } from '@scalar/hono-api-reference'; import { SnowflakeIDGenerator } from '../id/main'; +import { DummyMainMatchRepository } from '../match/adaptor/dummy/mainMatchRepository'; +import { DummyPreMatchRepository } from '../match/adaptor/dummy/preMatchRepository'; +import { PrismaMainMatchRepository } from '../match/adaptor/prisma/mainMatchRepository'; +import { PrismaPreMatchRepository } from '../match/adaptor/prisma/preMatchRepository'; +import { GetMatchService } from '../match/service/get'; import { CreateTeamService } from './service/createTeam'; import { DeleteTeamService } from './service/delete'; import { EntryService } from './service/entry'; @@ -29,12 +34,20 @@ const isProduction = process.env.NODE_ENV === 'production'; const teamRepository = isProduction ? new PrismaTeamRepository(prismaClient) : new DummyRepository(); +const preMatchRepository = isProduction + ? new PrismaPreMatchRepository(prismaClient) + : new DummyPreMatchRepository(); +const mainMatchRepository = isProduction + ? new PrismaMainMatchRepository(prismaClient) + : new DummyMainMatchRepository(); const idGenerator = new SnowflakeIDGenerator(1, () => BigInt(new Date().getTime())); +const getMatchService = new GetMatchService(preMatchRepository, mainMatchRepository); + const fetchTeamService = new FetchTeamService(teamRepository); const createTeamService = new CreateTeamService(teamRepository, idGenerator); const deleteTeamService = new DeleteTeamService(teamRepository); -const entryService = new EntryService(teamRepository); +const entryService = new EntryService(teamRepository, getMatchService); export const controller = new TeamController( createTeamService, diff --git a/packages/kcms/src/team/service/entry.ts b/packages/kcms/src/team/service/entry.ts index d5159e9a..b3ee18c2 100644 --- a/packages/kcms/src/team/service/entry.ts +++ b/packages/kcms/src/team/service/entry.ts @@ -1,4 +1,5 @@ import { Option, Result } from '@mikuroxina/mini-fn'; +import { GetMatchService } from '../../match/service/get'; import { TeamRepository } from '../models/repository'; import { Team, TeamID } from '../models/team'; @@ -6,7 +7,10 @@ import { Team, TeamID } from '../models/team'; * 当日参加を行うService */ export class EntryService { - constructor(private readonly teamRepository: TeamRepository) {} + constructor( + private readonly teamRepository: TeamRepository, + private readonly PreMatch: GetMatchService + ) {} /** * チームの出欠を登録します @@ -15,6 +19,11 @@ export class EntryService { */ async enter(teamID: TeamID): Promise> { const teamRes = await this.teamRepository.findByID(teamID); + const matchRes = await this.PreMatch.findAllPreMatch(); + + if (!Result.isErr(matchRes)) { + return Result.err(new Error('Cannot enter now')); + } if (Option.isNone(teamRes)) { return Result.err(new Error('Team not found')); } @@ -35,6 +44,11 @@ export class EntryService { */ async cancel(teamID: TeamID): Promise> { const teamRes = await this.teamRepository.findByID(teamID); + const matchRes = await this.PreMatch.findAllPreMatch(); + + if (!Result.isErr(matchRes)) { + return Result.err(new Error('Cannot enter now')); + } if (Option.isNone(teamRes)) { return Result.err(new Error('Team not found')); }