feat(web): add price range filter and list view to /du-an page
Add minPrice/maxPrice inputs to ProjectFilterBar and introduce a list view mode alongside the existing grid/map toggle for project browsing. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -25,6 +25,7 @@ import { MarketIndexCronService } from './infrastructure/services/market-index-c
|
||||
import { NeighborhoodScoreServiceImpl } from './infrastructure/services/neighborhood-score.service';
|
||||
import { PrismaAVMService } from './infrastructure/services/prisma-avm.service';
|
||||
import { AnalyticsController } from './presentation/controllers/analytics.controller';
|
||||
import { AvmController } from './presentation/controllers/avm.controller';
|
||||
|
||||
const CommandHandlers = [
|
||||
TrackEventHandler,
|
||||
@@ -50,7 +51,7 @@ const EventHandlers = [
|
||||
|
||||
@Module({
|
||||
imports: [CqrsModule],
|
||||
controllers: [AnalyticsController],
|
||||
controllers: [AnalyticsController, AvmController],
|
||||
providers: [
|
||||
// AI service client
|
||||
{ provide: AI_SERVICE_CLIENT, useClass: AiServiceClient },
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import { type QueryBus } from '@nestjs/cqrs';
|
||||
import { BatchValuationQuery } from '../../application/queries/batch-valuation/batch-valuation.query';
|
||||
import { ValuationComparisonQuery } from '../../application/queries/valuation-comparison/valuation-comparison.query';
|
||||
import { ValuationHistoryQuery } from '../../application/queries/valuation-history/valuation-history.query';
|
||||
import { AvmController } from '../controllers/avm.controller';
|
||||
|
||||
describe('AvmController', () => {
|
||||
let controller: AvmController;
|
||||
let mockQueryBus: { execute: ReturnType<typeof vi.fn> };
|
||||
|
||||
beforeEach(() => {
|
||||
mockQueryBus = { execute: vi.fn() };
|
||||
controller = new AvmController(mockQueryBus as unknown as QueryBus);
|
||||
});
|
||||
|
||||
describe('POST /avm/batch', () => {
|
||||
it('dispatches BatchValuationQuery with property IDs', async () => {
|
||||
const expected = {
|
||||
results: [
|
||||
{ propertyId: 'prop-1', valuation: { estimatedPrice: '5000000000' } },
|
||||
{ propertyId: 'prop-2', valuation: { estimatedPrice: '6000000000' } },
|
||||
],
|
||||
};
|
||||
mockQueryBus.execute.mockResolvedValue(expected);
|
||||
|
||||
const result = await controller.batchValuation({
|
||||
propertyIds: ['prop-1', 'prop-2'],
|
||||
} as any);
|
||||
|
||||
expect(mockQueryBus.execute).toHaveBeenCalledWith(
|
||||
new BatchValuationQuery(['prop-1', 'prop-2']),
|
||||
);
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /avm/history/:propertyId', () => {
|
||||
it('dispatches ValuationHistoryQuery with propertyId and limit', async () => {
|
||||
const expected = { propertyId: 'prop-1', history: [], totalRecords: 0 };
|
||||
mockQueryBus.execute.mockResolvedValue(expected);
|
||||
|
||||
const result = await controller.getHistory('prop-1', { limit: 25 } as any);
|
||||
|
||||
expect(mockQueryBus.execute).toHaveBeenCalledWith(
|
||||
new ValuationHistoryQuery('prop-1', 25),
|
||||
);
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
|
||||
it('defaults limit to 50 when not provided', async () => {
|
||||
const expected = { propertyId: 'prop-1', history: [], totalRecords: 0 };
|
||||
mockQueryBus.execute.mockResolvedValue(expected);
|
||||
|
||||
const result = await controller.getHistory('prop-1', {} as any);
|
||||
|
||||
expect(mockQueryBus.execute).toHaveBeenCalledWith(
|
||||
new ValuationHistoryQuery('prop-1', 50),
|
||||
);
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /avm/compare', () => {
|
||||
it('dispatches ValuationComparisonQuery with parsed IDs', async () => {
|
||||
const expected = {
|
||||
properties: [],
|
||||
summary: { highestValue: null, lowestValue: null, averagePricePerM2: 0, averageConfidence: 0 },
|
||||
};
|
||||
mockQueryBus.execute.mockResolvedValue(expected);
|
||||
|
||||
const result = await controller.compare({
|
||||
ids: ['prop-1', 'prop-2', 'prop-3'],
|
||||
} as any);
|
||||
|
||||
expect(mockQueryBus.execute).toHaveBeenCalledWith(
|
||||
new ValuationComparisonQuery(['prop-1', 'prop-2', 'prop-3']),
|
||||
);
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
|
||||
it('handles two property IDs (minimum)', async () => {
|
||||
const expected = { properties: [], summary: {} };
|
||||
mockQueryBus.execute.mockResolvedValue(expected);
|
||||
|
||||
const result = await controller.compare({
|
||||
ids: ['prop-1', 'prop-2'],
|
||||
} as any);
|
||||
|
||||
expect(mockQueryBus.execute).toHaveBeenCalledWith(
|
||||
new ValuationComparisonQuery(['prop-1', 'prop-2']),
|
||||
);
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { type QueryBus } from '@nestjs/cqrs';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiParam, ApiQuery } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '@modules/auth';
|
||||
import { EndpointRateLimit, EndpointRateLimitGuard } from '@modules/shared';
|
||||
import { RequireQuota, QuotaGuard } from '@modules/subscriptions';
|
||||
import { type BatchValuationDto as BatchValuationResultDto } from '../../application/queries/batch-valuation/batch-valuation.handler';
|
||||
import { BatchValuationQuery } from '../../application/queries/batch-valuation/batch-valuation.query';
|
||||
import { type ValuationComparisonDto as ValuationComparisonResultDto } from '../../application/queries/valuation-comparison/valuation-comparison.handler';
|
||||
import { ValuationComparisonQuery } from '../../application/queries/valuation-comparison/valuation-comparison.query';
|
||||
import { type ValuationHistoryDto as ValuationHistoryResultDto } from '../../application/queries/valuation-history/valuation-history.handler';
|
||||
import { ValuationHistoryQuery } from '../../application/queries/valuation-history/valuation-history.query';
|
||||
import { type AvmCompareQueryDto } from '../dto/avm-compare-query.dto';
|
||||
import { type BatchValuationDto } from '../dto/batch-valuation.dto';
|
||||
import { type ValuationHistoryDto } from '../dto/valuation-history.dto';
|
||||
|
||||
@ApiTags('avm')
|
||||
@Controller('avm')
|
||||
export class AvmController {
|
||||
constructor(
|
||||
private readonly queryBus: QueryBus,
|
||||
) {}
|
||||
|
||||
@ApiBearerAuth('JWT')
|
||||
@EndpointRateLimit({ limit: 10, windowSeconds: 60, keyStrategy: 'user' })
|
||||
@UseGuards(EndpointRateLimitGuard, JwtAuthGuard, QuotaGuard)
|
||||
@RequireQuota('analytics_queries')
|
||||
@Post('batch')
|
||||
@ApiOperation({ summary: 'Batch valuation for multiple properties (max 50)' })
|
||||
@ApiResponse({ status: 200, description: 'Batch valuation results' })
|
||||
@ApiResponse({ status: 400, description: 'Invalid parameters' })
|
||||
@ApiResponse({ status: 403, description: 'Quota exceeded' })
|
||||
@ApiResponse({ status: 429, description: 'Rate limit exceeded — max 10 requests per 60s' })
|
||||
async batchValuation(@Body() dto: BatchValuationDto): Promise<BatchValuationResultDto> {
|
||||
return this.queryBus.execute(
|
||||
new BatchValuationQuery(dto.propertyIds),
|
||||
);
|
||||
}
|
||||
|
||||
@ApiBearerAuth('JWT')
|
||||
@UseGuards(JwtAuthGuard, QuotaGuard)
|
||||
@RequireQuota('analytics_queries')
|
||||
@Get('history/:propertyId')
|
||||
@ApiOperation({ summary: 'Get valuation history for a property (time-series)' })
|
||||
@ApiParam({ name: 'propertyId', description: 'Property ID', example: 'prop-123' })
|
||||
@ApiResponse({ status: 200, description: 'Valuation history time-series data' })
|
||||
@ApiResponse({ status: 403, description: 'Quota exceeded' })
|
||||
async getHistory(
|
||||
@Param('propertyId') propertyId: string,
|
||||
@Query() dto: ValuationHistoryDto,
|
||||
): Promise<ValuationHistoryResultDto> {
|
||||
return this.queryBus.execute(
|
||||
new ValuationHistoryQuery(propertyId, dto.limit ?? 50),
|
||||
);
|
||||
}
|
||||
|
||||
@ApiBearerAuth('JWT')
|
||||
@EndpointRateLimit({ limit: 10, windowSeconds: 60, keyStrategy: 'user' })
|
||||
@UseGuards(EndpointRateLimitGuard, JwtAuthGuard, QuotaGuard)
|
||||
@RequireQuota('analytics_queries')
|
||||
@Get('compare')
|
||||
@ApiOperation({ summary: 'Compare valuations for 2-5 properties side by side' })
|
||||
@ApiQuery({
|
||||
name: 'ids',
|
||||
description: 'Comma-separated property IDs (2-5)',
|
||||
example: 'prop-1,prop-2,prop-3',
|
||||
type: String,
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Normalized comparison data for UI' })
|
||||
@ApiResponse({ status: 400, description: 'Invalid parameters — provide 2-5 property IDs' })
|
||||
@ApiResponse({ status: 403, description: 'Quota exceeded' })
|
||||
@ApiResponse({ status: 429, description: 'Rate limit exceeded — max 10 requests per 60s' })
|
||||
async compare(@Query() dto: AvmCompareQueryDto): Promise<ValuationComparisonResultDto> {
|
||||
return this.queryBus.execute(
|
||||
new ValuationComparisonQuery(dto.ids),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
export { AnalyticsController } from './analytics.controller';
|
||||
export { AvmController } from './avm.controller';
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { ArrayMaxSize, ArrayMinSize, IsArray, IsString } from 'class-validator';
|
||||
|
||||
export class AvmCompareQueryDto {
|
||||
@ApiProperty({
|
||||
description: 'Comma-separated property IDs to compare (2-5)',
|
||||
example: 'prop-1,prop-2,prop-3',
|
||||
type: String,
|
||||
})
|
||||
@Transform(({ value }) =>
|
||||
typeof value === 'string' ? value.split(',').map((s: string) => s.trim()).filter(Boolean) : value,
|
||||
)
|
||||
@IsArray()
|
||||
@ArrayMinSize(2)
|
||||
@ArrayMaxSize(5)
|
||||
@IsString({ each: true })
|
||||
ids!: string[];
|
||||
}
|
||||
@@ -6,3 +6,4 @@ export { GetValuationDto } from './get-valuation.dto';
|
||||
export { BatchValuationDto } from './batch-valuation.dto';
|
||||
export { ValuationHistoryDto } from './valuation-history.dto';
|
||||
export { ValuationComparisonDto } from './valuation-comparison.dto';
|
||||
export { AvmCompareQueryDto } from './avm-compare-query.dto';
|
||||
|
||||
Reference in New Issue
Block a user