Files
goodgo-platform/apps/api/src/modules/industrial/domain/entities/industrial-park.entity.ts
Ho Ngoc Hai 33a5ff407b
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
feat(auth): add DEVELOPER + PARK_OPERATOR roles with owner scoping (B2B accounts)
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>
2026-04-20 22:12:16 +07:00

178 lines
7.7 KiB
TypeScript

import { type IndustrialParkStatus, type VietnamRegion } from '@prisma/client';
import { AggregateRoot } from '@modules/shared';
export interface IndustrialParkProps {
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, unknown> | null;
connectivity: Record<string, unknown> | null;
incentives: Record<string, unknown> | null;
targetIndustries: string[];
existingTenants: Record<string, unknown>[] | null;
certifications: string[] | null;
media: Record<string, unknown>[] | null;
documents: Record<string, unknown>[] | null;
description: string | null;
descriptionEn: string | null;
isVerified: boolean;
ownerId: string | null;
}
export class IndustrialParkEntity extends AggregateRoot<string> {
private _name: string;
private _nameEn: string | null;
private _slug: string;
private _developer: string;
private _operator: string | null;
private _status: IndustrialParkStatus;
private _latitude: number;
private _longitude: number;
private _address: string;
private _district: string;
private _province: string;
private _region: VietnamRegion;
private _totalAreaHa: number;
private _leasableAreaHa: number;
private _occupancyRate: number;
private _remainingAreaHa: number;
private _tenantCount: number;
private _establishedYear: number | null;
private _landRentUsdM2Year: number | null;
private _rbfRentUsdM2Month: number | null;
private _rbwRentUsdM2Month: number | null;
private _managementFeeUsd: number | null;
private _infrastructure: Record<string, unknown> | null;
private _connectivity: Record<string, unknown> | null;
private _incentives: Record<string, unknown> | null;
private _targetIndustries: string[];
private _existingTenants: Record<string, unknown>[] | null;
private _certifications: string[] | null;
private _media: Record<string, unknown>[] | null;
private _documents: Record<string, unknown>[] | null;
private _description: string | null;
private _descriptionEn: string | null;
private _isVerified: boolean;
private _ownerId: string | null;
constructor(id: string, props: IndustrialParkProps, createdAt: Date, updatedAt: Date) {
super(id, createdAt, updatedAt);
this._name = props.name;
this._nameEn = props.nameEn;
this._slug = props.slug;
this._developer = props.developer;
this._operator = props.operator;
this._status = props.status;
this._latitude = props.latitude;
this._longitude = props.longitude;
this._address = props.address;
this._district = props.district;
this._province = props.province;
this._region = props.region;
this._totalAreaHa = props.totalAreaHa;
this._leasableAreaHa = props.leasableAreaHa;
this._occupancyRate = props.occupancyRate;
this._remainingAreaHa = props.remainingAreaHa;
this._tenantCount = props.tenantCount;
this._establishedYear = props.establishedYear;
this._landRentUsdM2Year = props.landRentUsdM2Year;
this._rbfRentUsdM2Month = props.rbfRentUsdM2Month;
this._rbwRentUsdM2Month = props.rbwRentUsdM2Month;
this._managementFeeUsd = props.managementFeeUsd;
this._infrastructure = props.infrastructure;
this._connectivity = props.connectivity;
this._incentives = props.incentives;
this._targetIndustries = props.targetIndustries;
this._existingTenants = props.existingTenants;
this._certifications = props.certifications;
this._media = props.media;
this._documents = props.documents;
this._description = props.description;
this._descriptionEn = props.descriptionEn;
this._isVerified = props.isVerified;
this._ownerId = props.ownerId;
}
get name() { return this._name; }
get nameEn() { return this._nameEn; }
get slug() { return this._slug; }
get developer() { return this._developer; }
get operator() { return this._operator; }
get status() { return this._status; }
get latitude() { return this._latitude; }
get longitude() { return this._longitude; }
get address() { return this._address; }
get district() { return this._district; }
get province() { return this._province; }
get region() { return this._region; }
get totalAreaHa() { return this._totalAreaHa; }
get leasableAreaHa() { return this._leasableAreaHa; }
get occupancyRate() { return this._occupancyRate; }
get remainingAreaHa() { return this._remainingAreaHa; }
get tenantCount() { return this._tenantCount; }
get establishedYear() { return this._establishedYear; }
get landRentUsdM2Year() { return this._landRentUsdM2Year; }
get rbfRentUsdM2Month() { return this._rbfRentUsdM2Month; }
get rbwRentUsdM2Month() { return this._rbwRentUsdM2Month; }
get managementFeeUsd() { return this._managementFeeUsd; }
get infrastructure() { return this._infrastructure; }
get connectivity() { return this._connectivity; }
get incentives() { return this._incentives; }
get targetIndustries() { return this._targetIndustries; }
get existingTenants() { return this._existingTenants; }
get certifications() { return this._certifications; }
get media() { return this._media; }
get documents() { return this._documents; }
get description() { return this._description; }
get descriptionEn() { return this._descriptionEn; }
get isVerified() { return this._isVerified; }
get ownerId() { return this._ownerId; }
updateDetails(props: Partial<IndustrialParkProps>): void {
if (props.name !== undefined) this._name = props.name;
if (props.nameEn !== undefined) this._nameEn = props.nameEn;
if (props.developer !== undefined) this._developer = props.developer;
if (props.operator !== undefined) this._operator = props.operator;
if (props.status !== undefined) this._status = props.status;
if (props.occupancyRate !== undefined) this._occupancyRate = props.occupancyRate;
if (props.remainingAreaHa !== undefined) this._remainingAreaHa = props.remainingAreaHa;
if (props.tenantCount !== undefined) this._tenantCount = props.tenantCount;
if (props.landRentUsdM2Year !== undefined) this._landRentUsdM2Year = props.landRentUsdM2Year;
if (props.rbfRentUsdM2Month !== undefined) this._rbfRentUsdM2Month = props.rbfRentUsdM2Month;
if (props.rbwRentUsdM2Month !== undefined) this._rbwRentUsdM2Month = props.rbwRentUsdM2Month;
if (props.managementFeeUsd !== undefined) this._managementFeeUsd = props.managementFeeUsd;
if (props.infrastructure !== undefined) this._infrastructure = props.infrastructure;
if (props.connectivity !== undefined) this._connectivity = props.connectivity;
if (props.incentives !== undefined) this._incentives = props.incentives;
if (props.targetIndustries !== undefined) this._targetIndustries = props.targetIndustries;
if (props.existingTenants !== undefined) this._existingTenants = props.existingTenants;
if (props.certifications !== undefined) this._certifications = props.certifications;
if (props.media !== undefined) this._media = props.media;
if (props.documents !== undefined) this._documents = props.documents;
if (props.description !== undefined) this._description = props.description;
if (props.descriptionEn !== undefined) this._descriptionEn = props.descriptionEn;
if (props.isVerified !== undefined) this._isVerified = props.isVerified;
if (props.ownerId !== undefined) this._ownerId = props.ownerId;
this.updatedAt = new Date();
}
}