Update process_logbook_queue_fn, moorage name part2

This commit is contained in:
xbgmsharp
2024-04-27 18:13:06 +02:00
parent ed555c1f32
commit 5df3e1dbd3

View File

@@ -347,29 +347,34 @@ CREATE OR REPLACE FUNCTION process_logbook_queue_fn(IN _id integer) RETURNS void
SET SET
track_geojson = geojson track_geojson = geojson
WHERE id = logbook_rec.id; WHERE id = logbook_rec.id;
-- Add moorage name as note for the second and last entry of the GeoJSON
-- Update the note properties of the second feature with geometry point -- Add moorage name as note for the third and last entry of the GeoJSON
select format('{"notes": "%s"}', from_moorage.moorage_name) into from_moorage_note; SELECT format('{"notes": "%s"}', from_moorage.moorage_name) into from_moorage_note;
-- Update the properties of the second feature with geometry point -- Update the properties of the third feature, the second with geometry point
UPDATE api.logbook UPDATE api.logbook
SET track_geojson = jsonb_set( SET track_geojson = jsonb_set(
track_geojson, track_geojson,
'{features, 1, properties, notes}', '{features, 2, properties}',
(track_geojson -> 'features' -> 1 -> 'properties' || from_moorage_note)::jsonb (track_geojson -> 'features' -> 2 -> 'properties' || from_moorage_note)::jsonb
) )
WHERE id = logbook_rec.id WHERE id = logbook_rec.id
AND track_geojson -> 'features' -> 1 -> 'geometry' ->> 'type' = 'Point'; AND track_geojson -> 'features' -> 2 -> 'geometry' ->> 'type' = 'Point';
-- Update the note properties of the last feature with geometry point -- Update the note properties of the last feature with geometry point
select format('{"notes": "%s"}', to_moorage.moorage_name) into to_moorage_note; SELECT format('{"notes": "%s"}', to_moorage.moorage_name) into to_moorage_note;
UPDATE api.logbook UPDATE api.logbook
SET track_geojson = jsonb_set( SET track_geojson = jsonb_set(
track_geojson, track_geojson,
'{features, -1, properties, notes}', '{features, -1, properties}',
(track_geojson -> 'features' -> -1 -> 'properties' || to_moorage_note)::jsonb CASE
) WHEN COALESCE((track_geojson -> 'features' -> -1 -> 'properties' ->> 'notes'), '') = '' THEN
WHERE id = logbook_rec.id (track_geojson -> 'features' -> -1 -> 'properties' || to_moorage_note)::jsonb
AND track_geojson -> 'features' -> -1 -> 'geometry' ->> 'type' = 'Point'; ELSE
track_geojson -> 'features' -> -1 -> 'properties'
END
)
WHERE id = logbook_rec.id
AND track_geojson -> 'features' -> -1 -> 'geometry' ->> 'type' = 'Point';
-- Prepare notification, gather user settings -- Prepare notification, gather user settings
SELECT json_build_object('logbook_name', log_name, 'logbook_link', logbook_rec.id) into log_settings; SELECT json_build_object('logbook_name', log_name, 'logbook_link', logbook_rec.id) into log_settings;