Files
SMATEC-FRONTEND/ZONE_MIGRATION.md

4.0 KiB

Zone (Banzone) API Migration - Complete

Migration Banzone/Zone API vào SGW Module

Files Created

  1. ZoneController.ts - src/services/slave/sgw/ZoneController.ts

     apiGetAllBanzones(body) - Get all banzones with pagination
     apiRemoveBanzone(id, groupID) - Remove a banzone
     apiGetZoneById(zoneId) - Get banzone by ID
     apiCreateBanzone(body) - Create new banzone
     apiUpdateBanzone(id, body) - Update banzone
    
  2. Type Definitions - Added to src/services/slave/sgw/sgw.typing.d.ts

     Banzone
     Condition
     Geom
     ZoneResponse
     ZoneBodyRequest
    
  3. Route Constants - Added to src/constants/slave/sgw/routes.ts

     SGW_ROUTE_BANZONES = '/api/sgw/banzones'
     SGW_ROUTE_BANZONES_LIST = '/api/sgw/banzones/list'
    

Files Updated

  • src/pages/Slave/SGW/Map/components/ShipDetail.tsx
    • Updated import: @/services/controller/ZoneController@/services/slave/sgw/ZoneController
    • Updated types: API.ThingSgwModel.SgwThing
    • Updated types: API.UserResponseMasterModel.UserResponse
    • Updated types: API.GeomSgwModel.Geom

Migration Changes

Before:

import { apiGetZoneById } from '@/services/controller/ZoneController';

thing: API.Thing
const zone_geom: API.Geom = ...

After:

import { apiGetZoneById } from '@/services/slave/sgw/ZoneController';

thing: SgwModel.SgwThing
const zone_geom: SgwModel.Geom = ...

Type Definitions

declare namespace SgwModel {
  interface Banzone {
    id?: string;
    name?: string;
    province_code?: string;
    type?: number;
    conditions?: Condition[];
    description?: string;
    geometry?: string;
    enabled?: boolean;
    created_at?: Date;
    updated_at?: Date;
  }

  interface Condition {
    max?: number;
    min?: number;
    type?: 'length_limit' | 'month_range' | 'date_range';
    to?: number;
    from?: number;
  }

  interface Geom {
    geom_type?: number;
    geom_poly?: string;
    geom_lines?: string;
    geom_point?: string;
    geom_radius?: number;
  }

  interface ZoneResponse {
    total?: number;
    offset?: number;
    limit?: number;
    banzones?: Banzone[];
  }

  interface ZoneBodyRequest {
    name?: string;
    province_code?: string;
    type?: number;
    conditions?: Condition[];
    description?: string;
    geometry?: string;
    enabled?: boolean;
  }
}

API Usage Examples

Get Zone by ID:

import { apiGetZoneById } from '@/services/slave/sgw/ZoneController';

const zone = await apiGetZoneById('zone-123');
const geometry: SgwModel.Geom = JSON.parse(zone.geometry || '{}');

Create Banzone:

import { apiCreateBanzone } from '@/services/slave/sgw/ZoneController';

const zoneData: SgwModel.ZoneBodyRequest = {
  name: 'Vùng cấm mùa sinh sản',
  province_code: 'QN',
  type: 1,
  enabled: true,
  conditions: [
    {
      type: 'month_range',
      from: 4,
      to: 8,
    },
  ],
  geometry: JSON.stringify({
    geom_type: 1,
    geom_poly: 'POLYGON(...)',
  }),
};

await apiCreateBanzone(zoneData);

Get All Banzones:

import { apiGetAllBanzones } from '@/services/slave/sgw/ZoneController';

const response = await apiGetAllBanzones({
  offset: 0,
  limit: 20,
  order: 'name',
  dir: 'asc',
});

Status: Complete

  • 5 API functions migrated
  • 5 type definitions added
  • 2 route constants added
  • 1 file updated (ShipDetail.tsx)
  • 0 compilation errors

Total SGW Migration Progress

Module APIs Types Status
Ship 12 15+
Trip 17 21+
Photo 2 2
Zone 5 5
TOTAL 36 43+

Migration Date: January 23, 2026
Status: Complete
Ready for Testing: YES