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
This commit is contained in:
Adam Moussa 2026-04-17 11:59:34 -04:00
parent 521bb0fba2
commit b072d1fa2d

View file

@ -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<string> GenerateInternalWONumber()
{
var lastWO = await _db.workOrders