aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_get_notifications_user_js
Description
Modify by KenG (2020/05/19)
Parameters
Name
Type
Mode
i_username
text
IN (DEFAULT NULL)
Definition
declare json_result json; current_username text; begin if (i_username is not null) then current_username = i_username; else current_username = fn_current_user(); end if; select jsonb_agg(dataset) from ( select n.id, n.notify_type as ref_type, case when n.notify_type = 'followup' then nf.followup_id when n.notify_type = 'booking' then n.ref_id end as ref_id, case when n.notify_type = 'followup' then f.title else n.notify_titile end as title, case when n.notify_type = 'followup' then f.create_user else n.create_user end as create_user, case when n.notify_type = 'followup' then f.profile_user else n.profile_user end as profile_user, n.notify_message, n.notify_date, n.notify_user from notification as n left join notification_followup as nf on n.id = nf.notification_id left join followup as f on nf.followup_id = f.id where (LOWER(n.notify_user) = LOWER(current_username)) order by n.notify_date desc limit 200 ) as dataset into json_result; return coalesce(json_result, '[]'); END;