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; result_property_data json; v_prop_id integer; v_prop_name text; v_company text; v_tax_id 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_tax_id := p_data ->> 'tax_id'; 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(v_log_base64, 'base64'); else v_logo_data := null; end if; 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, ''), is_public => true ); end if; update property_info p set "name" = v_prop_name, company = v_company, tax_id = v_tax_id, 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 = coalesce(v_logo_url, p.logo_url) where p.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, 'tax_id', pi.tax_id, '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_url', pi.logo_url ) into result_property_data from property_info pi where pi.prop_id = v_prop_id; 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;