fix adapters
This commit is contained in:
@@ -213,10 +213,19 @@ export class InMemoryStandingRepository implements IStandingRepository {
|
||||
|
||||
const standingsMap = new Map<string, Standing>();
|
||||
|
||||
results.forEach(result => {
|
||||
const normalizePosition = (position: unknown): number => {
|
||||
if (typeof position === 'number') return position;
|
||||
if (typeof position === 'string') return Number(position);
|
||||
if (position && typeof (position as { toNumber?: unknown }).toNumber === 'function') {
|
||||
return (position as { toNumber: () => number }).toNumber();
|
||||
}
|
||||
return Number(position);
|
||||
};
|
||||
|
||||
results.forEach((result) => {
|
||||
const driverIdStr = result.driverId.toString();
|
||||
let standing = standingsMap.get(driverIdStr);
|
||||
|
||||
|
||||
if (!standing) {
|
||||
standing = Standing.create({
|
||||
leagueId,
|
||||
@@ -225,7 +234,8 @@ export class InMemoryStandingRepository implements IStandingRepository {
|
||||
this.logger.debug(`Created new standing for driver ${driverIdStr} in league ${leagueId}.`);
|
||||
}
|
||||
|
||||
standing = standing.addRaceResult(result.position.toNumber(), resolvedPointsSystem);
|
||||
const position = normalizePosition((result as { position: unknown }).position);
|
||||
standing = standing.addRaceResult(position, resolvedPointsSystem);
|
||||
standingsMap.set(driverIdStr, standing);
|
||||
this.logger.debug(`Driver ${driverIdStr} in league ${leagueId} accumulated ${standing.points} points.`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user