project-nomad/admin/app/models/map_marker.ts
Chris Sherwood e0a3523807 feat(maps): persist markers to database instead of localStorage
Moves map marker storage from browser localStorage to a server-side database
table so pins survive cache clears, browser changes, and device switches.

Backend:
- New `map_markers` table with future-proofed columns for routing (marker_type,
  route_id, route_order, notes) to avoid a migration when routes are added later
- CRUD endpoints: GET/POST /api/maps/markers, PATCH/DELETE /api/maps/markers/:id
- VineJS validation on create/update
- MapMarker Lucid model

Frontend:
- useMapMarkers hook now fetches from API instead of localStorage
- Marker IDs changed from string (UUID) to number (DB auto-increment)
- API client methods added for all marker operations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 11:16:07 -07:00

44 lines
969 B
TypeScript

import { DateTime } from 'luxon'
import { BaseModel, column, SnakeCaseNamingStrategy } from '@adonisjs/lucid/orm'
export default class MapMarker extends BaseModel {
static namingStrategy = new SnakeCaseNamingStrategy()
@column({ isPrimary: true })
declare id: number
@column()
declare name: string
@column()
declare longitude: number
@column()
declare latitude: number
@column()
declare color: string
// 'pin' for user-placed markers, 'waypoint' for route points (future)
@column()
declare marker_type: string
// Groups markers into a route (future)
@column()
declare route_id: string | null
// Order within a route (future)
@column()
declare route_order: number | null
// Optional user notes for a location
@column()
declare notes: string | null
@column.dateTime({ autoCreate: true })
declare created_at: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updated_at: DateTime
}