B2B-86: add function to save order response (#11)

* fix import

* B2B-86: add function to save order response

* fix private message parsing

* generate new types

* clean up

* remove comment

---------

Co-authored-by: Helena <helena@Helenas-MacBook-Pro.local>
This commit is contained in:
Helena
2025-06-11 18:25:53 +03:00
committed by GitHub
parent 4aedc0b527
commit 0d560e5a02
5 changed files with 501 additions and 46 deletions

View File

@@ -346,28 +346,128 @@ export type Database = {
}
analysis_orders: {
Row: {
analysis_group_ids: number[] | null
analysis_element_ids: number[] | null
analysis_ids: number[] | null
created_at: string
id: string
id: number
status: Database["public"]["Enums"]["analysis_order_status"]
user_id: string
}
Insert: {
analysis_group_ids?: number[] | null
analysis_element_ids?: number[] | null
analysis_ids?: number[] | null
created_at?: string
id: string
id?: number
status: Database["public"]["Enums"]["analysis_order_status"]
user_id: string
}
Update: {
analysis_group_ids?: number[] | null
analysis_element_ids?: number[] | null
analysis_ids?: number[] | null
created_at?: string
id?: string
id?: number
status?: Database["public"]["Enums"]["analysis_order_status"]
user_id?: string
}
Relationships: []
}
analysis_response_elements: {
Row: {
analysis_element_original_id: string
analysis_response_id: number
created_at: string
id: number
norm_lower: number | null
norm_lower_included: boolean | null
norm_status: number | null
norm_upper: number | null
norm_upper_included: boolean | null
original_response_element: Json
response_time: string
response_value: Json
unit: string | null
updated_at: string | null
}
Insert: {
analysis_element_original_id: string
analysis_response_id: number
created_at?: string
id?: number
norm_lower?: number | null
norm_lower_included?: boolean | null
norm_status?: number | null
norm_upper?: number | null
norm_upper_included?: boolean | null
original_response_element: Json
response_time: string
response_value: Json
unit?: string | null
updated_at?: string | null
}
Update: {
analysis_element_original_id?: string
analysis_response_id?: number
created_at?: string
id?: number
norm_lower?: number | null
norm_lower_included?: boolean | null
norm_status?: number | null
norm_upper?: number | null
norm_upper_included?: boolean | null
original_response_element?: Json
response_time?: string
response_value?: Json
unit?: string | null
updated_at?: string | null
}
Relationships: [
{
foreignKeyName: "analysis_response_element_analysis_response_id_fkey"
columns: ["analysis_response_id"]
isOneToOne: false
referencedRelation: "analysis_responses"
referencedColumns: ["id"]
},
]
}
analysis_responses: {
Row: {
analysis_order_id: number
created_at: string
id: number
order_number: string
order_status: Database["public"]["Enums"]["analysis_order_status"]
updated_at: string | null
user_id: string
}
Insert: {
analysis_order_id: number
created_at?: string
id?: number
order_number: string
order_status: Database["public"]["Enums"]["analysis_order_status"]
updated_at?: string | null
user_id: string
}
Update: {
analysis_order_id?: number
created_at?: string
id?: number
order_number?: string
order_status?: Database["public"]["Enums"]["analysis_order_status"]
updated_at?: string | null
user_id?: string
}
Relationships: [
{
foreignKeyName: "analysis_responses_analysis_order_id_fkey"
columns: ["analysis_order_id"]
isOneToOne: false
referencedRelation: "analysis_orders"
referencedColumns: ["id"]
},
]
}
billing_customers: {
Row: {
account_id: string

View File

@@ -0,0 +1,129 @@
create table "public"."analysis_response_elements" (
"id" bigint generated by default as identity not null,
"analysis_response_id" bigint not null,
"analysis_element_original_id" text not null,
"unit" text,
"response_value" jsonb not null,
"response_time" timestamp with time zone not null,
"norm_upper" double precision,
"norm_upper_included" boolean,
"norm_lower" double precision,
"norm_lower_included" boolean,
"norm_status" smallint,
"original_response_element" jsonb not null,
"created_at" timestamp with time zone not null default now(),
"updated_at" timestamp with time zone default now()
);
alter table "public"."analysis_response_elements" enable row level security;
create table "public"."analysis_responses" (
"id" bigint generated by default as identity not null,
"analysis_order_id" bigint not null,
"order_number" text not null,
"order_status" analysis_order_status not null,
"user_id" uuid not null,
"created_at" timestamp with time zone not null default now(),
"updated_at" timestamp with time zone default now()
);
alter table "public"."analysis_responses" enable row level security;
CREATE UNIQUE INDEX analysis_response_element_pkey ON public.analysis_response_elements USING btree (id);
CREATE UNIQUE INDEX analysis_response_pkey ON public.analysis_responses USING btree (id);
CREATE UNIQUE INDEX analysis_responses_order_number_key ON public.analysis_responses USING btree (order_number);
alter table "public"."analysis_response_elements" add constraint "analysis_response_element_pkey" PRIMARY KEY using index "analysis_response_element_pkey";
alter table "public"."analysis_responses" add constraint "analysis_response_pkey" PRIMARY KEY using index "analysis_response_pkey";
alter table "public"."analysis_response_elements" add constraint "analysis_response_element_analysis_response_id_fkey" FOREIGN KEY (analysis_response_id) REFERENCES analysis_responses(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."analysis_response_elements" validate constraint "analysis_response_element_analysis_response_id_fkey";
alter table "public"."analysis_responses" add constraint "analysis_response_user_id_fkey" FOREIGN KEY (user_id) REFERENCES auth.users(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."analysis_responses" validate constraint "analysis_response_user_id_fkey";
alter table "public"."analysis_responses" add constraint "analysis_responses_order_number_key" UNIQUE using index "analysis_responses_order_number_key";
grant delete on table "public"."analysis_response_elements" to "service_role";
grant insert on table "public"."analysis_response_elements" to "service_role";
grant references on table "public"."analysis_response_elements" to "service_role";
grant select on table "public"."analysis_response_elements" to "service_role";
grant trigger on table "public"."analysis_response_elements" to "service_role";
grant truncate on table "public"."analysis_response_elements" to "service_role";
grant update on table "public"."analysis_response_elements" to "service_role";
grant delete on table "public"."analysis_responses" to "service_role";
grant insert on table "public"."analysis_responses" to "service_role";
grant references on table "public"."analysis_responses" to "service_role";
grant select on table "public"."analysis_responses" to "service_role";
grant trigger on table "public"."analysis_responses" to "service_role";
grant truncate on table "public"."analysis_responses" to "service_role";
grant update on table "public"."analysis_responses" to "service_role";
create policy "select_own"
on "public"."analysis_response_elements"
as permissive
for select
to authenticated
using ((( SELECT auth.uid() AS uid) IN ( SELECT analysis_responses.user_id
FROM analysis_responses
WHERE (analysis_responses.id = analysis_response_elements.analysis_response_id))));
create policy "service_role_all"
on "public"."analysis_response_elements"
as permissive
for all
to service_role
using (true);
create policy "select_own"
on "public"."analysis_responses"
as permissive
for select
to authenticated
using ((( SELECT auth.uid() AS uid) = user_id));
create policy "service_role_all"
on "public"."analysis_responses"
as permissive
for all
to service_role
using (true);
create policy "service_role_all"
on "public"."analysis_orders"
as permissive
for all
to service_role
using (true);
alter table "public"."analysis_orders" add constraint "analysis_orders_user_id_fkey" FOREIGN KEY (user_id) REFERENCES auth.users(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."analysis_orders" drop constraint "analysis_orders_id_fkey";
alter table "public"."analysis_orders" drop column "id";
alter table "public"."analysis_orders" add "id" bigint generated by default as identity not null;
CREATE UNIQUE INDEX analysis_orders_pkey ON public.analysis_orders USING btree (id);
alter table "public"."analysis_orders" add constraint "analysis_orders_pkey" PRIMARY KEY using index "analysis_orders_pkey";
alter table "public"."analysis_responses" add constraint "analysis_responses_analysis_order_id_fkey" FOREIGN KEY (analysis_order_id) REFERENCES analysis_orders(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;
alter table "public"."analysis_responses" validate constraint "analysis_responses_analysis_order_id_fkey";