fix: align Project status enum to Prisma + cascade child records on listing delete
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 10s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 31s
E2E Tests / Playwright E2E (push) Failing after 7s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 3s
Security Scanning / Trivy Scan — API Image (push) Failing after 34s
Security Scanning / Trivy Scan — Web Image (push) Failing after 23s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 25s
Security Scanning / Trivy Filesystem Scan (push) Failing after 26s
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Deploy to Production (push) Has been skipped
Deploy / Build API Image (push) Failing after 16s
Deploy / Build Web Image (push) Failing after 9s
Deploy / Build AI Services Image (push) Failing after 8s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Security Scanning / Security Gate (push) Failing after 0s
Deploy / Rollback Staging (push) Has been skipped
Deploy / Rollback Production (push) Has been skipped

Project status was declared on the frontend as
UPCOMING/SELLING/HANDOVER/COMPLETED but the Prisma enum
ProjectDevelopmentStatus is PLANNING/UNDER_CONSTRUCTION/HANDOVER/
COMPLETED — CREATE failed with "status must be one of …". Aligned the
TypeScript union + PROJECT_STATUS_LABELS/COLORS, filter options on
/projects list, and both new + edit forms. Updated the
normalizeProjectDetail fallback and the du-an test spec to match.

Listings DELETE was blocked by FK references (Inquiry, SavedListing,
PriceHistory, Order, Transaction have no onDelete: Cascade in schema).
Wrapped the Prisma listing delete in a $transaction that removes the
child rows first, then the listing itself, so CRUD from the dashboard
actually lands instead of returning "Referenced record does not exist".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-04-19 13:36:46 +07:00
parent ba0bf97426
commit dfc01c3bee
7 changed files with 34 additions and 19 deletions

View File

@@ -3,9 +3,11 @@ 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 =
| 'UPCOMING'
| 'SELLING'
| 'PLANNING'
| 'UNDER_CONSTRUCTION'
| 'HANDOVER'
| 'COMPLETED';
@@ -198,16 +200,16 @@ export interface SearchProjectsParams {
// ─── Status Labels ───────────────────────────────────────
export const PROJECT_STATUS_LABELS: Record<ProjectStatus, string> = {
UPCOMING: 'Sắp mở bán',
SELLING: 'Đang bán',
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> = {
UPCOMING: 'bg-blue-100 text-blue-800',
SELLING: 'bg-green-100 text-green-800',
HANDOVER: 'bg-amber-100 text-amber-800',
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',
};

View File

@@ -63,7 +63,7 @@ function normalizeProjectDetail(raw: unknown): ProjectDetail | null {
id: String(r['id'] ?? ''),
slug: String(r['slug'] ?? ''),
name: String(r['name'] ?? ''),
status: (r['status'] as ProjectDetail['status']) ?? 'SELLING',
status: (r['status'] as ProjectDetail['status']) ?? 'PLANNING',
developer,
city: String(r['city'] ?? ''),
district: String(r['district'] ?? ''),