mirror of
https://github.com/xbgmsharp/postgsail.git
synced 2025-09-17 19:27:49 +00:00
Update badges, renew badge
This commit is contained in:
@@ -36,7 +36,8 @@ INSERT INTO geocoders VALUES
|
||||
---------------------------------------------------------------------------
|
||||
-- Tables for message template email/pushover/telegram
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS email_templates(
|
||||
DROP TABLE IF EXISTS public.email_templates;
|
||||
CREATE TABLE IF NOT EXISTS public.email_templates(
|
||||
name TEXT UNIQUE,
|
||||
email_subject TEXT,
|
||||
email_content TEXT,
|
||||
@@ -184,7 +185,7 @@ COMMENT ON COLUMN public.app_settings.value IS 'application settings value';
|
||||
---------------------------------------------------------------------------
|
||||
-- Badges description
|
||||
--
|
||||
DROP FUNCTION IF EXISTS public.badges;
|
||||
DROP TABLE IF EXISTS public.badges;
|
||||
CREATE TABLE IF NOT EXISTS public.badges(
|
||||
name TEXT UNIQUE,
|
||||
description TEXT
|
||||
@@ -216,13 +217,14 @@ INSERT INTO badges VALUES
|
||||
('Aloha Award',
|
||||
'Ticking off over 2300 NM across the great blue Pacific makes you the rare recipient of the Aloha Award. Well done and Aloha sailor!'),
|
||||
('Navigator Award',
|
||||
'You made it, Ticking off over 100NM in one go, well done sailor!'),
|
||||
('Long-distance Award',
|
||||
'Woohoo! You made it, Ticking off over 100NM in one go, well done sailor!'),
|
||||
('Captain Award',
|
||||
'Congratulation, you reach over 1000NM, well done sailor!');
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- aistypes description
|
||||
--
|
||||
DROP TABLE IF EXISTS public.aistypes;
|
||||
CREATE TABLE IF NOT EXISTS aistypes(
|
||||
id NUMERIC UNIQUE,
|
||||
description TEXT
|
||||
@@ -318,7 +320,8 @@ INSERT INTO aistypes VALUES
|
||||
---------------------------------------------------------------------------
|
||||
-- MMSI MID Codes
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS mid(
|
||||
DROP TABLE IF EXISTS public.mid;
|
||||
CREATE TABLE IF NOT EXISTS public.mid(
|
||||
country TEXT,
|
||||
id NUMERIC UNIQUE,
|
||||
country_id INTEGER
|
||||
@@ -621,7 +624,8 @@ INSERT INTO mid VALUES
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS iso3166(
|
||||
DROP TABLE IF EXISTS public.iso3166;
|
||||
CREATE TABLE IF NOT EXISTS public.iso3166(
|
||||
id INTEGER,
|
||||
country TEXT,
|
||||
alpha_2 TEXT,
|
||||
|
@@ -903,13 +903,13 @@ CREATE OR REPLACE FUNCTION public.badges_logbook_fn(IN logbook_id integer) RETUR
|
||||
end if;
|
||||
end if;
|
||||
|
||||
-- Long-distance sailing = total logbook distance over 1000NM
|
||||
SELECT (preferences->'badges'->'Long-distance sailing') IS NOT NULL INTO _exist FROM auth.accounts a WHERE a.email = current_setting('user.email', false);
|
||||
-- Captain Award = total logbook distance over 1000NM
|
||||
SELECT (preferences->'badges'->'Captain Award') IS NOT NULL INTO _exist FROM auth.accounts a WHERE a.email = current_setting('user.email', false);
|
||||
if _exist is false then
|
||||
select sum(l.distance) into distance from api.logbook l where client_id = current_setting('vessel.client_id', false);
|
||||
if distance >= 1000 then
|
||||
-- Create badge
|
||||
badge := '{"Long-distance sailing": {"log": '|| logbook_id ||', "date":"' || NOW()::timestamp || '"}}';
|
||||
badge := '{"Captain Award": {"log": '|| logbook_id ||', "date":"' || NOW()::timestamp || '"}}';
|
||||
-- Get existing badges
|
||||
SELECT preferences->'badges' INTO _badges FROM auth.accounts a WHERE a.email = current_setting('user.email', false);
|
||||
-- Merge badges
|
||||
@@ -918,7 +918,7 @@ CREATE OR REPLACE FUNCTION public.badges_logbook_fn(IN logbook_id integer) RETUR
|
||||
PERFORM api.update_user_preferences_fn('{badges}'::TEXT, badge::TEXT);
|
||||
-- Gather user settings
|
||||
user_settings := get_user_settings_from_clientid_fn(current_setting('vessel.client_id', false));
|
||||
SELECT user_settings::JSONB || '{"badge": "Long-distance sailing"}'::JSONB into user_settings;
|
||||
SELECT user_settings::JSONB || '{"badge": "Captain Award"}'::JSONB into user_settings;
|
||||
-- Send notification
|
||||
PERFORM send_notification_fn('badge'::TEXT, user_settings::JSONB);
|
||||
end if;
|
||||
|
Reference in New Issue
Block a user