Skip to main content
Version: 0.9.0 (Latest)

🏢 Location Blocks

Location blocks provide comprehensive functionality for hierarchical location management in Nodeblocks applications. These blocks handle location hierarchies with support for parent-child relationships, ancestor tracking, and various location types.


🎯 Overview

Location blocks are designed to:

  • Manage hierarchical location structures with parent-child relationships and ancestor tracking
  • Support multiple location types (regions, cities, buildings, etc.)
  • Handle location CRUD operations with proper validation and normalization
  • Maintain referential integrity through ancestor chains and parent relationships
  • Provide location validation and business rules for hierarchical data
  • Enable location administration with comprehensive controls

🏗️ Hierarchical Structure

Locations support a tree-like hierarchical structure where each location can have:

  • Parent Location: Direct parent in the hierarchy
  • Ancestors: Complete path from root to current location
  • Children: Locations that have this location as their parent

Example Hierarchy

Organization (Root)
├── Region A
│ ├── City X
│ │ ├── Building 1
│ │ └── Building 2
│ └── City Y
└── Region B
└── City Z

📦 Block Types

🔍 Schemas

JSON Schema definitions for location data validation:

  • locationSchema: Base location entity structure with core fields
  • createLocationSchema: Location creation validation with hierarchical parent support
  • getLocationSchema: Location retrieval schema with path parameter validation
  • updateLocationSchema: Location update schema with optional fields for partial updates
  • deleteLocationSchema: Location deletion schema with path parameter validation
  • findLocationsSchema: Location search schema with pagination query validation

View Location Schemas →

🔧 Blocks

Pure business logic functions for location operations:

  • buildAncestorsFromParent: Builds ancestor path by appending parent ID to existing ancestors
  • buildLocationToCreate: Normalizes location data for creation with ancestors and parent handling
  • getLocationById: Retrieves a location by ID from the database with proper projection
  • createLocation: Creates a new location document in the database with base entity normalization
  • updateLocation: Updates an existing location document by ID with partial field updates
  • buildDescendantsFilter: Builds MongoDB filter to find locations with specified ancestor in their hierarchy
  • assertNoDescendantLocations: Validates that no child locations exist before allowing parent location deletion
  • deleteLocation: Deletes a location from the database by ID
  • findLocations: Retrieves multiple locations matching a filter from the database with automatic field projection
  • normalizeLocation: Normalizes location data by transforming internal fields to API-friendly format

View Location Blocks →

🛣️ Routes

HTTP endpoint definitions for location operations:

  • createLocationRoute: POST /locations with hierarchical parent support and ancestor building
  • getLocationRoute: GET /locations/:locationId with public access and location lookup
  • updateLocationRoute: PATCH /locations/:locationId with admin authentication and partial updates
  • deleteLocationRoute: DELETE /locations/:locationId with hierarchy validation and admin authentication
  • findLocationsRoute: GET /locations with pagination support and public access

View Location Routes →

🚀 Features

Complete location management features combining schemas and routes:

  • createLocationFeature: Location creation with schema validation and hierarchical routing
  • getLocationFeature: Location retrieval feature with schema validation and public routing
  • updateLocationFeature: Location update feature with schema validation and admin routing
  • deleteLocationFeature: Location deletion feature with schema validation and hierarchy validation routing
  • findLocationsFeature: Location search feature with schema validation and pagination routing

View Location Features →