Skip to content

Commit aebd702

Browse files
committed
fix: submission link to date query and registrants details sql
1 parent 99377f6 commit aebd702

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

sql/reports/topgear/topgear-registrants-details.sql

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ proj AS (
5858
p."billingAccountId"::bigint AS project_billing_account_id
5959
FROM projects.projects p
6060
),
61+
proj_phase_end AS (
62+
SELECT
63+
pp."projectId"::bigint AS project_id, -- cast to text to match base.project_id
64+
MAX(pp."endDate") AS project_scheduled_end_date
65+
FROM projects."project_phases" pp
66+
WHERE pp.status ILIKE 'planned'
67+
GROUP BY pp."projectId"
68+
),
6169
registrants AS (
6270
SELECT
6371
r."challengeId" AS challenge_id,
@@ -82,7 +90,7 @@ SELECT
8290
proj.group_customer_name AS "Customer name",
8391
reg.registrant_email AS "Registrant email",
8492
CASE WHEN base.challenge_status = 'ACTIVE'
85-
THEN base.planned_end_at END AS "Project scheduled end date",
93+
THEN ppe.project_scheduled_end_date END AS "Project scheduled end date",
8694
sub.best_final_score AS "Submission score"
8795
FROM base
8896
JOIN registrants reg
@@ -100,11 +108,24 @@ LEFT JOIN billing b
100108
ON b.challenge_id = base.challenge_id
101109
LEFT JOIN proj
102110
ON proj.project_id = base.project_id
111+
LEFT JOIN proj_phase_end ppe
112+
ON ppe.project_id = base.project_id
103113
WHERE
104114
COALESCE(b.billing_account_id, proj.project_billing_account_id) = 80000062
105115
AND COALESCE(
106116
CASE WHEN base.challenge_status = 'COMPLETED' THEN lp.last_phase_end END,
107117
base.planned_end_at,
108118
base.challenge_created_at
109119
) BETWEEN $1::timestamptz AND $2::timestamptz
120+
AND (
121+
(base.challenge_status = 'COMPLETED'
122+
AND lp.last_phase_end ) BETWEEN $1::timestamptz AND $2::timestamptz
123+
)
124+
OR
125+
(base.challenge_status = 'ACTIVE' AND (
126+
base.challenge_created_at ) BETWEEN $1::timestamptz AND $2::timestamptz
127+
OR base.challenge_updated_at ) BETWEEN $1::timestamptz AND $2::timestamptz
128+
OR base.planned_end_at ) BETWEEN $1::timestamptz AND $2::timestamptz
129+
))
130+
)
110131
ORDER BY base.challenge_id DESC, reg.registrant_handle;

src/reports/challenges/dtos/submission-links.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class SubmissionLinksQueryDto {
2525
})
2626
@IsOptional()
2727
@IsDateString()
28+
@Transform(({ value }) => value || new Date().toISOString())
2829
completionDateTo?: Date;
2930

3031
@ApiProperty({

0 commit comments

Comments
 (0)