mirror of
https://github.com/xbgmsharp/postgsail.git
synced 2025-09-17 11:17:46 +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
|
-- 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,
|
name TEXT UNIQUE,
|
||||||
email_subject TEXT,
|
email_subject TEXT,
|
||||||
email_content TEXT,
|
email_content TEXT,
|
||||||
@@ -184,7 +185,7 @@ COMMENT ON COLUMN public.app_settings.value IS 'application settings value';
|
|||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
-- Badges description
|
-- Badges description
|
||||||
--
|
--
|
||||||
DROP FUNCTION IF EXISTS public.badges;
|
DROP TABLE IF EXISTS public.badges;
|
||||||
CREATE TABLE IF NOT EXISTS public.badges(
|
CREATE TABLE IF NOT EXISTS public.badges(
|
||||||
name TEXT UNIQUE,
|
name TEXT UNIQUE,
|
||||||
description TEXT
|
description TEXT
|
||||||
@@ -216,13 +217,14 @@ INSERT INTO badges VALUES
|
|||||||
('Aloha Award',
|
('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!'),
|
'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',
|
('Navigator Award',
|
||||||
'You made it, Ticking off over 100NM in one go, well done sailor!'),
|
'Woohoo! You made it, Ticking off over 100NM in one go, well done sailor!'),
|
||||||
('Long-distance Award',
|
('Captain Award',
|
||||||
'Congratulation, you reach over 1000NM, well done sailor!');
|
'Congratulation, you reach over 1000NM, well done sailor!');
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
-- aistypes description
|
-- aistypes description
|
||||||
--
|
--
|
||||||
|
DROP TABLE IF EXISTS public.aistypes;
|
||||||
CREATE TABLE IF NOT EXISTS aistypes(
|
CREATE TABLE IF NOT EXISTS aistypes(
|
||||||
id NUMERIC UNIQUE,
|
id NUMERIC UNIQUE,
|
||||||
description TEXT
|
description TEXT
|
||||||
@@ -318,7 +320,8 @@ INSERT INTO aistypes VALUES
|
|||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
-- MMSI MID Codes
|
-- MMSI MID Codes
|
||||||
--
|
--
|
||||||
CREATE TABLE IF NOT EXISTS mid(
|
DROP TABLE IF EXISTS public.mid;
|
||||||
|
CREATE TABLE IF NOT EXISTS public.mid(
|
||||||
country TEXT,
|
country TEXT,
|
||||||
id NUMERIC UNIQUE,
|
id NUMERIC UNIQUE,
|
||||||
country_id INTEGER
|
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,
|
id INTEGER,
|
||||||
country TEXT,
|
country TEXT,
|
||||||
alpha_2 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;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
-- Long-distance sailing = total logbook distance over 1000NM
|
-- Captain Award = 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);
|
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
|
if _exist is false then
|
||||||
select sum(l.distance) into distance from api.logbook l where client_id = current_setting('vessel.client_id', false);
|
select sum(l.distance) into distance from api.logbook l where client_id = current_setting('vessel.client_id', false);
|
||||||
if distance >= 1000 then
|
if distance >= 1000 then
|
||||||
-- Create badge
|
-- Create badge
|
||||||
badge := '{"Long-distance sailing": {"log": '|| logbook_id ||', "date":"' || NOW()::timestamp || '"}}';
|
badge := '{"Captain Award": {"log": '|| logbook_id ||', "date":"' || NOW()::timestamp || '"}}';
|
||||||
-- Get existing badges
|
-- Get existing badges
|
||||||
SELECT preferences->'badges' INTO _badges FROM auth.accounts a WHERE a.email = current_setting('user.email', false);
|
SELECT preferences->'badges' INTO _badges FROM auth.accounts a WHERE a.email = current_setting('user.email', false);
|
||||||
-- Merge badges
|
-- 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);
|
PERFORM api.update_user_preferences_fn('{badges}'::TEXT, badge::TEXT);
|
||||||
-- Gather user settings
|
-- Gather user settings
|
||||||
user_settings := get_user_settings_from_clientid_fn(current_setting('vessel.client_id', false));
|
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
|
-- Send notification
|
||||||
PERFORM send_notification_fn('badge'::TEXT, user_settings::JSONB);
|
PERFORM send_notification_fn('badge'::TEXT, user_settings::JSONB);
|
||||||
end if;
|
end if;
|
||||||
|
Reference in New Issue
Block a user