authentication authorization
This commit is contained in:
@@ -14,7 +14,7 @@ import type { IResultRepository } from '../../domain/repositories/IResultReposit
|
||||
|
||||
export type GetRaceDetailInput = {
|
||||
raceId: string;
|
||||
driverId: string;
|
||||
driverId?: string;
|
||||
};
|
||||
|
||||
// Backwards-compatible alias for older callers
|
||||
@@ -60,7 +60,7 @@ export class GetRaceDetailUseCase {
|
||||
const [league, registrations, membership] = await Promise.all([
|
||||
this.leagueRepository.findById(race.leagueId),
|
||||
this.raceRegistrationRepository.findByRaceId(race.id),
|
||||
this.leagueMembershipRepository.getMembership(race.leagueId, driverId),
|
||||
driverId ? this.leagueMembershipRepository.getMembership(race.leagueId, driverId) : Promise.resolve(null),
|
||||
]);
|
||||
|
||||
const drivers = await Promise.all(
|
||||
@@ -69,14 +69,20 @@ export class GetRaceDetailUseCase {
|
||||
|
||||
const validDrivers = drivers.filter((driver): driver is NonNullable<typeof driver> => driver !== null);
|
||||
|
||||
const isUserRegistered = registrations.some(reg => reg.driverId.toString() === driverId);
|
||||
const isUserRegistered =
|
||||
typeof driverId === 'string' && driverId.length > 0
|
||||
? registrations.some(reg => reg.driverId.toString() === driverId)
|
||||
: false;
|
||||
|
||||
const isUpcoming = race.status === 'scheduled' && race.scheduledAt > new Date();
|
||||
const canRegister =
|
||||
!!membership && membership.status.toString() === 'active' && isUpcoming;
|
||||
typeof driverId === 'string' && driverId.length > 0
|
||||
? !!membership && membership.status.toString() === 'active' && isUpcoming
|
||||
: false;
|
||||
|
||||
let userResult: RaceResult | null = null;
|
||||
|
||||
if (race.status === 'completed') {
|
||||
if (race.status === 'completed' && typeof driverId === 'string' && driverId.length > 0) {
|
||||
const results = await this.resultRepository.findByRaceId(race.id);
|
||||
userResult = results.find(r => r.driverId.toString() === driverId) ?? null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user