inmemory to postgres

This commit is contained in:
2025-12-29 18:34:12 +01:00
parent 9e17d0752a
commit f5639a367f
176 changed files with 10175 additions and 468 deletions

View File

@@ -0,0 +1,46 @@
import { Module } from '@nestjs/common';
import { LoggingModule } from '../../domain/logging/LoggingModule';
import type { Logger } from '@core/shared/application/Logger';
import type { IEngagementRepository } from '@core/analytics/domain/repositories/IEngagementRepository';
import type { IAnalyticsSnapshotRepository } from '@core/analytics/domain/repositories/IAnalyticsSnapshotRepository';
import type { IPageViewRepository } from '@core/analytics/application/repositories/IPageViewRepository';
import { InMemoryAnalyticsSnapshotRepository } from '@adapters/analytics/persistence/inmemory/InMemoryAnalyticsSnapshotRepository';
import { InMemoryEngagementRepository } from '@adapters/analytics/persistence/inmemory/InMemoryEngagementRepository';
import { InMemoryPageViewRepository } from '@adapters/analytics/persistence/inmemory/InMemoryPageViewRepository';
import {
ANALYTICS_ENGAGEMENT_REPOSITORY_TOKEN,
ANALYTICS_PAGE_VIEW_REPOSITORY_TOKEN,
ANALYTICS_SNAPSHOT_REPOSITORY_TOKEN,
} from '../analytics/AnalyticsPersistenceTokens';
@Module({
imports: [LoggingModule],
providers: [
{
provide: ANALYTICS_PAGE_VIEW_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IPageViewRepository => new InMemoryPageViewRepository(logger),
inject: ['Logger'],
},
{
provide: ANALYTICS_ENGAGEMENT_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IEngagementRepository => new InMemoryEngagementRepository(logger),
inject: ['Logger'],
},
{
provide: ANALYTICS_SNAPSHOT_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IAnalyticsSnapshotRepository => new InMemoryAnalyticsSnapshotRepository(logger),
inject: ['Logger'],
},
],
exports: [
ANALYTICS_PAGE_VIEW_REPOSITORY_TOKEN,
ANALYTICS_ENGAGEMENT_REPOSITORY_TOKEN,
ANALYTICS_SNAPSHOT_REPOSITORY_TOKEN,
],
})
export class InMemoryAnalyticsPersistenceModule {}

View File

@@ -0,0 +1,49 @@
import { Module } from '@nestjs/common';
import { LoggingModule } from '../../domain/logging/LoggingModule';
import type { Logger } from '@core/shared/application/Logger';
import type { IPasswordHashingService } from '@core/identity/domain/services/PasswordHashingService';
import type { StoredUser } from '@core/identity/domain/repositories/IUserRepository';
import { InMemoryAuthRepository } from '@adapters/identity/persistence/inmemory/InMemoryAuthRepository';
import { InMemoryUserRepository } from '@adapters/identity/persistence/inmemory/InMemoryUserRepository';
import { InMemoryPasswordHashingService } from '@adapters/identity/services/InMemoryPasswordHashingService';
import { AUTH_REPOSITORY_TOKEN, PASSWORD_HASHING_SERVICE_TOKEN, USER_REPOSITORY_TOKEN } from '../identity/IdentityPersistenceTokens';
@Module({
imports: [LoggingModule],
providers: [
{
provide: USER_REPOSITORY_TOKEN,
useFactory: (logger: Logger) => {
const initialUsers: StoredUser[] = [
{
// Match seeded racing driver id so dashboard works in inmemory mode.
id: 'driver-1',
email: 'admin@gridpilot.local',
passwordHash: 'demo_salt_321nimda', // InMemoryPasswordHashingService: "admin123" reversed.
displayName: 'Admin',
salt: '',
createdAt: new Date(),
},
];
return new InMemoryUserRepository(logger, initialUsers);
},
inject: ['Logger'],
},
{
provide: AUTH_REPOSITORY_TOKEN,
useFactory: (userRepository: InMemoryUserRepository, passwordHashingService: IPasswordHashingService, logger: Logger) =>
new InMemoryAuthRepository(userRepository, passwordHashingService, logger),
inject: [USER_REPOSITORY_TOKEN, PASSWORD_HASHING_SERVICE_TOKEN, 'Logger'],
},
{
provide: PASSWORD_HASHING_SERVICE_TOKEN,
useClass: InMemoryPasswordHashingService,
},
],
exports: [USER_REPOSITORY_TOKEN, AUTH_REPOSITORY_TOKEN, PASSWORD_HASHING_SERVICE_TOKEN],
})
export class InMemoryIdentityPersistenceModule {}

View File

@@ -0,0 +1,72 @@
import { Module } from '@nestjs/common';
import { LoggingModule } from '../../domain/logging/LoggingModule';
import type { Logger } from '@core/shared/application/Logger';
import type { IPaymentRepository } from '@core/payments/domain/repositories/IPaymentRepository';
import type {
IMemberPaymentRepository,
IMembershipFeeRepository,
} from '@core/payments/domain/repositories/IMembershipFeeRepository';
import type { IPrizeRepository } from '@core/payments/domain/repositories/IPrizeRepository';
import type { ITransactionRepository, IWalletRepository } from '@core/payments/domain/repositories/IWalletRepository';
import { InMemoryMembershipFeeRepository, InMemoryMemberPaymentRepository } from '@adapters/payments/persistence/inmemory/InMemoryMembershipFeeRepository';
import { InMemoryPaymentRepository } from '@adapters/payments/persistence/inmemory/InMemoryPaymentRepository';
import { InMemoryPrizeRepository } from '@adapters/payments/persistence/inmemory/InMemoryPrizeRepository';
import { InMemoryTransactionRepository, InMemoryWalletRepository } from '@adapters/payments/persistence/inmemory/InMemoryWalletRepository';
import {
PAYMENTS_MEMBER_PAYMENT_REPOSITORY_TOKEN,
PAYMENTS_MEMBERSHIP_FEE_REPOSITORY_TOKEN,
PAYMENTS_PAYMENT_REPOSITORY_TOKEN,
PAYMENTS_PRIZE_REPOSITORY_TOKEN,
PAYMENTS_TRANSACTION_REPOSITORY_TOKEN,
PAYMENTS_WALLET_REPOSITORY_TOKEN,
} from '../payments/PaymentsPersistenceTokens';
@Module({
imports: [LoggingModule],
providers: [
{
provide: PAYMENTS_PAYMENT_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IPaymentRepository => new InMemoryPaymentRepository(logger),
inject: ['Logger'],
},
{
provide: PAYMENTS_MEMBERSHIP_FEE_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IMembershipFeeRepository => new InMemoryMembershipFeeRepository(logger),
inject: ['Logger'],
},
{
provide: PAYMENTS_MEMBER_PAYMENT_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IMemberPaymentRepository => new InMemoryMemberPaymentRepository(logger),
inject: ['Logger'],
},
{
provide: PAYMENTS_PRIZE_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IPrizeRepository => new InMemoryPrizeRepository(logger),
inject: ['Logger'],
},
{
provide: PAYMENTS_WALLET_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IWalletRepository => new InMemoryWalletRepository(logger),
inject: ['Logger'],
},
{
provide: PAYMENTS_TRANSACTION_REPOSITORY_TOKEN,
useFactory: (logger: Logger): ITransactionRepository => new InMemoryTransactionRepository(logger),
inject: ['Logger'],
},
],
exports: [
PAYMENTS_PAYMENT_REPOSITORY_TOKEN,
PAYMENTS_MEMBERSHIP_FEE_REPOSITORY_TOKEN,
PAYMENTS_MEMBER_PAYMENT_REPOSITORY_TOKEN,
PAYMENTS_PRIZE_REPOSITORY_TOKEN,
PAYMENTS_WALLET_REPOSITORY_TOKEN,
PAYMENTS_TRANSACTION_REPOSITORY_TOKEN,
],
})
export class InMemoryPaymentsPersistenceModule {}

View File

@@ -12,14 +12,13 @@ import {
InMemorySocialGraphRepository,
} from '@adapters/social/persistence/inmemory/InMemorySocialAndFeed';
export const FEED_REPOSITORY_TOKEN = 'IFeedRepository';
export const SOCIAL_GRAPH_REPOSITORY_TOKEN = 'ISocialGraphRepository';
import { SOCIAL_FEED_REPOSITORY_TOKEN, SOCIAL_GRAPH_REPOSITORY_TOKEN } from '../social/SocialPersistenceTokens';
@Module({
imports: [LoggingModule],
providers: [
{
provide: FEED_REPOSITORY_TOKEN,
provide: SOCIAL_FEED_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IFeedRepository =>
new InMemoryFeedRepository(logger, { drivers: [], friendships: [], feedEvents: [] }),
inject: ['Logger'],
@@ -31,6 +30,6 @@ export const SOCIAL_GRAPH_REPOSITORY_TOKEN = 'ISocialGraphRepository';
inject: ['Logger'],
},
],
exports: [FEED_REPOSITORY_TOKEN, SOCIAL_GRAPH_REPOSITORY_TOKEN],
exports: [SOCIAL_FEED_REPOSITORY_TOKEN, SOCIAL_GRAPH_REPOSITORY_TOKEN],
})
export class InMemorySocialPersistenceModule {}