Actually update the pool location when we create the lead

This commit is contained in:
Eli Ribble 2026-03-05 18:55:36 +00:00
parent 4577fda4a9
commit 72a4ef9fff
No known key found for this signature in database
2 changed files with 29 additions and 13 deletions

View file

@ -13,14 +13,16 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
//"github.com/rs/zerolog/log"
"github.com/Gleipnir-Technology/nidus-sync/platform/geom"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/rs/zerolog/log"
"github.com/stephenafamo/scan"
)
type createLead struct {
SignalIDs []int `json:"signal_ids"`
PoolLocations map[int]Location `json:"pool_locations"`
SignalIDs []int `json:"signal_ids"`
}
type createdLead struct {
ID int32 `json:"id"`
@ -102,7 +104,21 @@ func postLeads(ctx context.Context, r *http.Request, org *models.Organization, u
if err != nil {
return nil, nhttp.NewError("failed to update signal %d: %w", signal_id, err)
}
pool_location, ok := req.PoolLocations[signal_id]
if ok {
log.Info().Float64("lat", pool_location.Latitude).Float64("lng", pool_location.Longitude).Msg("got pool location")
geom_query := geom.PostgisPointQuery(pool_location.Longitude, pool_location.Latitude)
_, err = psql.Update(
um.Table("pool"),
um.SetCol("geometry").To(geom_query),
um.From("signal_pool"),
um.Where(psql.Quote("signal_pool", "pool_id").EQ(psql.Quote("pool", "id"))),
um.Where(psql.Quote("signal_pool", "signal_id").EQ(psql.Arg(signal_id))),
).Exec(ctx, txn)
if err != nil {
return nil, nhttp.NewError("failed to update pool through signal %d: %w", signal_id, err)
}
}
txn.Commit(ctx)
return &createdLead{

View file

@ -15,16 +15,6 @@
<script src="https://unpkg.com/@esri/maplibre-arcgis@1.1.0/dist/umd/maplibre-arcgis.min.js"></script>
<script>
function updateSignalLocation(event, signal_id) {
console.log("map click", signal_id, event.detail);
const map = event.detail.map;
const loc = {
latitude: event.detail.lat,
longitude: event.detail.lng,
};
map.SetMarkers([loc]);
this.poolLocations[signal_id] = loc;
}
// Return two points defining a bounding box for the given points
function getBoundingBox(points) {
// Handle empty or invalid input
@ -270,6 +260,16 @@
}
updateMap(this.selectedSignals);
},
updateSignalLocation(event, signal_id) {
console.log("map click", signal_id, event.detail);
const map = event.detail.map;
const loc = {
latitude: event.detail.lat,
longitude: event.detail.lng,
};
map.SetMarkers([loc]);
this.poolLocations[signal_id] = loc;
},
};
}
</script>