aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_update_propertyinfo_json
Parameters
Name
Type
Mode
p_data
jsonb
IN
Definition
DECLARE v_msg_text text; v_sqlstate text; v_detail text; v_hint text; v_context text; property_data record; result_property_data json; v_prop_id integer; v_prop_name text; v_company text; v_logo_data bytea; v_logo_type text ; v_address1 text ; v_address2 text ; v_address3 text ; v_address4 text ; v_email text ; v_telephone text ; v_fax text; v_website text; v_prop_code text; v_logo_path text; v_logo_url text; v_file_ext text; v_content_type text; v_log_base64 text; begin v_prop_id := (p_data ->> 'prop_id')::int4; v_prop_name := p_data ->> 'prop_name'; v_company := p_data ->> 'company'; v_log_base64 := p_data ->> 'logo'; v_address1 := p_data ->> 'address1'; v_address2 := p_data ->> 'address2'; v_address3 := p_data ->> 'address3'; v_address4 := p_data ->> 'address4'; v_email := p_data ->> 'email'; v_telephone := p_data ->> 'telephone'; v_fax := p_data ->> 'fax'; v_website := p_data ->> 'website'; v_logo_type := p_data ->> 'logo_type'; if v_log_base64 is not null then v_logo_data := decode(p_data ->> 'logo', 'base64'); else v_logo_data := null; end if; -- ======================= -- call upload file to s3 -- ======================= if v_logo_data is not null then v_prop_code := fn_prop_code(); v_file_ext := case when v_logo_type like '%image/png%' then '.png' else '.jpg' end; v_content_type := case when v_logo_type like '%image/png%' then 'image/png' else 'image/jpeg' end; v_logo_path := v_prop_code || '/logo/' || gen_random_uuid()::text || '_logo' || v_file_ext; v_logo_url := doc.s3_upload_file( file_path => coalesce(v_logo_path, '') , file_data => v_logo_data , content_type => coalesce(v_content_type, '') ); end if; -- ======================= -- update -- ======================= update property_info set "name" = v_prop_name, company = v_company, address1 = v_address1, address2 = v_address2, address3 = v_address3, address4 = v_address4, email = v_email, telephone = v_telephone, fax = v_fax, website = v_website, logo_url = v_logo_url, logo = v_logo_data where prop_id = v_prop_id; select json_build_object( 'prop_id', pi.prop_id, 'prop_code', pi.prop_code, 'prop_name', pi.name, 'company', pi.company, 'address1', pi.address1, 'address2', pi.address2, 'address3', pi.address3, 'address4', pi.address4, 'email', pi.email, 'telephone', pi.telephone, 'fax', pi.fax , 'website', pi.website , 'logo', pi.logo_url -- 'logo', format('https://%s.sgp1.cdn.digitaloceanspaces.com/%s', 'fromas', v_logo_path) ) into result_property_data from property_info pi; return fn_result_success(coalesce(result_property_data, '{}'::json)); EXCEPTION when others then GET STACKED DIAGNOSTICS v_msg_text = message_text, v_sqlstate = returned_sqlstate, v_detail = pg_exception_detail, v_hint = pg_exception_hint, v_context = pg_exception_context; return fn_handle_error( v_sqlstate, v_msg_text, v_detail, v_hint, v_context, 'sp_update_propertyinfo_json', null ); END;