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>
270 lines
7.0 KiB
TypeScript
270 lines
7.0 KiB
TypeScript
import { apiClient } from './api-client';
|
|
import type { ListingDetail } from './listings-api';
|
|
|
|
// ─── Enums ───────────────────────────────────────────────
|
|
|
|
// Must match the Prisma enum `ProjectDevelopmentStatus` in
|
|
// `prisma/schema.prisma` — the backend rejects any other value.
|
|
export type ProjectStatus =
|
|
| 'PLANNING'
|
|
| 'UNDER_CONSTRUCTION'
|
|
| 'HANDOVER'
|
|
| 'COMPLETED';
|
|
|
|
export type ProjectPropertyType =
|
|
| 'APARTMENT'
|
|
| 'VILLA'
|
|
| 'TOWNHOUSE'
|
|
| 'SHOPHOUSE'
|
|
| 'LAND'
|
|
| 'MIXED';
|
|
|
|
// ─── Interfaces ──────────────────────────────────────────
|
|
|
|
export interface ProjectMedia {
|
|
id: string;
|
|
url: string;
|
|
type: 'image' | 'video' | 'master_plan' | 'document';
|
|
order: number;
|
|
caption: string | null;
|
|
}
|
|
|
|
export interface ProjectBlock {
|
|
id: string;
|
|
name: string;
|
|
totalUnits: number;
|
|
availableUnits: number;
|
|
floors: number;
|
|
}
|
|
|
|
export interface ProjectAmenity {
|
|
id: string;
|
|
name: string;
|
|
icon: string;
|
|
category: string;
|
|
}
|
|
|
|
export interface ProjectPriceRange {
|
|
propertyType: ProjectPropertyType;
|
|
minPrice: string;
|
|
maxPrice: string;
|
|
pricePerM2Min: number | null;
|
|
pricePerM2Max: number | null;
|
|
}
|
|
|
|
export interface ProjectPriceHistory {
|
|
period: string;
|
|
avgPricePerM2: number;
|
|
transactionCount: number;
|
|
}
|
|
|
|
export interface NeighborhoodScore {
|
|
category: string;
|
|
score: number;
|
|
label: string;
|
|
}
|
|
|
|
export interface ProjectPOI {
|
|
id: string;
|
|
name: string;
|
|
type: string;
|
|
distance: number;
|
|
latitude: number;
|
|
longitude: number;
|
|
}
|
|
|
|
export interface ProjectDeveloper {
|
|
id: string;
|
|
name: string;
|
|
logoUrl: string | null;
|
|
totalProjects: number;
|
|
}
|
|
|
|
export interface ProjectDocument {
|
|
id: string;
|
|
name: string;
|
|
url: string;
|
|
type: string;
|
|
sizeBytes: number;
|
|
}
|
|
|
|
export interface ProjectSummary {
|
|
id: string;
|
|
slug: string;
|
|
name: string;
|
|
status: ProjectStatus;
|
|
developer: ProjectDeveloper;
|
|
city: string;
|
|
district: string;
|
|
address: string;
|
|
latitude: number | null;
|
|
longitude: number | null;
|
|
thumbnailUrl: string | null;
|
|
totalArea: number;
|
|
totalUnits: number;
|
|
propertyTypes: ProjectPropertyType[];
|
|
minPrice: string | null;
|
|
maxPrice: string | null;
|
|
completionDate: string | null;
|
|
createdAt: string;
|
|
}
|
|
|
|
export interface ProjectDetail extends ProjectSummary {
|
|
description: string;
|
|
media: ProjectMedia[];
|
|
blocks: ProjectBlock[];
|
|
amenities: ProjectAmenity[];
|
|
priceRanges: ProjectPriceRange[];
|
|
priceHistory: ProjectPriceHistory[];
|
|
neighborhoodScores: NeighborhoodScore[];
|
|
pois: ProjectPOI[];
|
|
documents: ProjectDocument[];
|
|
linkedListingCount: number;
|
|
suitableFor?: string[];
|
|
whyThisLocation?: string | null;
|
|
}
|
|
|
|
export interface PaginatedResult<T> {
|
|
data: T[];
|
|
total: number;
|
|
page: number;
|
|
limit: number;
|
|
totalPages: number;
|
|
}
|
|
|
|
export interface CreateProjectPayload {
|
|
name: string;
|
|
slug: string;
|
|
developer: string;
|
|
developerLogo?: string;
|
|
totalUnits: number;
|
|
status: string;
|
|
latitude: number;
|
|
longitude: number;
|
|
address: string;
|
|
ward: string;
|
|
district: string;
|
|
city: string;
|
|
description?: string;
|
|
amenities?: Record<string, unknown>;
|
|
masterPlanUrl?: string;
|
|
minPrice?: string;
|
|
maxPrice?: string;
|
|
pricePerM2Range?: Record<string, unknown>;
|
|
totalArea?: number;
|
|
buildingCount?: number;
|
|
floorCount?: number;
|
|
unitTypes?: Record<string, unknown>;
|
|
tags?: string[];
|
|
suitableFor?: string[];
|
|
whyThisLocation?: string;
|
|
startDate?: string;
|
|
completionDate?: string;
|
|
}
|
|
|
|
export interface UpdateProjectPayload {
|
|
name?: string;
|
|
developer?: string;
|
|
developerLogo?: string | null;
|
|
totalUnits?: number;
|
|
completedUnits?: number;
|
|
status?: string;
|
|
description?: string | null;
|
|
amenities?: Record<string, unknown> | null;
|
|
masterPlanUrl?: string | null;
|
|
minPrice?: string | null;
|
|
maxPrice?: string | null;
|
|
pricePerM2Range?: Record<string, unknown> | null;
|
|
totalArea?: number | null;
|
|
buildingCount?: number | null;
|
|
floorCount?: number | null;
|
|
unitTypes?: Record<string, unknown> | null;
|
|
media?: Record<string, unknown>[] | null;
|
|
documents?: Record<string, unknown>[] | null;
|
|
tags?: string[];
|
|
suitableFor?: string[];
|
|
whyThisLocation?: string | null;
|
|
isVerified?: boolean;
|
|
startDate?: string | null;
|
|
completionDate?: string | null;
|
|
}
|
|
|
|
export interface SearchProjectsParams {
|
|
city?: string;
|
|
district?: string;
|
|
developerId?: string;
|
|
status?: ProjectStatus;
|
|
propertyType?: ProjectPropertyType;
|
|
minPrice?: string;
|
|
maxPrice?: string;
|
|
sort?: string;
|
|
page?: number;
|
|
limit?: number;
|
|
q?: string;
|
|
}
|
|
|
|
// ─── Status Labels ───────────────────────────────────────
|
|
|
|
export const PROJECT_STATUS_LABELS: Record<ProjectStatus, string> = {
|
|
PLANNING: 'Đang quy hoạch',
|
|
UNDER_CONSTRUCTION: 'Đang xây dựng',
|
|
HANDOVER: 'Đang bàn giao',
|
|
COMPLETED: 'Đã hoàn thành',
|
|
};
|
|
|
|
export const PROJECT_STATUS_COLORS: Record<ProjectStatus, string> = {
|
|
PLANNING: 'bg-blue-100 text-blue-800',
|
|
UNDER_CONSTRUCTION: 'bg-amber-100 text-amber-800',
|
|
HANDOVER: 'bg-purple-100 text-purple-800',
|
|
COMPLETED: 'bg-gray-100 text-gray-800',
|
|
};
|
|
|
|
export const PROJECT_PROPERTY_TYPE_LABELS: Record<ProjectPropertyType, string> = {
|
|
APARTMENT: 'Căn hộ',
|
|
VILLA: 'Biệt thự',
|
|
TOWNHOUSE: 'Nhà phố',
|
|
SHOPHOUSE: 'Shophouse',
|
|
LAND: 'Đất nền',
|
|
MIXED: 'Tổng hợp',
|
|
};
|
|
|
|
// ─── API Functions ───────────────────────────────────────
|
|
|
|
export const duAnApi = {
|
|
search: (params: SearchProjectsParams = {}) => {
|
|
const query = new URLSearchParams();
|
|
Object.entries(params).forEach(([key, value]) => {
|
|
if (value !== undefined && value !== '') query.append(key, String(value));
|
|
});
|
|
const qs = query.toString();
|
|
return apiClient.get<PaginatedResult<ProjectSummary>>(
|
|
`/projects${qs ? `?${qs}` : ''}`,
|
|
);
|
|
},
|
|
|
|
getBySlug: (slug: string) =>
|
|
apiClient.get<ProjectDetail>(`/projects/${slug}`),
|
|
|
|
getLinkedListings: (projectId: string, params: { page?: number; limit?: number } = {}) => {
|
|
const query = new URLSearchParams();
|
|
if (params.page) query.append('page', String(params.page));
|
|
if (params.limit) query.append('limit', String(params.limit));
|
|
const qs = query.toString();
|
|
return apiClient.get<PaginatedResult<ListingDetail>>(
|
|
`/projects/${projectId}/listings${qs ? `?${qs}` : ''}`,
|
|
);
|
|
},
|
|
|
|
submitInquiry: (projectId: string, data: { name: string; phone: string; message: string }) =>
|
|
apiClient.post<{ inquiryId: string }>(`/projects/${projectId}/inquiries`, data),
|
|
|
|
create: (payload: CreateProjectPayload) =>
|
|
apiClient.post<{ id: string; slug: string }>('/projects', payload),
|
|
|
|
update: (id: string, payload: UpdateProjectPayload) =>
|
|
apiClient.patch<ProjectDetail>(`/projects/${id}`, payload),
|
|
|
|
delete: (id: string) =>
|
|
apiClient.delete<{ success: boolean }>(`/projects/${id}`),
|
|
};
|