feat(api): add industrial, transfer, and reports backend modules

Add three new NestJS modules following DDD/CQRS architecture:
- Industrial: KCN (industrial park) management with PostGIS geo queries, Typesense search, and market statistics
- Transfer: Furniture/premises transfer listings with AI-powered price estimation and depreciation modeling
- Reports: Async AI report generation via BullMQ with Claude narrative service, PDF generation, and macro data integration

Includes Prisma schema models, migrations, seed scripts, and app.module wiring with BullMQ Redis config.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-16 09:11:16 +07:00
parent 7ce651fce5
commit deb04989de
123 changed files with 8260 additions and 12 deletions

View File

@@ -0,0 +1,168 @@
-- CreateEnum
CREATE TYPE "IndustrialParkStatus" AS ENUM ('PLANNING', 'UNDER_CONSTRUCTION', 'OPERATIONAL', 'FULL');
-- CreateEnum
CREATE TYPE "IndustrialPropertyType" AS ENUM ('INDUSTRIAL_LAND', 'READY_BUILT_FACTORY', 'READY_BUILT_WAREHOUSE', 'LOGISTICS_CENTER', 'OFFICE_IN_PARK', 'DATA_CENTER');
-- CreateEnum
CREATE TYPE "IndustrialLeaseType" AS ENUM ('LAND_LEASE', 'FACTORY_LEASE', 'WAREHOUSE_LEASE', 'SUBLEASE');
-- CreateEnum
CREATE TYPE "IndustrialListingStatus" AS ENUM ('DRAFT', 'ACTIVE', 'RESERVED', 'LEASED', 'EXPIRED');
-- CreateEnum
CREATE TYPE "VietnamRegion" AS ENUM ('NORTH', 'CENTRAL', 'SOUTH');
-- CreateTable
CREATE TABLE "IndustrialPark" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"nameEn" TEXT,
"slug" TEXT NOT NULL,
"developer" TEXT NOT NULL,
"operator" TEXT,
"status" "IndustrialParkStatus" NOT NULL DEFAULT 'PLANNING',
"location" geometry(Point, 4326) NOT NULL,
"address" TEXT NOT NULL,
"district" TEXT NOT NULL,
"province" TEXT NOT NULL,
"region" "VietnamRegion" NOT NULL,
"totalAreaHa" DOUBLE PRECISION NOT NULL,
"leasableAreaHa" DOUBLE PRECISION NOT NULL,
"occupancyRate" DOUBLE PRECISION NOT NULL DEFAULT 0,
"remainingAreaHa" DOUBLE PRECISION NOT NULL,
"tenantCount" INTEGER NOT NULL DEFAULT 0,
"establishedYear" INTEGER,
"landRentUsdM2Year" DOUBLE PRECISION,
"rbfRentUsdM2Month" DOUBLE PRECISION,
"rbwRentUsdM2Month" DOUBLE PRECISION,
"managementFeeUsd" DOUBLE PRECISION,
"infrastructure" JSONB,
"connectivity" JSONB,
"incentives" JSONB,
"targetIndustries" TEXT[],
"existingTenants" JSONB,
"certifications" JSONB,
"media" JSONB,
"documents" JSONB,
"description" TEXT,
"descriptionEn" TEXT,
"isVerified" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "IndustrialPark_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "IndustrialListing" (
"id" TEXT NOT NULL,
"parkId" TEXT NOT NULL,
"agentId" TEXT,
"sellerId" TEXT NOT NULL,
"propertyType" "IndustrialPropertyType" NOT NULL,
"leaseType" "IndustrialLeaseType" NOT NULL,
"status" "IndustrialListingStatus" NOT NULL DEFAULT 'DRAFT',
"title" TEXT NOT NULL,
"description" TEXT,
"areaM2" DOUBLE PRECISION NOT NULL,
"ceilingHeightM" DOUBLE PRECISION,
"floorLoadTonM2" DOUBLE PRECISION,
"columnSpacingM" DOUBLE PRECISION,
"dockCount" INTEGER,
"craneCapacityTon" DOUBLE PRECISION,
"hasMezzanine" BOOLEAN NOT NULL DEFAULT false,
"hasOfficeArea" BOOLEAN NOT NULL DEFAULT false,
"officeAreaM2" DOUBLE PRECISION,
"priceUsdM2" DOUBLE PRECISION,
"pricingUnit" TEXT,
"totalLeasePrice" DOUBLE PRECISION,
"managementFee" DOUBLE PRECISION,
"depositMonths" INTEGER,
"minLeaseYears" INTEGER,
"maxLeaseYears" INTEGER,
"leaseExpiry" TIMESTAMP(3),
"availableFrom" TIMESTAMP(3),
"powerCapacityKva" DOUBLE PRECISION,
"waterSupplyM3Day" DOUBLE PRECISION,
"media" JSONB,
"viewCount" INTEGER NOT NULL DEFAULT 0,
"inquiryCount" INTEGER NOT NULL DEFAULT 0,
"publishedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "IndustrialListing_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "IndustrialPark_slug_key" ON "IndustrialPark"("slug");
-- CreateIndex
CREATE INDEX "IndustrialPark_status_idx" ON "IndustrialPark"("status");
-- CreateIndex
CREATE INDEX "IndustrialPark_province_idx" ON "IndustrialPark"("province");
-- CreateIndex
CREATE INDEX "IndustrialPark_region_idx" ON "IndustrialPark"("region");
-- CreateIndex
CREATE INDEX "IndustrialPark_developer_idx" ON "IndustrialPark"("developer");
-- CreateIndex
CREATE INDEX "IndustrialPark_location_idx" ON "IndustrialPark" USING GIST ("location");
-- CreateIndex
CREATE INDEX "IndustrialPark_isVerified_idx" ON "IndustrialPark"("isVerified");
-- CreateIndex
CREATE INDEX "IndustrialPark_occupancyRate_idx" ON "IndustrialPark"("occupancyRate");
-- CreateIndex
CREATE INDEX "IndustrialPark_landRentUsdM2Year_idx" ON "IndustrialPark"("landRentUsdM2Year");
-- CreateIndex
CREATE INDEX "IndustrialPark_region_province_status_idx" ON "IndustrialPark"("region", "province", "status");
-- CreateIndex
CREATE INDEX "IndustrialPark_createdAt_idx" ON "IndustrialPark"("createdAt");
-- CreateIndex
CREATE INDEX "IndustrialListing_parkId_idx" ON "IndustrialListing"("parkId");
-- CreateIndex
CREATE INDEX "IndustrialListing_propertyType_idx" ON "IndustrialListing"("propertyType");
-- CreateIndex
CREATE INDEX "IndustrialListing_leaseType_idx" ON "IndustrialListing"("leaseType");
-- CreateIndex
CREATE INDEX "IndustrialListing_status_idx" ON "IndustrialListing"("status");
-- CreateIndex
CREATE INDEX "IndustrialListing_areaM2_idx" ON "IndustrialListing"("areaM2");
-- CreateIndex
CREATE INDEX "IndustrialListing_priceUsdM2_idx" ON "IndustrialListing"("priceUsdM2");
-- CreateIndex
CREATE INDEX "IndustrialListing_sellerId_idx" ON "IndustrialListing"("sellerId");
-- CreateIndex
CREATE INDEX "IndustrialListing_agentId_idx" ON "IndustrialListing"("agentId");
-- CreateIndex
CREATE INDEX "IndustrialListing_publishedAt_idx" ON "IndustrialListing"("publishedAt");
-- CreateIndex
CREATE INDEX "IndustrialListing_parkId_status_idx" ON "IndustrialListing"("parkId", "status");
-- CreateIndex
CREATE INDEX "IndustrialListing_propertyType_leaseType_status_idx" ON "IndustrialListing"("propertyType", "leaseType", "status");
-- CreateIndex
CREATE INDEX "IndustrialListing_status_publishedAt_idx" ON "IndustrialListing"("status", "publishedAt" DESC);
-- AddForeignKey
ALTER TABLE "IndustrialListing" ADD CONSTRAINT "IndustrialListing_parkId_fkey" FOREIGN KEY ("parkId") REFERENCES "IndustrialPark"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,105 @@
-- CreateEnum
CREATE TYPE "TransferCategory" AS ENUM ('FURNITURE', 'APPLIANCE', 'OFFICE_EQUIPMENT', 'KITCHEN', 'PREMISES', 'FULL_UNIT');
-- CreateEnum
CREATE TYPE "TransferCondition" AS ENUM ('NEW', 'LIKE_NEW', 'GOOD', 'FAIR', 'WORN');
-- CreateEnum
CREATE TYPE "TransferListingStatus" AS ENUM ('DRAFT', 'PENDING_REVIEW', 'ACTIVE', 'RESERVED', 'SOLD', 'EXPIRED', 'REJECTED');
-- CreateEnum
CREATE TYPE "TransferPricingSource" AS ENUM ('MANUAL', 'AI_ESTIMATED', 'NEGOTIABLE');
-- CreateTable
CREATE TABLE "TransferListing" (
"id" TEXT NOT NULL,
"sellerId" TEXT NOT NULL,
"category" "TransferCategory" NOT NULL,
"status" "TransferListingStatus" NOT NULL DEFAULT 'DRAFT',
"title" TEXT NOT NULL,
"description" TEXT,
"address" TEXT NOT NULL,
"ward" TEXT,
"district" TEXT NOT NULL,
"city" TEXT NOT NULL,
"location" geometry(Point, 4326) NOT NULL,
"askingPriceVND" BIGINT NOT NULL,
"aiEstimatePriceVND" BIGINT,
"aiConfidence" DOUBLE PRECISION,
"pricingSource" "TransferPricingSource" NOT NULL DEFAULT 'MANUAL',
"isNegotiable" BOOLEAN NOT NULL DEFAULT true,
"areaM2" DOUBLE PRECISION,
"monthlyRentVND" BIGINT,
"depositMonths" INTEGER,
"remainingLeaseMo" INTEGER,
"businessType" TEXT,
"footTraffic" TEXT,
"media" JSONB,
"moderationScore" DOUBLE PRECISION,
"moderationNotes" TEXT,
"viewCount" INTEGER NOT NULL DEFAULT 0,
"saveCount" INTEGER NOT NULL DEFAULT 0,
"inquiryCount" INTEGER NOT NULL DEFAULT 0,
"contactPhone" TEXT,
"contactName" TEXT,
"featuredUntil" TIMESTAMP(3),
"expiresAt" TIMESTAMP(3),
"publishedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "TransferListing_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "TransferItem" (
"id" TEXT NOT NULL,
"transferListingId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"brand" TEXT,
"modelName" TEXT,
"category" "TransferCategory" NOT NULL,
"condition" "TransferCondition" NOT NULL,
"purchaseYear" INTEGER,
"originalPriceVND" BIGINT,
"askingPriceVND" BIGINT NOT NULL,
"aiEstimatePriceVND" BIGINT,
"aiConfidence" DOUBLE PRECISION,
"quantity" INTEGER NOT NULL DEFAULT 1,
"dimensions" JSONB,
"media" JSONB,
"notes" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "TransferItem_pkey" PRIMARY KEY ("id")
);
-- CreateIndex: TransferListing
CREATE INDEX "TransferListing_sellerId_idx" ON "TransferListing"("sellerId");
CREATE INDEX "TransferListing_category_idx" ON "TransferListing"("category");
CREATE INDEX "TransferListing_status_idx" ON "TransferListing"("status");
CREATE INDEX "TransferListing_district_city_idx" ON "TransferListing"("district", "city");
CREATE INDEX "TransferListing_askingPriceVND_idx" ON "TransferListing"("askingPriceVND");
CREATE INDEX "TransferListing_location_idx" ON "TransferListing" USING GIST ("location");
CREATE INDEX "TransferListing_publishedAt_idx" ON "TransferListing"("publishedAt");
CREATE INDEX "TransferListing_createdAt_idx" ON "TransferListing"("createdAt");
CREATE INDEX "TransferListing_featuredUntil_idx" ON "TransferListing"("featuredUntil");
CREATE INDEX "TransferListing_expiresAt_idx" ON "TransferListing"("expiresAt");
CREATE INDEX "TransferListing_category_status_publishedAt_idx" ON "TransferListing"("category", "status", "publishedAt" DESC);
CREATE INDEX "TransferListing_district_city_category_status_idx" ON "TransferListing"("district", "city", "category", "status");
CREATE INDEX "TransferListing_status_createdAt_idx" ON "TransferListing"("status", "createdAt" DESC);
-- CreateIndex: TransferItem
CREATE INDEX "TransferItem_transferListingId_idx" ON "TransferItem"("transferListingId");
CREATE INDEX "TransferItem_category_idx" ON "TransferItem"("category");
CREATE INDEX "TransferItem_condition_idx" ON "TransferItem"("condition");
CREATE INDEX "TransferItem_brand_idx" ON "TransferItem"("brand");
CREATE INDEX "TransferItem_askingPriceVND_idx" ON "TransferItem"("askingPriceVND");
CREATE INDEX "TransferItem_transferListingId_category_idx" ON "TransferItem"("transferListingId", "category");
-- AddForeignKey
ALTER TABLE "TransferListing" ADD CONSTRAINT "TransferListing_sellerId_fkey" FOREIGN KEY ("sellerId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "TransferItem" ADD CONSTRAINT "TransferItem_transferListingId_fkey" FOREIGN KEY ("transferListingId") REFERENCES "TransferListing"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,77 @@
-- CreateEnum
CREATE TYPE "ReportType" AS ENUM ('RESIDENTIAL_MARKET', 'INDUSTRIAL_MARKET', 'DISTRICT_ANALYSIS', 'INVESTMENT_FEASIBILITY', 'INDUSTRIAL_LOCATION', 'PROPERTY_VALUATION', 'PORTFOLIO');
-- CreateEnum
CREATE TYPE "ReportStatus" AS ENUM ('GENERATING', 'READY', 'FAILED');
-- AlterTable: Add maxReports to Plan
ALTER TABLE "Plan" ADD COLUMN "maxReports" INTEGER;
-- CreateTable: Report
CREATE TABLE "Report" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"type" "ReportType" NOT NULL,
"title" TEXT NOT NULL,
"params" JSONB NOT NULL,
"content" JSONB,
"pdfUrl" TEXT,
"status" "ReportStatus" NOT NULL DEFAULT 'GENERATING',
"errorMsg" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Report_pkey" PRIMARY KEY ("id")
);
-- CreateTable: MacroeconomicData
CREATE TABLE "MacroeconomicData" (
"id" TEXT NOT NULL,
"province" TEXT NOT NULL,
"indicator" TEXT NOT NULL,
"value" DOUBLE PRECISION NOT NULL,
"unit" TEXT NOT NULL,
"period" TEXT NOT NULL,
"source" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "MacroeconomicData_pkey" PRIMARY KEY ("id")
);
-- CreateTable: InfrastructureProject
CREATE TABLE "InfrastructureProject" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"province" TEXT NOT NULL,
"category" TEXT NOT NULL,
"status" TEXT NOT NULL,
"investmentVND" BIGINT,
"startDate" TIMESTAMP(3),
"completionDate" TIMESTAMP(3),
"description" TEXT,
"impactRadius" DOUBLE PRECISION,
"location" geometry(Point, 4326),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "InfrastructureProject_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "Report_userId_createdAt_idx" ON "Report"("userId", "createdAt" DESC);
CREATE INDEX "Report_userId_type_idx" ON "Report"("userId", "type");
CREATE INDEX "Report_status_idx" ON "Report"("status");
-- CreateIndex
CREATE UNIQUE INDEX "MacroeconomicData_province_indicator_period_key" ON "MacroeconomicData"("province", "indicator", "period");
CREATE INDEX "MacroeconomicData_province_idx" ON "MacroeconomicData"("province");
CREATE INDEX "MacroeconomicData_indicator_period_idx" ON "MacroeconomicData"("indicator", "period");
-- CreateIndex
CREATE INDEX "InfrastructureProject_province_idx" ON "InfrastructureProject"("province");
CREATE INDEX "InfrastructureProject_category_idx" ON "InfrastructureProject"("category");
CREATE INDEX "InfrastructureProject_status_idx" ON "InfrastructureProject"("status");
CREATE INDEX "InfrastructureProject_province_category_idx" ON "InfrastructureProject"("province", "category");
-- AddForeignKey
ALTER TABLE "Report" ADD CONSTRAINT "Report_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;