-
Notifications
You must be signed in to change notification settings - Fork 38
fix(admin/analytics): use sql.raw for date_trunc period to avoid parameter mismatch #2354
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
bbc6b8f
0e1b011
3e2c9d3
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 |
|---|---|---|
|
|
@@ -44,31 +44,31 @@ export const platformAnalyticsRoutes = new Elysia({ prefix: '/platform' }) | |
| const [userGrowth, packGrowth, catalogGrowth] = await Promise.all([ | ||
| db | ||
| .select({ | ||
| date: sql<string>`date_trunc(${period}, ${users.createdAt})::date::text`, | ||
| date: sql<string>`date_trunc(${sql.raw(`'${period}'`)}, ${users.createdAt})::date::text`, | ||
| count: count(), | ||
| }) | ||
| .from(users) | ||
| .where(gte(users.createdAt, startDate)) | ||
| .groupBy(sql`date_trunc(${period}, ${users.createdAt})`) | ||
| .orderBy(sql`date_trunc(${period}, ${users.createdAt})`), | ||
| .groupBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${users.createdAt})`) | ||
| .orderBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${users.createdAt})`), | ||
| db | ||
| .select({ | ||
| date: sql<string>`date_trunc(${period}, ${packs.createdAt})::date::text`, | ||
| date: sql<string>`date_trunc(${sql.raw(`'${period}'`)}, ${packs.createdAt})::date::text`, | ||
| count: count(), | ||
| }) | ||
| .from(packs) | ||
| .where(and(eq(packs.deleted, false), gte(packs.createdAt, startDate))) | ||
| .groupBy(sql`date_trunc(${period}, ${packs.createdAt})`) | ||
| .orderBy(sql`date_trunc(${period}, ${packs.createdAt})`), | ||
| .groupBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${packs.createdAt})`) | ||
| .orderBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${packs.createdAt})`), | ||
|
Comment on lines
+61
to
+62
|
||
| db | ||
| .select({ | ||
| date: sql<string>`date_trunc(${period}, ${catalogItems.createdAt})::date::text`, | ||
| date: sql<string>`date_trunc(${sql.raw(`'${period}'`)}, ${catalogItems.createdAt})::date::text`, | ||
| count: count(), | ||
| }) | ||
| .from(catalogItems) | ||
| .where(gte(catalogItems.createdAt, startDate)) | ||
| .groupBy(sql`date_trunc(${period}, ${catalogItems.createdAt})`) | ||
| .orderBy(sql`date_trunc(${period}, ${catalogItems.createdAt})`), | ||
| .groupBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${catalogItems.createdAt})`) | ||
| .orderBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${catalogItems.createdAt})`), | ||
|
Comment on lines
+70
to
+71
|
||
| ]); | ||
|
|
||
| const userMap = Object.fromEntries(userGrowth.map((r) => [r.date, r.count])); | ||
|
|
@@ -113,16 +113,16 @@ export const platformAnalyticsRoutes = new Elysia({ prefix: '/platform' }) | |
| const [tripActivity, trailActivity, postActivity] = await Promise.all([ | ||
| db | ||
| .select({ | ||
| date: sql<string>`date_trunc(${period}, ${trips.createdAt})::date::text`, | ||
| date: sql<string>`date_trunc(${sql.raw(`'${period}'`)}, ${trips.createdAt})::date::text`, | ||
| count: count(), | ||
| }) | ||
| .from(trips) | ||
| .where(and(eq(trips.deleted, false), gte(trips.createdAt, startDate))) | ||
| .groupBy(sql`date_trunc(${period}, ${trips.createdAt})`) | ||
| .orderBy(sql`date_trunc(${period}, ${trips.createdAt})`), | ||
| .groupBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${trips.createdAt})`) | ||
| .orderBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${trips.createdAt})`), | ||
|
Comment on lines
+121
to
+122
|
||
| db | ||
| .select({ | ||
| date: sql<string>`date_trunc(${period}, ${trailConditionReports.createdAt})::date::text`, | ||
| date: sql<string>`date_trunc(${sql.raw(`'${period}'`)}, ${trailConditionReports.createdAt})::date::text`, | ||
| count: count(), | ||
| }) | ||
| .from(trailConditionReports) | ||
|
|
@@ -132,17 +132,19 @@ export const platformAnalyticsRoutes = new Elysia({ prefix: '/platform' }) | |
| gte(trailConditionReports.createdAt, startDate), | ||
| ), | ||
| ) | ||
| .groupBy(sql`date_trunc(${period}, ${trailConditionReports.createdAt})`) | ||
| .orderBy(sql`date_trunc(${period}, ${trailConditionReports.createdAt})`), | ||
| .groupBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${trailConditionReports.createdAt})`) | ||
| .orderBy( | ||
| sql`date_trunc(${sql.raw(`'${period}'`)}, ${trailConditionReports.createdAt})`, | ||
| ), | ||
|
Comment on lines
+135
to
+138
|
||
| db | ||
| .select({ | ||
| date: sql<string>`date_trunc(${period}, ${posts.createdAt})::date::text`, | ||
| date: sql<string>`date_trunc(${sql.raw(`'${period}'`)}, ${posts.createdAt})::date::text`, | ||
| count: count(), | ||
| }) | ||
| .from(posts) | ||
| .where(gte(posts.createdAt, startDate)) | ||
| .groupBy(sql`date_trunc(${period}, ${posts.createdAt})`) | ||
| .orderBy(sql`date_trunc(${period}, ${posts.createdAt})`), | ||
| .groupBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${posts.createdAt})`) | ||
| .orderBy(sql`date_trunc(${sql.raw(`'${period}'`)}, ${posts.createdAt})`), | ||
|
Comment on lines
+146
to
+147
|
||
| ]); | ||
|
|
||
| const tripMap = Object.fromEntries(tripActivity.map((r) => [r.date, r.count])); | ||
|
|
||
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.
The
groupBycall is missing the closing template-literal backtick/parenthesis, which will cause a TypeScript syntax error and prevent this route from compiling. Close thesqltemplate literal and thegroupBy(...)call before chaining.orderBy(...).