-
Notifications
You must be signed in to change notification settings - Fork 0
Start / end dates to weekly member participation report #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,22 @@ | ||
| WITH window_bounds AS ( | ||
| WITH provided_dates AS ( | ||
| SELECT | ||
| (DATE_TRUNC('week', CURRENT_DATE) - INTERVAL '4 weeks') AS window_start, | ||
| (DATE_TRUNC('week', CURRENT_DATE) + INTERVAL '1 week') AS window_end | ||
| NULLIF($1, '')::timestamptz AS start_date, | ||
| NULLIF($2, '')::timestamptz AS end_date | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| ), | ||
| window_bounds AS ( | ||
| SELECT | ||
| COALESCE( | ||
| pd.start_date, | ||
| CASE | ||
| WHEN pd.end_date IS NOT NULL THEN pd.end_date - INTERVAL '5 weeks' | ||
| ELSE DATE_TRUNC('week', CURRENT_DATE) - INTERVAL '4 weeks' | ||
| END | ||
| ) AS window_start, | ||
| COALESCE( | ||
| pd.end_date, | ||
| DATE_TRUNC('week', CURRENT_DATE) + INTERVAL '1 week' | ||
| ) AS window_end | ||
| FROM provided_dates pd | ||
| ), | ||
| billing AS ( | ||
| SELECT | ||
|
|
@@ -18,7 +33,7 @@ billing AS ( | |
| LEFT JOIN projects.projects proj | ||
| ON proj.id::text = NULLIF(TRIM(c."projectId"::text), '') | ||
| LEFT JOIN "billing-accounts"."BillingAccount" project_ba | ||
| ON project_ba.id = proj."billingAccountId" | ||
| ON project_ba.id::text = NULLIF(TRIM(proj."billingAccountId"::text), '') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| GROUP BY c.id | ||
| ), | ||
| project_clients AS ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { ApiPropertyOptional } from "@nestjs/swagger"; | ||
| import { IsDateString, IsOptional } from "class-validator"; | ||
|
|
||
| export class WeeklyMemberParticipationQueryDto { | ||
| @ApiPropertyOptional({ | ||
| description: | ||
| "Start date (inclusive) for filtering challenge posting date in ISO 8601 format", | ||
| example: "2024-01-01T00:00:00.000Z", | ||
| }) | ||
| @IsOptional() | ||
| @IsDateString() | ||
| startDate?: string; | ||
|
|
||
| @ApiPropertyOptional({ | ||
| description: | ||
| "End date (exclusive) for filtering challenge posting date in ISO 8601 format", | ||
| example: "2024-02-01T00:00:00.000Z", | ||
| }) | ||
| @IsOptional() | ||
| @IsDateString() | ||
| endDate?: string; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { TopcoderReportsService } from "./topcoder-reports.service"; | |
| import { RegistrantCountriesQueryDto } from "./dto/registrant-countries.dto"; | ||
| import { MemberPaymentAccrualQueryDto } from "./dto/member-payment-accrual.dto"; | ||
| import { RecentMemberDataQueryDto } from "./dto/recent-member-data.dto"; | ||
| import { WeeklyMemberParticipationQueryDto } from "./dto/weekly-member-participation.dto"; | ||
| import { TopcoderReportsGuard } from "../../auth/guards/topcoder-reports.guard"; | ||
| import { CsvResponseInterceptor } from "../../common/interceptors/csv-response.interceptor"; | ||
|
|
||
|
|
@@ -63,10 +64,13 @@ export class TopcoderReportsController { | |
| @Get("/weekly-member-participation") | ||
| @ApiOperation({ | ||
| summary: | ||
| "Weekly distinct registrants and submitters for the last five weeks", | ||
| "Weekly distinct registrants and submitters for the provided date range (defaults to last five weeks)", | ||
| }) | ||
| getWeeklyMemberParticipation() { | ||
| return this.reports.getWeeklyMemberParticipation(); | ||
| getWeeklyMemberParticipation( | ||
| @Query() query: WeeklyMemberParticipationQueryDto, | ||
| ) { | ||
| const { startDate, endDate } = query; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| return this.reports.getWeeklyMemberParticipation(startDate, endDate); | ||
| } | ||
|
|
||
| @Get("/member-payment-accrual") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -448,15 +448,15 @@ export class TopcoderReportsService { | |
| })); | ||
| } | ||
|
|
||
| async getWeeklyMemberParticipation() { | ||
| async getWeeklyMemberParticipation(startDate?: string, endDate?: string) { | ||
| const query = this.sql.load( | ||
| "reports/topcoder/weekly-member-participation.sql", | ||
| ); | ||
| const rows = await this.db.query<{ | ||
| "challenge_stats.posting_date_week": string; | ||
| "challenge_stats.count_distinct_registrant": string | number; | ||
| "challenge_stats.count_distinct_submitter": string | number; | ||
| }>(query); | ||
| }>(query, [startDate ?? null, endDate ?? null]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
|
|
||
| return rows.map((row) => ({ | ||
| "challenge_stats.posting_date_week": | ||
|
|
@@ -470,10 +470,7 @@ export class TopcoderReportsService { | |
| })); | ||
| } | ||
|
|
||
| async getMemberPaymentAccrual( | ||
| startDate?: string, | ||
| endDate?: string, | ||
| ) { | ||
| async getMemberPaymentAccrual(startDate?: string, endDate?: string) { | ||
| const query = this.sql.load("reports/topcoder/member-payment-accrual.sql"); | ||
| const rows = await this.db.query<MemberPaymentAccrualRow>(query, [ | ||
| startDate ?? null, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[❗❗
correctness]Casting directly from
NULLIF($1, '')totimestamptzmight lead to runtime errors if the input is not a valid timestamp. Consider validating the input before casting.