inmemory to postgres
This commit is contained in:
@@ -3,9 +3,13 @@ import { League } from '@core/racing/domain/entities/League';
|
||||
import { Race } from '@core/racing/domain/entities/Race';
|
||||
import type { FeedItem } from '@core/social/domain/types/FeedItem';
|
||||
import type { Friendship } from './RacingSeed';
|
||||
import { seedId } from './SeedIdHelper';
|
||||
|
||||
export class RacingFeedFactory {
|
||||
constructor(private readonly baseDate: Date) {}
|
||||
constructor(
|
||||
private readonly baseDate: Date,
|
||||
private readonly persistence: 'postgres' | 'inmemory' = 'inmemory',
|
||||
) {}
|
||||
|
||||
create(drivers: Driver[], friendships: Friendship[], races: Race[], leagues: League[]): FeedItem[] {
|
||||
const items: FeedItem[] = [];
|
||||
@@ -18,13 +22,13 @@ export class RacingFeedFactory {
|
||||
const now = this.addMinutes(this.baseDate, 10);
|
||||
|
||||
for (let i = 2; i <= 10; i++) {
|
||||
const actor = drivers.find((d) => d.id === `driver-${i}`);
|
||||
const actor = drivers.find((d) => d.id === seedId(`driver-${i}`, this.persistence));
|
||||
if (!actor) continue;
|
||||
|
||||
if (!friendMap.has(`driver-1:${actor.id}`)) continue;
|
||||
|
||||
items.push({
|
||||
id: `feed:${actor.id}:joined:${i}`,
|
||||
id: seedId(`feed:${actor.id}:joined:${i}`, this.persistence),
|
||||
type: 'friend-joined-league',
|
||||
timestamp: this.addMinutes(now, -(i * 7)),
|
||||
actorDriverId: actor.id,
|
||||
@@ -38,7 +42,7 @@ export class RacingFeedFactory {
|
||||
|
||||
if (completedRace) {
|
||||
items.push({
|
||||
id: `feed:${actor.id}:result:${i}`,
|
||||
id: seedId(`feed:${actor.id}:result:${i}`, this.persistence),
|
||||
type: 'friend-finished-race',
|
||||
timestamp: this.addMinutes(now, -(i * 7 + 3)),
|
||||
actorDriverId: actor.id,
|
||||
@@ -56,7 +60,7 @@ export class RacingFeedFactory {
|
||||
|
||||
if (upcomingRace) {
|
||||
items.push({
|
||||
id: `feed:system:scheduled:${upcomingRace.id}`,
|
||||
id: seedId(`feed:system:scheduled:${upcomingRace.id}`, this.persistence),
|
||||
type: 'new-race-scheduled',
|
||||
timestamp: this.addMinutes(now, -3),
|
||||
leagueId: upcomingRace.leagueId,
|
||||
|
||||
Reference in New Issue
Block a user