Files
goodgo-platform/apps/api/src/modules/search/search.module.ts
Ho Ngoc Hai 2502aa69b7 fix: production readiness — resolve build, lint, and code quality issues
- Fix Next.js build failure: remove duplicate route at (dashboard)/listings/[id]
  that conflicted with (public)/listings/[id] (same URL path in two route groups)
- Fix 772 ESLint errors: auto-fix import ordering (import-x/order), remove unused
  imports/variables, convert empty interfaces to type aliases, replace require()
  with ESM imports, fix consistent-type-imports violations
- Add CLAUDE.md for developer onboarding documentation
- All checks pass: 0 lint errors, typecheck clean, 230 tests passing, build success

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-08 07:15:06 +07:00

56 lines
2.3 KiB
TypeScript

import { Module, type OnModuleInit } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { type LoggerService } from '@modules/shared/infrastructure/logger.service';
import { ReindexAllHandler } from './application/commands/reindex-all/reindex-all.handler';
import { SyncListingHandler } from './application/commands/sync-listing/sync-listing.handler';
import { GeoSearchHandler } from './application/queries/geo-search/geo-search.handler';
import { SearchPropertiesHandler } from './application/queries/search-properties/search-properties.handler';
import { SEARCH_REPOSITORY } from './domain/repositories/search.repository';
import { ListingApprovedEventHandler } from './infrastructure/event-handlers/listing-approved.handler';
import { ListingIndexerService } from './infrastructure/services/listing-indexer.service';
import { TypesenseClientService } from './infrastructure/services/typesense-client.service';
import { TypesenseSearchRepository } from './infrastructure/services/typesense-search.repository';
import { SearchController } from './presentation/controllers/search.controller';
const CommandHandlers = [SyncListingHandler, ReindexAllHandler];
const QueryHandlers = [SearchPropertiesHandler, GeoSearchHandler];
@Module({
imports: [CqrsModule],
controllers: [SearchController],
providers: [
// Infrastructure
TypesenseClientService,
TypesenseSearchRepository,
{ provide: SEARCH_REPOSITORY, useExisting: TypesenseSearchRepository },
ListingIndexerService,
// Event handlers
ListingApprovedEventHandler,
// CQRS
...CommandHandlers,
...QueryHandlers,
],
exports: [ListingIndexerService, SEARCH_REPOSITORY, TypesenseClientService],
})
export class SearchModule implements OnModuleInit {
constructor(
private readonly typesenseClient: TypesenseClientService,
private readonly searchRepo: TypesenseSearchRepository,
private readonly logger: LoggerService,
) {}
async onModuleInit(): Promise<void> {
try {
await this.searchRepo.ensureCollection();
this.logger.log('Search module initialized — Typesense collection ready', 'SearchModule');
} catch (err) {
this.logger.error(
`Failed to initialize Typesense collection: ${err instanceof Error ? err.message : String(err)}`,
'SearchModule',
);
}
}
}