Skip to content

Commit

Permalink
Updated clicks by job tags to only fetch within given date range
Browse files Browse the repository at this point in the history
  • Loading branch information
rayceramsay committed Aug 29, 2024
1 parent 0cf5d23 commit 9e5132c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions backend/src/graphql/resolvers/analytics.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,31 @@ const analyticsResolver = {
client.release();
}
},
getJobTagRankingByClicksWithDateRange: async (_: any, { startDate, endDate }: any, { dataSources }: any) => {
const { db } = dataSources
const client = await establishConnection(db)
try {
const query = `
SELECT unnest(tags) AS tag, COUNT(*) AS click_count
FROM job_clicks
JOIN job ON job_clicks.job_id = job.job_id
WHERE tags IS NOT NULL and click_time BETWEEN $1 AND $2
GROUP BY tag
ORDER BY click_count DESC
`
const resp = await client.query(query, [startDate, endDate])
const formattedRows = resp.rows.map((row: any) => ({
tag: row.tag,
click_count: parseInt(row.click_count),
}))
return formattedRows
} catch (err) {
console.error('Error executing query:', err)
throw new Error('Failed to get job tag ranking by clicks with date range')
} finally {
client.release()
}
},
getApplyClicksForScholar: async (
_: any,
{ scholarId }: any,
Expand Down
1 change: 1 addition & 0 deletions backend/src/graphql/typeDefs/analytics.typedef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const analyticsTypeDefs = gql`
getNumberOfActiveScholars: Int
getNumberOfAllowedScholars: Int
getClicksCustomAnalytics(startDate: Date, endDate: Date, interval: String, clickType: String): [CustomAnalytics]
getJobTagRankingByClicksWithDateRange(startDate: Date, endDate: Date): [JobTagRankingByClick]
}
type Mutation {
Expand Down
2 changes: 1 addition & 1 deletion frontend/graphql/queries/analyticsQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export const GET_ANALYTICS_DASHBOARD_DATA = gql`
date
count
}
jobTagRankingsByClicks: getJobTagRankingByClicks {
jobTagRankingsByClicks: getJobTagRankingByClicksWithDateRange(startDate: $startDate, endDate: $endDate) {
tag
click_count
}
Expand Down

0 comments on commit 9e5132c

Please sign in to comment.