Skip to content

Commit

Permalink
Fix a bug that caused the external game deploy screen to interpret se…
Browse files Browse the repository at this point in the history
…ssion dates incorrectly.
  • Loading branch information
sei-bstein committed Nov 20, 2023
1 parent d9b58fb commit 8053ad8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
18 changes: 18 additions & 0 deletions projects/gameboard-ui/src/app/services/api-date.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
import { DateTime } from 'luxon';

@Injectable({ providedIn: 'root' })
export class ApiDateService {
toDateTime(input?: string): DateTime | null {
if (!input) return null;

// as of now, the API returns date objects as string (blargh)
const parsedDateTime = DateTime.fromISO(input);

// also, it stores null dates as 1/1/01, so account for that too
if (parsedDateTime.year == 1)
return null;

return parsedDateTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { HttpClient } from '@angular/common/http';
import { GetExternalTeamDataResponse } from '@/api/game-models';
import { ExternalGameAdminContext } from '@/admin/components/external-game-admin/external-game-admin.component';
import { DateTime } from 'luxon';
import { ApiDateService } from './api-date.service';

export interface ExternalGameActive {
gameServerUrl: string;
Expand All @@ -21,6 +22,7 @@ export class ExternalGameService {
errors$ = this._errors$.asObservable();

constructor(
private apiDateService: ApiDateService,
private apiUrl: ApiUrlService,
private config: ConfigService,
private httpClient: HttpClient,
Expand Down Expand Up @@ -66,10 +68,9 @@ export class ExternalGameService {

public getAdminContext(gameId: string): Observable<ExternalGameAdminContext> {
return this.httpClient.get<ExternalGameAdminContext>(this.apiUrl.build(`/admin/games/external/${gameId}`)).pipe(
// fix dates to be date objects and not dumb strings
map(ctx => {
ctx.startTime = !!ctx.startTime ? DateTime.fromISO(ctx.startTime!.toString()) : undefined;
ctx.endTime = !!ctx.endTime ? DateTime.fromISO(ctx.endTime!.toString()) : undefined;
ctx.startTime = this.apiDateService.toDateTime(ctx.startTime?.toString()) || undefined;
ctx.endTime = this.apiDateService.toDateTime(ctx.endTime?.toString()) || undefined;

return ctx;
})
Expand Down

0 comments on commit 8053ad8

Please sign in to comment.