From b072d1fa2dca4dddd43509cb9e68e4641e3759fc Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Fri, 17 Apr 2026 11:59:34 -0400 Subject: [PATCH] Extract zip code from location address as fallback for distance calc - Regex extracts 5-digit zip from address string when ZipCode field is empty - Enables distance calculation for synced locations without structured zip data --- .../Controllers/WorkOrderController.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs b/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs index 33227e7..9de9b5f 100644 --- a/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs +++ b/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs @@ -610,7 +610,7 @@ namespace Api.SeaHavenIndustries.Controllers assignee = s.AssignToUser != null ? s.AssignToUser.FirstName : "", location = s.Locations != null ? s.Locations.Name : "", locationId = s.LocationId, - locationZip = s.Locations != null ? s.Locations.ZipCode : "", + locationZip = s.Locations != null ? (s.Locations.ZipCode ?? ExtractZip(s.Locations.Address)) : "", priority = s.Priority, s.Problem, s.Trade, @@ -1115,6 +1115,13 @@ namespace Api.SeaHavenIndustries.Controllers return Ok(data); } + private static string? ExtractZip(string? address) + { + if (string.IsNullOrWhiteSpace(address)) return null; + var match = System.Text.RegularExpressions.Regex.Match(address, @"\b(\d{5})(?:-\d{4})?\b"); + return match.Success ? match.Groups[1].Value : null; + } + private async Task GenerateInternalWONumber() { var lastWO = await _db.workOrders