Skip to content

Commit cd0e42a

Browse files
committed
fix(#3733): blank page when dRep have @value in uri or label references
1 parent 12ace05 commit cd0e42a

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

govtool/backend/sql/list-dreps.sql

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ HasNonDeregisterVotingAnchor AS (
9595
EXISTS (
9696
SELECT 1
9797
FROM drep_registration dr_sub
98-
WHERE
98+
WHERE
9999
dr_sub.drep_hash_id = dr.drep_hash_id
100100
AND dr_sub.voting_anchor_id IS NULL
101101
AND COALESCE(dr_sub.deposit, 0) >= 0
@@ -129,12 +129,25 @@ DRepData AS (
129129
off_chain_vote_drep_data.image_hash,
130130
COALESCE(
131131
(
132-
SELECT jsonb_agg(ref)
132+
SELECT jsonb_agg(
133+
jsonb_build_object(
134+
'uri', COALESCE(
135+
CASE WHEN jsonb_typeof(ref->'uri') = 'string' THEN ref->>'uri' END,
136+
ref->'uri'->>'@value',
137+
ref->>'@value'
138+
),
139+
'@type', ref->>'@type',
140+
'label', COALESCE(
141+
CASE WHEN jsonb_typeof(ref->'label') = 'string' THEN ref->>'label' END,
142+
ref->'label'->>'@value'
143+
)
144+
)
145+
)
133146
FROM jsonb_array_elements(
134-
CASE
135-
WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL
136-
THEN (ocvd.json::jsonb)->'body'->'references'
137-
ELSE '[]'::jsonb
147+
CASE
148+
WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL
149+
THEN (ocvd.json::jsonb)->'body'->'references'
150+
ELSE '[]'::jsonb
138151
END
139152
) AS ref
140153
WHERE ref->>'@type' = 'Identity'
@@ -143,12 +156,25 @@ DRepData AS (
143156
) AS identity_references,
144157
COALESCE(
145158
(
146-
SELECT jsonb_agg(ref)
159+
SELECT jsonb_agg(
160+
jsonb_build_object(
161+
'uri', COALESCE(
162+
CASE WHEN jsonb_typeof(ref->'uri') = 'string' THEN ref->>'uri' END,
163+
ref->'uri'->>'@value',
164+
ref->>'@value'
165+
),
166+
'@type', ref->>'@type',
167+
'label', COALESCE(
168+
CASE WHEN jsonb_typeof(ref->'label') = 'string' THEN ref->>'label' END,
169+
ref->'label'->>'@value'
170+
)
171+
)
172+
)
147173
FROM jsonb_array_elements(
148-
CASE
149-
WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL
150-
THEN (ocvd.json::jsonb)->'body'->'references'
151-
ELSE '[]'::jsonb
174+
CASE
175+
WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL
176+
THEN (ocvd.json::jsonb)->'body'->'references'
177+
ELSE '[]'::jsonb
152178
END
153179
) AS ref
154180
WHERE ref->>'@type' = 'Link'
@@ -185,7 +211,7 @@ DRepData AS (
185211
LEFT JOIN FetchError fetch_error ON fetch_error.voting_anchor_id = leva.voting_anchor_id
186212
LEFT JOIN HasNonDeregisterVotingAnchor hndva ON hndva.drep_hash_id = dh.id
187213
LEFT JOIN off_chain_vote_data ocvd ON ocvd.voting_anchor_id = leva.voting_anchor_id
188-
LEFT JOIN off_chain_vote_drep_data ON off_chain_vote_drep_data.off_chain_vote_data_id = ocvd.id
214+
LEFT JOIN off_chain_vote_drep_data ON off_chain_vote_drep_data.off_chain_vote_data_id = ocvd.id
189215
LEFT JOIN voting_procedure ON voting_procedure.drep_voter = dh.id
190216
LEFT JOIN tx voting_procedure_transaction ON voting_procedure_transaction.id = voting_procedure.tx_id
191217
LEFT JOIN block voting_procedure_block ON voting_procedure_block.id = voting_procedure_transaction.block_id
@@ -244,21 +270,21 @@ DRepData AS (
244270
(
245271
SELECT jsonb_agg(ref)
246272
FROM jsonb_array_elements(
247-
CASE
248-
WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL
249-
THEN (ocvd.json::jsonb)->'body'->'references'
250-
ELSE '[]'::jsonb
273+
CASE
274+
WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL
275+
THEN (ocvd.json::jsonb)->'body'->'references'
276+
ELSE '[]'::jsonb
251277
END
252278
) AS ref
253279
WHERE ref->>'@type' = 'Identity'
254280
),
255281
(
256282
SELECT jsonb_agg(ref)
257283
FROM jsonb_array_elements(
258-
CASE
259-
WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL
260-
THEN (ocvd.json::jsonb)->'body'->'references'
261-
ELSE '[]'::jsonb
284+
CASE
285+
WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL
286+
THEN (ocvd.json::jsonb)->'body'->'references'
287+
ELSE '[]'::jsonb
262288
END
263289
) AS ref
264290
WHERE ref->>'@type' = 'Link'
@@ -275,4 +301,4 @@ WHERE
275301
objectives ILIKE ? OR
276302
motivations ILIKE ? OR
277303
qualifications ILIKE ?
278-
)
304+
)

0 commit comments

Comments
 (0)