Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 16s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 50s
Deploy / Build API Image (push) Failing after 25s
Deploy / Build Web Image (push) Failing after 11s
Deploy / Build AI Services Image (push) Failing after 10s
E2E Tests / Playwright E2E (push) Failing after 12s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 4s
Security Scanning / Trivy Scan — API Image (push) Failing after 1m16s
Security Scanning / Trivy Scan — Web Image (push) Failing after 1m2s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 50s
Security Scanning / Trivy Filesystem Scan (push) Failing after 38s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Deploy to Production (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Security Scanning / Security Gate (push) Failing after 0s
Deploy / Rollback Production (push) Has been skipped
Deploy / Rollback Staging (push) Failing after 10m50s
Two new B2B roles for CĐT (project developers) and KCN operators, provisioned by
admin. Each account owns a subset of ProjectDevelopment / IndustrialPark records
and can CRUD them from the dashboard; admin retains full access.
Phase 1 — Schema
- Extend UserRole enum with DEVELOPER + PARK_OPERATOR (before ADMIN)
- ProjectDevelopment.ownerId FK (User, ON DELETE SET NULL) + index
- IndustrialPark.ownerId FK + index
- Migration 20260420030000
Phase 2a — Backend authorization
- CreateProjectCommand + CreateIndustrialParkCommand accept ownerId; controllers
auto-set it to the caller's user id when role=DEVELOPER / PARK_OPERATOR
- Update + Delete commands gain (requesterUserId, requesterRole) and enforce
ADMIN-or-owner via ForbiddenException; reassigning ownerId is admin-only
- Search params gain optional ownerId filter wired through Prisma repos
- New endpoints: GET /projects/mine/list, GET /industrial/parks/mine/list
- user-rate-limit guard: add DEVELOPER + PARK_OPERATOR entries (300/window)
Phase 2b — Admin provision
- ProvisionDeveloperCommand/Handler: create user (role=DEVELOPER), pre-validate
target projects have no existing owner, batch-assign ownerId
- ProvisionParkOperatorCommand/Handler: same for PARK_OPERATOR + IndustrialPark
- POST /admin/accounts/developers, POST /admin/accounts/park-operators (admin-only)
- DTOs with phone/password/fullName/email + optional {project,park}Ids[]
Phase 2c — Project stats for developer dashboard
- GetProjectStatsQuery + handler: aggregates linkedListingCount, activeListingCount,
totalInquiries, unreadInquiries, savedByUsers via Property → Listing → Inquiry chain
- GET /projects/:id/stats — admin sees all, DEVELOPER only their own (403 otherwise)
Phase 3 — Frontend
- Dashboard layout role-aware: DEVELOPER sees "Dự án của tôi" + CRM + Profile (hides
listings/analytics/subscription); PARK_OPERATOR sees "KCN của tôi" equivalent
- /projects dashboard page switches to duAnApi.searchMine() when role=DEVELOPER
- /industrial-parks page switches to industrialApi.searchMine() when role=PARK_OPERATOR
- Admin nav gains "Tài khoản CĐT" + "Tài khoản KCN" entries
- New pages /admin/accounts/developers + /admin/accounts/park-operators with
checkbox-based multi-select for linking entities
- adminApi.provisionDeveloper + provisionParkOperator + types
- duAnApi.searchMine + getStats; industrialApi.searchMine
- Login demo accounts list includes CĐT Vingroup + KCN VSIP
Phase 4 — Seed (prisma/seed-b2b-accounts.ts)
- DEVELOPER "CĐT Vingroup" (+84912000001) owns 4 projects
- DEVELOPER "CĐT Masterise Homes" (+84912000003) owns 2 projects
- PARK_OPERATOR "Vận hành KCN VSIP" (+84912000002) owns 2 seeded KCN
- Password Velik@2026 for all
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
321 lines
9.3 KiB
TypeScript
321 lines
9.3 KiB
TypeScript
import { apiClient } from './api-client';
|
|
|
|
// ─── Types ──────────────────────────────────────────────
|
|
|
|
export type IndustrialParkStatus =
|
|
| 'PLANNING'
|
|
| 'UNDER_CONSTRUCTION'
|
|
| 'OPERATIONAL'
|
|
| 'FULL';
|
|
|
|
export type VietnamRegion = 'NORTH' | 'CENTRAL' | 'SOUTH';
|
|
|
|
export interface IndustrialParkListItem {
|
|
id: string;
|
|
name: string;
|
|
nameEn: string | null;
|
|
slug: string;
|
|
developer: string;
|
|
status: IndustrialParkStatus;
|
|
province: string;
|
|
region: VietnamRegion;
|
|
totalAreaHa: number;
|
|
occupancyRate: number;
|
|
remainingAreaHa: number;
|
|
tenantCount: number;
|
|
landRentUsdM2Year: number | null;
|
|
rbfRentUsdM2Month: number | null;
|
|
rbwRentUsdM2Month: number | null;
|
|
targetIndustries: string[];
|
|
latitude: number;
|
|
longitude: number;
|
|
}
|
|
|
|
export interface IndustrialParkDetail {
|
|
id: string;
|
|
name: string;
|
|
nameEn: string | null;
|
|
slug: string;
|
|
developer: string;
|
|
operator: string | null;
|
|
status: IndustrialParkStatus;
|
|
latitude: number;
|
|
longitude: number;
|
|
address: string;
|
|
district: string;
|
|
province: string;
|
|
region: VietnamRegion;
|
|
totalAreaHa: number;
|
|
leasableAreaHa: number;
|
|
occupancyRate: number;
|
|
remainingAreaHa: number;
|
|
tenantCount: number;
|
|
establishedYear: number | null;
|
|
landRentUsdM2Year: number | null;
|
|
rbfRentUsdM2Month: number | null;
|
|
rbwRentUsdM2Month: number | null;
|
|
managementFeeUsd: number | null;
|
|
infrastructure: Record<string, string> | null;
|
|
connectivity: Record<string, { name: string; distanceKm: number }> | null;
|
|
incentives: Record<string, unknown> | null;
|
|
targetIndustries: string[];
|
|
existingTenants: { name: string; country: string; industry: string }[] | null;
|
|
certifications: string[] | null;
|
|
media: { url: string; type: string; caption?: string }[] | null;
|
|
documents: { url: string; name: string }[] | null;
|
|
description: string | null;
|
|
descriptionEn: string | null;
|
|
isVerified: boolean;
|
|
listingCount: number;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface IndustrialParkStats {
|
|
totalParks: number;
|
|
totalAreaHa: number;
|
|
avgOccupancyRate: number;
|
|
totalTenants: number;
|
|
byRegion: { region: string; count: number; avgOccupancy: number }[];
|
|
byStatus: { status: string; count: number }[];
|
|
topProvinces: { province: string; count: number; avgRent: number | null }[];
|
|
}
|
|
|
|
export interface IndustrialMarketData {
|
|
totalParks: number;
|
|
avgOccupancyRate: number;
|
|
avgLandRentUsdM2: number | null;
|
|
avgRbfRentUsdM2: number | null;
|
|
rentByRegion: { region: string; avgLandRent: number | null; avgRbfRent: number | null; parkCount: number }[];
|
|
rentByProvince: { province: string; avgLandRent: number | null; avgRbfRent: number | null; parkCount: number }[];
|
|
}
|
|
|
|
// ─── Industrial Listing Types ───────────────────────────
|
|
|
|
export type IndustrialPropertyType =
|
|
| 'INDUSTRIAL_LAND'
|
|
| 'READY_BUILT_FACTORY'
|
|
| 'READY_BUILT_WAREHOUSE'
|
|
| 'LOGISTICS_CENTER'
|
|
| 'OFFICE_IN_PARK'
|
|
| 'DATA_CENTER';
|
|
|
|
export type IndustrialLeaseType =
|
|
| 'LAND_LEASE'
|
|
| 'FACTORY_LEASE'
|
|
| 'WAREHOUSE_LEASE'
|
|
| 'SUBLEASE';
|
|
|
|
export type IndustrialListingStatus =
|
|
| 'DRAFT'
|
|
| 'ACTIVE'
|
|
| 'RESERVED'
|
|
| 'LEASED'
|
|
| 'EXPIRED';
|
|
|
|
export interface IndustrialListingItem {
|
|
id: string;
|
|
parkId: string;
|
|
parkName: string;
|
|
parkSlug: string;
|
|
propertyType: IndustrialPropertyType;
|
|
leaseType: IndustrialLeaseType;
|
|
status: IndustrialListingStatus;
|
|
title: string;
|
|
description: string | null;
|
|
areaM2: number;
|
|
ceilingHeightM: number | null;
|
|
priceUsdM2: number | null;
|
|
pricingUnit: string | null;
|
|
totalLeasePrice: number | null;
|
|
minLeaseYears: number | null;
|
|
maxLeaseYears: number | null;
|
|
availableFrom: string | null;
|
|
media: { url: string; type: string; caption?: string }[] | null;
|
|
viewCount: number;
|
|
publishedAt: string | null;
|
|
}
|
|
|
|
export interface SearchIndustrialListingsParams {
|
|
parkId?: string;
|
|
propertyType?: IndustrialPropertyType;
|
|
leaseType?: IndustrialLeaseType;
|
|
minAreaM2?: number;
|
|
maxAreaM2?: number;
|
|
minPriceUsdM2?: number;
|
|
maxPriceUsdM2?: number;
|
|
q?: string;
|
|
page?: number;
|
|
limit?: number;
|
|
}
|
|
|
|
export interface CreateIndustrialParkPayload {
|
|
name: string;
|
|
nameEn?: string;
|
|
slug: string;
|
|
developer: string;
|
|
operator?: string;
|
|
status: IndustrialParkStatus;
|
|
latitude: number;
|
|
longitude: number;
|
|
address: string;
|
|
district: string;
|
|
province: string;
|
|
region: VietnamRegion;
|
|
totalAreaHa: number;
|
|
leasableAreaHa: number;
|
|
occupancyRate: number;
|
|
remainingAreaHa: number;
|
|
tenantCount?: number;
|
|
establishedYear?: number;
|
|
landRentUsdM2Year?: number;
|
|
rbfRentUsdM2Month?: number;
|
|
rbwRentUsdM2Month?: number;
|
|
managementFeeUsd?: number;
|
|
infrastructure?: Record<string, unknown>;
|
|
connectivity?: Record<string, unknown>;
|
|
incentives?: Record<string, unknown>;
|
|
targetIndustries: string[];
|
|
description?: string;
|
|
descriptionEn?: string;
|
|
}
|
|
|
|
export interface UpdateIndustrialParkPayload {
|
|
name?: string;
|
|
nameEn?: string;
|
|
developer?: string;
|
|
operator?: string;
|
|
status?: IndustrialParkStatus;
|
|
occupancyRate?: number;
|
|
remainingAreaHa?: number;
|
|
tenantCount?: number;
|
|
landRentUsdM2Year?: number;
|
|
rbfRentUsdM2Month?: number;
|
|
rbwRentUsdM2Month?: number;
|
|
managementFeeUsd?: number;
|
|
infrastructure?: Record<string, unknown>;
|
|
connectivity?: Record<string, unknown>;
|
|
incentives?: Record<string, unknown>;
|
|
targetIndustries?: string[];
|
|
description?: string;
|
|
descriptionEn?: string;
|
|
isVerified?: boolean;
|
|
}
|
|
|
|
export interface PaginatedResult<T> {
|
|
data: T[];
|
|
total: number;
|
|
page: number;
|
|
limit: number;
|
|
totalPages: number;
|
|
}
|
|
|
|
export interface SearchIndustrialParksParams {
|
|
q?: string;
|
|
province?: string;
|
|
region?: VietnamRegion;
|
|
status?: IndustrialParkStatus;
|
|
minAreaHa?: number;
|
|
maxRentUsdM2?: number;
|
|
targetIndustry?: string;
|
|
page?: number;
|
|
limit?: number;
|
|
}
|
|
|
|
// ─── Labels ─────────────────────────────────────────────
|
|
|
|
export const PARK_STATUS_LABELS: Record<IndustrialParkStatus, string> = {
|
|
PLANNING: 'Quy hoạch',
|
|
UNDER_CONSTRUCTION: 'Đang xây dựng',
|
|
OPERATIONAL: 'Đang hoạt động',
|
|
FULL: 'Đã lấp đầy',
|
|
};
|
|
|
|
export const PARK_STATUS_COLORS: Record<IndustrialParkStatus, string> = {
|
|
PLANNING: 'bg-blue-100 text-blue-800',
|
|
UNDER_CONSTRUCTION: 'bg-amber-100 text-amber-800',
|
|
OPERATIONAL: 'bg-green-100 text-green-800',
|
|
FULL: 'bg-red-100 text-red-800',
|
|
};
|
|
|
|
export const REGION_LABELS: Record<VietnamRegion, string> = {
|
|
NORTH: 'Miền Bắc',
|
|
CENTRAL: 'Miền Trung',
|
|
SOUTH: 'Miền Nam',
|
|
};
|
|
|
|
export const PROPERTY_TYPE_LABELS: Record<IndustrialPropertyType, string> = {
|
|
INDUSTRIAL_LAND: 'Đất công nghiệp',
|
|
READY_BUILT_FACTORY: 'Nhà xưởng xây sẵn',
|
|
READY_BUILT_WAREHOUSE: 'Kho bãi xây sẵn',
|
|
LOGISTICS_CENTER: 'Trung tâm logistics',
|
|
OFFICE_IN_PARK: 'Văn phòng trong KCN',
|
|
DATA_CENTER: 'Trung tâm dữ liệu',
|
|
};
|
|
|
|
export const LEASE_TYPE_LABELS: Record<IndustrialLeaseType, string> = {
|
|
LAND_LEASE: 'Thuê đất',
|
|
FACTORY_LEASE: 'Thuê nhà xưởng',
|
|
WAREHOUSE_LEASE: 'Thuê kho bãi',
|
|
SUBLEASE: 'Cho thuê lại',
|
|
};
|
|
|
|
// ─── API Functions ──────────────────────────────────────
|
|
|
|
export const industrialApi = {
|
|
search: (params: SearchIndustrialParksParams = {}) => {
|
|
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<IndustrialParkListItem>>(
|
|
`/industrial/parks${qs ? `?${qs}` : ''}`,
|
|
);
|
|
},
|
|
|
|
/** PARK_OPERATOR / ADMIN only — returns KCN owned by the current user. */
|
|
searchMine: (params: SearchIndustrialParksParams = {}) => {
|
|
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<IndustrialParkListItem>>(
|
|
`/industrial/parks/mine/list${qs ? `?${qs}` : ''}`,
|
|
);
|
|
},
|
|
|
|
getBySlug: (slug: string) =>
|
|
apiClient.get<IndustrialParkDetail>(`/industrial/parks/${slug}`),
|
|
|
|
compare: (ids: string[]) =>
|
|
apiClient.post<IndustrialParkDetail[]>('/industrial/parks/compare', { ids }),
|
|
|
|
getStats: () =>
|
|
apiClient.get<IndustrialParkStats>('/industrial/parks/stats'),
|
|
|
|
getMarket: () =>
|
|
apiClient.get<IndustrialMarketData>('/industrial/market'),
|
|
|
|
searchListings: (params: SearchIndustrialListingsParams = {}) => {
|
|
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<IndustrialListingItem>>(
|
|
`/industrial/listings${qs ? `?${qs}` : ''}`,
|
|
);
|
|
},
|
|
|
|
createPark: (payload: CreateIndustrialParkPayload) =>
|
|
apiClient.post<IndustrialParkDetail>('/industrial/parks', payload),
|
|
|
|
updatePark: (id: string, payload: UpdateIndustrialParkPayload) =>
|
|
apiClient.patch<IndustrialParkDetail>(`/industrial/parks/${id}`, payload),
|
|
|
|
deletePark: (id: string) =>
|
|
apiClient.delete<{ success: boolean }>(`/industrial/parks/${id}`),
|
|
};
|