feat(listings+projects): wire listing PATCH + project rich content parity
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 10s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 2s
Security Scanning / Trivy Scan — API Image (push) Failing after 28s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Deploy / Rollback Staging (push) Has been skipped
Deploy / Rollback Production (push) Has been skipped
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 37s
Deploy / Build API Image (push) Failing after 12s
Deploy / Build Web Image (push) Failing after 10s
Deploy / Build AI Services Image (push) Failing after 9s
E2E Tests / Playwright E2E (push) Failing after 9s
Security Scanning / Trivy Scan — Web Image (push) Failing after 38s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 38s
Security Scanning / Trivy Filesystem Scan (push) Failing after 28s
Deploy / Deploy to Production (push) Has been skipped
Security Scanning / Security Gate (push) Failing after 1s

Two CRUD/parity gaps closed:

Listings edit — PATCH was dead-ended at the frontend
----------------------------------------------------
Backend PATCH /listings/:id existed and accepted Phase B fields but
the dashboard edit page was read-only with a disclaimer stub. Now:
- listings-api.ts exports UpdateListingPayload (Partial<CreatePayload>)
  and listingsApi.update(id, data).
- /listings/[id]/edit/page.tsx wires handleSubmit → maps the form to
  UpdateListingPayload (coerces numerics, splits CSV amenities/view/
  suitableFor, normalises petFriendly 3-way select), calls update,
  shows green success banner or red error banner. Removed the
  disclaimer text.
- Form footer now has Huỷ + Lưu thay đổi buttons.

Projects rich content — parity with Phase B listings
---------------------------------------------------
Same "Phù hợp với ai / Vì sao nên chọn dự án này" pattern now on
project detail.

Schema
- ProjectDevelopment: suitableFor String[] @default([]) +
  whyThisLocation String? @db.Text. Migration 20260419100000 applied
  via db:push.

Backend
- CreateProjectDto / UpdateProjectDto pick up optional suitableFor +
  whyThisLocation (MaxLength 2000).
- CreateProjectCommand / UpdateProjectCommand append the two trailing
  args; handlers forward them.
- ProjectDevelopment entity carries the props + updateDetails
  branches.
- ProjectListItem (inherited by ProjectDetailData) exposes both.
- Prisma repo writes them on raw INSERT/UPDATE and reads them in
  toDomain + toListItem. Controller passes dto → commands.

Frontend
- du-an-api.ts: ProjectDetail / CreateProjectPayload /
  UpdateProjectPayload gain suitableFor + whyThisLocation. duAnApi
  exports create / update / delete (already landed earlier, now in
  sync with the new fields).
- du-an-server.ts normalizer pulls the two fields safely (filter
  strings, default empty array / null).
- Dashboard /projects/new + /projects/[id]/edit: new "Phù hợp & lý
  do khu vực" form section (CSV split + 2000-char textarea). Submit
  handlers forward to create/update payloads.
- Public /du-an/[slug] detail (du-an-detail-client.tsx): two new
  cards just below the quick-stats grid —
  * ProjectPersonaFitCard: chips for each suitableFor label with a
    "Chủ đầu tư chọn" badge (bg-primary/10), plus a disabled
    <Button><Sparkles /> AI nhận định dự án (sắp ra mắt)</Button>
    teaser with a TODO pointing to a future project-AI advisor
    endpoint.
  * ProjectWhyLocationCard: renders whyThisLocation in
    whitespace-pre-wrap; skipped when the field is empty.

Verification
- API typecheck clean; 1975/1975 tests pass.
- Web typecheck clean in touched files; 624/624 tests pass.
- Lucide-only icons; Vietnamese labels; no new npm packages;
  runtime imports preserved for NestJS-DI classes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-04-19 16:33:54 +07:00
parent 631e1200a1
commit 6b783c357d
20 changed files with 379 additions and 31 deletions

View File

@@ -27,5 +27,7 @@ export class CreateProjectCommand {
public readonly tags: string[],
public readonly startDate: Date | null,
public readonly completionDate: Date | null,
public readonly suitableFor: string[] = [],
public readonly whyThisLocation: string | null = null,
) {}
}

View File

@@ -54,6 +54,8 @@ export class CreateProjectHandler implements ICommandHandler<CreateProjectComman
media: null,
documents: null,
tags: cmd.tags,
suitableFor: cmd.suitableFor ?? [],
whyThisLocation: cmd.whyThisLocation ?? null,
isVerified: false,
},
now,

View File

@@ -25,5 +25,7 @@ export class UpdateProjectCommand {
public readonly isVerified?: boolean,
public readonly startDate?: Date | null,
public readonly completionDate?: Date | null,
public readonly suitableFor?: string[],
public readonly whyThisLocation?: string | null,
) {}
}

View File

@@ -40,6 +40,8 @@ export class UpdateProjectHandler implements ICommandHandler<UpdateProjectComman
...(cmd.media !== undefined && { media: cmd.media }),
...(cmd.documents !== undefined && { documents: cmd.documents }),
...(cmd.tags !== undefined && { tags: cmd.tags }),
...(cmd.suitableFor !== undefined && { suitableFor: cmd.suitableFor }),
...(cmd.whyThisLocation !== undefined && { whyThisLocation: cmd.whyThisLocation }),
...(cmd.isVerified !== undefined && { isVerified: cmd.isVerified }),
...(cmd.startDate !== undefined && { startDate: cmd.startDate }),
...(cmd.completionDate !== undefined && { completionDate: cmd.completionDate }),

View File

@@ -30,6 +30,8 @@ export interface ProjectDevelopmentProps {
media: Record<string, unknown>[] | null;
documents: Record<string, unknown>[] | null;
tags: string[];
suitableFor: string[];
whyThisLocation: string | null;
isVerified: boolean;
}
@@ -62,6 +64,8 @@ export class ProjectDevelopmentEntity extends AggregateRoot<string> {
private _media: Record<string, unknown>[] | null;
private _documents: Record<string, unknown>[] | null;
private _tags: string[];
private _suitableFor: string[];
private _whyThisLocation: string | null;
private _isVerified: boolean;
constructor(id: string, props: ProjectDevelopmentProps, createdAt: Date, updatedAt: Date) {
@@ -94,6 +98,8 @@ export class ProjectDevelopmentEntity extends AggregateRoot<string> {
this._media = props.media;
this._documents = props.documents;
this._tags = props.tags;
this._suitableFor = props.suitableFor;
this._whyThisLocation = props.whyThisLocation;
this._isVerified = props.isVerified;
}
@@ -125,6 +131,8 @@ export class ProjectDevelopmentEntity extends AggregateRoot<string> {
get media() { return this._media; }
get documents() { return this._documents; }
get tags() { return this._tags; }
get suitableFor() { return this._suitableFor; }
get whyThisLocation() { return this._whyThisLocation; }
get isVerified() { return this._isVerified; }
updateDetails(props: Partial<ProjectDevelopmentProps>): void {
@@ -149,6 +157,8 @@ export class ProjectDevelopmentEntity extends AggregateRoot<string> {
if (props.media !== undefined) this._media = props.media;
if (props.documents !== undefined) this._documents = props.documents;
if (props.tags !== undefined) this._tags = props.tags;
if (props.suitableFor !== undefined) this._suitableFor = props.suitableFor;
if (props.whyThisLocation !== undefined) this._whyThisLocation = props.whyThisLocation;
if (props.isVerified !== undefined) this._isVerified = props.isVerified;
this.updatedAt = new Date();
}

View File

@@ -39,6 +39,8 @@ export interface ProjectListItem {
maxPrice: bigint | null;
totalArea: number | null;
tags: string[];
suitableFor: string[];
whyThisLocation: string | null;
isVerified: boolean;
latitude: number;
longitude: number;

View File

@@ -68,7 +68,7 @@ export class PrismaProjectDevelopmentRepository implements IProjectRepository {
location, address, ward, district, city,
"minPrice", "maxPrice", "pricePerM2Range", "totalArea",
"buildingCount", "floorCount", "unitTypes", media, documents,
tags, "isVerified", "createdAt", "updatedAt"
tags, "suitableFor", "whyThisLocation", "isVerified", "createdAt", "updatedAt"
) VALUES (
${entity.id}, ${entity.name}, ${entity.slug}, ${entity.developer},
${entity.developerLogo}, ${entity.totalUnits}, ${entity.completedUnits},
@@ -86,6 +86,8 @@ export class PrismaProjectDevelopmentRepository implements IProjectRepository {
${entity.media ? JSON.stringify(entity.media) : null}::jsonb,
${entity.documents ? JSON.stringify(entity.documents) : null}::jsonb,
${entity.tags}::text[],
${entity.suitableFor}::text[],
${entity.whyThisLocation},
${entity.isVerified}, ${entity.createdAt}, ${entity.updatedAt}
)
`;
@@ -114,6 +116,8 @@ export class PrismaProjectDevelopmentRepository implements IProjectRepository {
media = ${entity.media ? JSON.stringify(entity.media) : null}::jsonb,
documents = ${entity.documents ? JSON.stringify(entity.documents) : null}::jsonb,
tags = ${entity.tags}::text[],
"suitableFor" = ${entity.suitableFor}::text[],
"whyThisLocation" = ${entity.whyThisLocation},
"isVerified" = ${entity.isVerified},
"updatedAt" = ${entity.updatedAt}
WHERE id = ${entity.id}
@@ -216,6 +220,8 @@ export class PrismaProjectDevelopmentRepository implements IProjectRepository {
media: row.media as Record<string, unknown>[] | null,
documents: row.documents as Record<string, unknown>[] | null,
tags: row.tags ?? [],
suitableFor: row.suitableFor ?? [],
whyThisLocation: row.whyThisLocation,
isVerified: row.isVerified,
},
row.createdAt,
@@ -241,6 +247,8 @@ export class PrismaProjectDevelopmentRepository implements IProjectRepository {
maxPrice: row.maxPrice,
totalArea: row.totalArea,
tags: row.tags ?? [],
suitableFor: row.suitableFor ?? [],
whyThisLocation: row.whyThisLocation,
isVerified: row.isVerified,
latitude: Number(row.lat),
longitude: Number(row.lng),
@@ -298,6 +306,8 @@ interface RawProject {
media: Prisma.JsonValue;
documents: Prisma.JsonValue;
tags: string[] | null;
suitableFor: string[] | null;
whyThisLocation: string | null;
isVerified: boolean;
createdAt: Date;
updatedAt: Date;

View File

@@ -131,6 +131,8 @@ export class ProjectsController {
dto.tags ?? [],
dto.startDate ? new Date(dto.startDate) : null,
dto.completionDate ? new Date(dto.completionDate) : null,
dto.suitableFor ?? [],
dto.whyThisLocation ?? null,
),
);
}
@@ -170,6 +172,8 @@ export class ProjectsController {
dto.isVerified,
dto.startDate !== undefined ? (dto.startDate ? new Date(dto.startDate) : null) : undefined,
dto.completionDate !== undefined ? (dto.completionDate ? new Date(dto.completionDate) : null) : undefined,
dto.suitableFor,
dto.whyThisLocation,
),
);
}

View File

@@ -134,6 +134,24 @@ export class CreateProjectDto {
@IsString({ each: true })
tags?: string[];
@ApiPropertyOptional({
example: ['Gia đình trẻ', 'Chuyên gia nước ngoài'],
description: 'Các nhóm khách phù hợp với dự án',
})
@IsOptional()
@IsArray()
@IsString({ each: true })
suitableFor?: string[];
@ApiPropertyOptional({
description: 'Mô tả ngắn vì sao khu vực này phù hợp',
maxLength: 2000,
})
@IsOptional()
@IsString()
@MaxLength(2000)
whyThisLocation?: string;
@ApiPropertyOptional({ example: '2020-06-01', description: 'Ngày khởi công' })
@IsOptional()
@IsDateString()

View File

@@ -10,6 +10,7 @@ import {
IsObject,
IsBoolean,
Min,
MaxLength,
IsDateString,
} from 'class-validator';
@@ -44,6 +45,13 @@ export class UpdateProjectDto {
@ApiPropertyOptional() @IsOptional() @IsArray() media?: Record<string, unknown>[] | null;
@ApiPropertyOptional() @IsOptional() @IsArray() documents?: Record<string, unknown>[] | null;
@ApiPropertyOptional() @IsOptional() @IsArray() @IsString({ each: true }) tags?: string[];
@ApiPropertyOptional({ description: 'Các nhóm khách phù hợp với dự án' })
@IsOptional() @IsArray() @IsString({ each: true }) suitableFor?: string[];
@ApiPropertyOptional({ description: 'Mô tả ngắn vì sao khu vực này phù hợp', maxLength: 2000 })
@IsOptional() @IsString() @MaxLength(2000) whyThisLocation?: string | null;
@ApiPropertyOptional() @IsOptional() @IsBoolean() isVerified?: boolean;
@ApiPropertyOptional() @IsOptional() @IsDateString() startDate?: string | null;
@ApiPropertyOptional() @IsOptional() @IsDateString() completionDate?: string | null;