feat: update API and database structure for membership confirmation and wallet integration

- Refactor API calls to use 'medreport' schema for membership confirmation and account updates
- Enhance success notification component to include wallet balance and expiration details
- Modify database types to reflect new 'medreport' schema and add product-related tables
- Update localization files to support new wallet messages
- Adjust SQL migration scripts for proper schema references and function definitions
This commit is contained in:
Danel Kungla
2025-07-09 10:01:12 +03:00
parent 4f36f9c037
commit 9371ff7710
6 changed files with 234 additions and 452 deletions

View File

@@ -1,342 +0,0 @@
drop trigger if exists "check_not_already_tied_to_connected_online" on "public"."medreport_products_analyses_relations";
drop trigger if exists "check_not_already_tied_to_analysis" on "public"."medreport_products_external_services_relations";
drop policy "read_all" on "public"."medreport_product_groups";
drop policy "Enable read access for all users" on "public"."medreport_products_analyses_relations";
revoke delete on table "public"."medreport_product_groups" from "anon";
revoke insert on table "public"."medreport_product_groups" from "anon";
revoke references on table "public"."medreport_product_groups" from "anon";
revoke select on table "public"."medreport_product_groups" from "anon";
revoke trigger on table "public"."medreport_product_groups" from "anon";
revoke truncate on table "public"."medreport_product_groups" from "anon";
revoke update on table "public"."medreport_product_groups" from "anon";
revoke delete on table "public"."medreport_product_groups" from "authenticated";
revoke insert on table "public"."medreport_product_groups" from "authenticated";
revoke references on table "public"."medreport_product_groups" from "authenticated";
revoke select on table "public"."medreport_product_groups" from "authenticated";
revoke trigger on table "public"."medreport_product_groups" from "authenticated";
revoke truncate on table "public"."medreport_product_groups" from "authenticated";
revoke update on table "public"."medreport_product_groups" from "authenticated";
revoke delete on table "public"."medreport_product_groups" from "service_role";
revoke insert on table "public"."medreport_product_groups" from "service_role";
revoke references on table "public"."medreport_product_groups" from "service_role";
revoke select on table "public"."medreport_product_groups" from "service_role";
revoke trigger on table "public"."medreport_product_groups" from "service_role";
revoke truncate on table "public"."medreport_product_groups" from "service_role";
revoke update on table "public"."medreport_product_groups" from "service_role";
revoke delete on table "public"."medreport_products_analyses_relations" from "anon";
revoke insert on table "public"."medreport_products_analyses_relations" from "anon";
revoke references on table "public"."medreport_products_analyses_relations" from "anon";
revoke select on table "public"."medreport_products_analyses_relations" from "anon";
revoke trigger on table "public"."medreport_products_analyses_relations" from "anon";
revoke truncate on table "public"."medreport_products_analyses_relations" from "anon";
revoke update on table "public"."medreport_products_analyses_relations" from "anon";
revoke delete on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke insert on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke references on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke select on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke trigger on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke truncate on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke update on table "public"."medreport_products_analyses_relations" from "authenticated";
revoke delete on table "public"."medreport_products_analyses_relations" from "service_role";
revoke insert on table "public"."medreport_products_analyses_relations" from "service_role";
revoke references on table "public"."medreport_products_analyses_relations" from "service_role";
revoke select on table "public"."medreport_products_analyses_relations" from "service_role";
revoke trigger on table "public"."medreport_products_analyses_relations" from "service_role";
revoke truncate on table "public"."medreport_products_analyses_relations" from "service_role";
revoke update on table "public"."medreport_products_analyses_relations" from "service_role";
revoke delete on table "public"."medreport_products_external_services_relations" from "anon";
revoke insert on table "public"."medreport_products_external_services_relations" from "anon";
revoke references on table "public"."medreport_products_external_services_relations" from "anon";
revoke select on table "public"."medreport_products_external_services_relations" from "anon";
revoke trigger on table "public"."medreport_products_external_services_relations" from "anon";
revoke truncate on table "public"."medreport_products_external_services_relations" from "anon";
revoke update on table "public"."medreport_products_external_services_relations" from "anon";
revoke delete on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke insert on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke references on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke select on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke trigger on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke truncate on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke update on table "public"."medreport_products_external_services_relations" from "authenticated";
revoke delete on table "public"."medreport_products_external_services_relations" from "service_role";
revoke insert on table "public"."medreport_products_external_services_relations" from "service_role";
revoke references on table "public"."medreport_products_external_services_relations" from "service_role";
revoke select on table "public"."medreport_products_external_services_relations" from "service_role";
revoke trigger on table "public"."medreport_products_external_services_relations" from "service_role";
revoke truncate on table "public"."medreport_products_external_services_relations" from "service_role";
revoke update on table "public"."medreport_products_external_services_relations" from "service_role";
alter table "public"."medreport_product_groups" drop constraint "medreport_product_groups_name_key";
alter table "public"."medreport_products" drop constraint "medreport_products_product_groups_id_fkey";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_analysis_element_id_fkey";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_analysis_element_id_key";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_analysis_id_fkey";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_analysis_id_key";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_product_id_fkey";
alter table "public"."medreport_products_analyses_relations" drop constraint "product_can_be_tied_to_only_one_analysis_item";
alter table "public"."medreport_products_analyses_relations" drop constraint "product_can_be_tied_to_only_one_external_item";
alter table "public"."medreport_products_external_services_relations" drop constraint "medreport_products_connected_online_services_id_fkey";
alter table "public"."medreport_products_external_services_relations" drop constraint "medreport_products_connected_online_services_id_key";
alter table "public"."medreport_products_external_services_relations" drop constraint "medreport_products_connected_online_services_product_id_fkey";
alter table "public"."medreport_product_groups" drop constraint "medreport_product_groups_pkey";
alter table "public"."medreport_products_analyses_relations" drop constraint "medreport_products_analyses_pkey";
alter table "public"."medreport_products_external_services_relations" drop constraint "medreport_products_connected_online_services_pkey";
drop index if exists "public"."medreport_product_groups_name_key";
drop index if exists "public"."medreport_product_groups_pkey";
drop index if exists "public"."medreport_products_analyses_pkey";
drop index if exists "public"."medreport_products_analyses_analysis_element_id_key";
drop index if exists "public"."medreport_products_analyses_analysis_id_key";
drop index if exists "public"."medreport_products_connected_online_services_id_key";
drop index if exists "public"."medreport_products_connected_online_services_pkey";
drop table "public"."medreport_product_groups";
drop table "public"."medreport_products_analyses_relations";
drop table "public"."medreport_products_external_services_relations";
create table "public"."medusa_products_analyses_relations" (
"medusa_product_id" bigint not null,
"analysis_element_id" bigint,
"analysis_id" bigint
);
alter table "public"."medusa_products_analyses_relations" enable row level security;
create table "public"."medusa_products_external_services_relations" (
"medusa_product_id" bigint not null,
"connected_online_service_id" bigint not null
);
alter table "public"."medusa_products_external_services_relations" enable row level security;
CREATE UNIQUE INDEX medusa_products_analyses_relations_pkey ON public.medusa_products_analyses_relations USING btree (medusa_product_id);
CREATE UNIQUE INDEX medusa_products_external_services_relations_product_id_key ON public.medusa_products_external_services_relations USING btree (medusa_product_id);
CREATE UNIQUE INDEX medreport_products_analyses_analysis_element_id_key ON public.medusa_products_analyses_relations USING btree (analysis_element_id);
CREATE UNIQUE INDEX medreport_products_analyses_analysis_id_key ON public.medusa_products_analyses_relations USING btree (analysis_id);
CREATE UNIQUE INDEX medreport_products_connected_online_services_id_key ON public.medusa_products_external_services_relations USING btree (connected_online_service_id);
CREATE UNIQUE INDEX medreport_products_connected_online_services_pkey ON public.medusa_products_external_services_relations USING btree (connected_online_service_id);
alter table "public"."medusa_products_analyses_relations" add constraint "medusa_products_analyses_relations_pkey" PRIMARY KEY using index "medusa_products_analyses_relations_pkey";
alter table "public"."medusa_products_external_services_relations" add constraint "medreport_products_connected_online_services_pkey" PRIMARY KEY using index "medreport_products_connected_online_services_pkey";
alter table "public"."medusa_products_analyses_relations" add constraint "medreport_products_analyses_analysis_element_id_fkey" FOREIGN KEY (analysis_element_id) REFERENCES analysis_elements(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."medusa_products_analyses_relations" validate constraint "medreport_products_analyses_analysis_element_id_fkey";
alter table "public"."medusa_products_analyses_relations" add constraint "medreport_products_analyses_analysis_element_id_key" UNIQUE using index "medreport_products_analyses_analysis_element_id_key";
alter table "public"."medusa_products_analyses_relations" add constraint "medreport_products_analyses_analysis_id_fkey" FOREIGN KEY (analysis_id) REFERENCES analyses(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."medusa_products_analyses_relations" validate constraint "medreport_products_analyses_analysis_id_fkey";
alter table "public"."medusa_products_analyses_relations" add constraint "medreport_products_analyses_analysis_id_key" UNIQUE using index "medreport_products_analyses_analysis_id_key";
alter table "public"."medusa_products_analyses_relations" add constraint "medreport_products_analyses_product_id_fkey" FOREIGN KEY (medusa_product_id) REFERENCES medreport_products(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."medusa_products_analyses_relations" validate constraint "medreport_products_analyses_product_id_fkey";
alter table "public"."medusa_products_analyses_relations" add constraint "product_can_be_tied_to_only_one_analysis_item" CHECK (((analysis_id IS NULL) OR (analysis_element_id IS NULL))) not valid;
alter table "public"."medusa_products_analyses_relations" validate constraint "product_can_be_tied_to_only_one_analysis_item";
alter table "public"."medusa_products_analyses_relations" add constraint "product_can_be_tied_to_only_one_external_item" CHECK (((analysis_id IS NULL) OR (analysis_element_id IS NULL))) not valid;
alter table "public"."medusa_products_analyses_relations" validate constraint "product_can_be_tied_to_only_one_external_item";
alter table "public"."medusa_products_external_services_relations" add constraint "medreport_products_connected_online_services_id_fkey" FOREIGN KEY (connected_online_service_id) REFERENCES connected_online_services(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."medusa_products_external_services_relations" validate constraint "medreport_products_connected_online_services_id_fkey";
alter table "public"."medusa_products_external_services_relations" add constraint "medreport_products_connected_online_services_id_key" UNIQUE using index "medreport_products_connected_online_services_id_key";
alter table "public"."medusa_products_external_services_relations" add constraint "medreport_products_connected_online_services_product_id_fkey" FOREIGN KEY (medusa_product_id) REFERENCES medreport_products(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."medusa_products_external_services_relations" validate constraint "medreport_products_connected_online_services_product_id_fkey";
alter table "public"."medusa_products_external_services_relations" add constraint "medusa_products_external_services_relations_product_id_key" UNIQUE using index "medusa_products_external_services_relations_product_id_key";
grant delete on table "public"."medusa_products_analyses_relations" to "service_role";
grant insert on table "public"."medusa_products_analyses_relations" to "service_role";
grant references on table "public"."medusa_products_analyses_relations" to "service_role";
grant select on table "public"."medusa_products_analyses_relations" to "service_role";
grant trigger on table "public"."medusa_products_analyses_relations" to "service_role";
grant truncate on table "public"."medusa_products_analyses_relations" to "service_role";
grant update on table "public"."medusa_products_analyses_relations" to "service_role";
grant delete on table "public"."medusa_products_external_services_relations" to "service_role";
grant insert on table "public"."medusa_products_external_services_relations" to "service_role";
grant references on table "public"."medusa_products_external_services_relations" to "service_role";
grant select on table "public"."medusa_products_external_services_relations" to "service_role";
grant trigger on table "public"."medusa_products_external_services_relations" to "service_role";
grant truncate on table "public"."medusa_products_external_services_relations" to "service_role";
grant update on table "public"."medusa_products_external_services_relations" to "service_role";
CREATE TRIGGER check_not_already_tied_to_connected_online BEFORE INSERT OR UPDATE ON public.medusa_products_analyses_relations FOR EACH ROW EXECUTE FUNCTION check_tied_to_connected_online();
CREATE TRIGGER check_not_already_tied_to_analysis BEFORE INSERT OR UPDATE ON public.medusa_products_external_services_relations FOR EACH ROW EXECUTE FUNCTION check_tied_to_analysis_item();
revoke delete on table "public"."medreport_products" from "anon";
revoke insert on table "public"."medreport_products" from "anon";
revoke references on table "public"."medreport_products" from "anon";
revoke select on table "public"."medreport_products" from "anon";
revoke trigger on table "public"."medreport_products" from "anon";
revoke truncate on table "public"."medreport_products" from "anon";
revoke update on table "public"."medreport_products" from "anon";
revoke delete on table "public"."medreport_products" from "authenticated";
revoke insert on table "public"."medreport_products" from "authenticated";
revoke references on table "public"."medreport_products" from "authenticated";
revoke select on table "public"."medreport_products" from "authenticated";
revoke trigger on table "public"."medreport_products" from "authenticated";
revoke truncate on table "public"."medreport_products" from "authenticated";
revoke update on table "public"."medreport_products" from "authenticated";
revoke delete on table "public"."medreport_products" from "service_role";
revoke insert on table "public"."medreport_products" from "service_role";
revoke references on table "public"."medreport_products" from "service_role";
revoke select on table "public"."medreport_products" from "service_role";
revoke trigger on table "public"."medreport_products" from "service_role";
revoke truncate on table "public"."medreport_products" from "service_role";
revoke update on table "public"."medreport_products" from "service_role";
alter table "public"."medreport_products" drop constraint "medreport_products_name_key";
alter table "public"."medusa_products_analyses_relations" drop constraint "medreport_products_analyses_product_id_fkey";
alter table "public"."medusa_products_external_services_relations" drop constraint "medreport_products_connected_online_services_product_id_fkey";
alter table "public"."medreport_products" drop constraint "medreport_products_pkey";
drop index if exists "public"."medreport_products_name_key";
drop index if exists "public"."medreport_products_pkey";
drop table "public"."medreport_products";

View File

@@ -1,28 +1,28 @@
alter table "public"."accounts_memberships" add column "has_seen_confirmation" boolean not null default false;
alter table "medreport"."accounts_memberships" add column "has_seen_confirmation" boolean not null default false;
set check_function_bodies = off;
CREATE OR REPLACE FUNCTION public.has_unseen_membership_confirmation(p_user_id uuid DEFAULT auth.uid())
CREATE OR REPLACE FUNCTION medreport.has_unseen_membership_confirmation(p_user_id uuid DEFAULT auth.uid())
RETURNS boolean
LANGUAGE sql
SECURITY DEFINER
SET search_path TO 'public', 'extensions'
SET search_path TO 'medreport', 'extensions'
AS $function$
select exists (
select 1
from public.accounts_memberships am
from medreport.accounts_memberships am
where am.user_id = p_user_id
and am.has_seen_confirmation = false
);
$function$
;
grant execute on function public.has_unseen_membership_confirmation(uuid)
grant execute on function medreport.has_unseen_membership_confirmation(uuid)
to authenticated, anon;
drop function if exists "public"."has_personal_code"(account_id uuid);
drop function if exists "medreport"."has_personal_code"(account_id uuid);
CREATE OR REPLACE FUNCTION public.has_consent_personal_data(account_id uuid)
CREATE OR REPLACE FUNCTION medreport.has_consent_personal_data(account_id uuid)
RETURNS boolean
LANGUAGE plpgsql
SECURITY DEFINER
@@ -30,12 +30,12 @@ CREATE OR REPLACE FUNCTION public.has_consent_personal_data(account_id uuid)
AS $function$BEGIN
RETURN EXISTS (
SELECT 1
FROM public.accounts
FROM medreport.accounts
WHERE id = account_id
AND has_consent_personal_data IS TRUE
);
END;$function$
;
grant execute on function public.has_consent_personal_data(uuid)
grant execute on function medreport.has_consent_personal_data(uuid)
to authenticated, anon;