Skip to content

Commit

Permalink
Merge pull request #88 from mustachebash/update/checkin-chart
Browse files Browse the repository at this point in the history
restored checkin graph with 15 minute intervals
  • Loading branch information
jfurfaro authored Mar 18, 2024
2 parents 491f533 + 9856fa9 commit 7cf1dc2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/routes/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Router from '@koa/router';
import { authorizeUser, requiresPermission } from '../middleware/auth.js';
import { getEvents, getEvent, createEvent, updateEvent, getEventSummary, getOpeningSales, getEventExtendedStats, getEventDailyTickets } from '../services/events.js';
import { getEvents, getEvent, createEvent, updateEvent, getEventSummary, getOpeningSales, getEventExtendedStats, getEventDailyTickets, getEventCheckins } from '../services/events.js';

const eventsRouter = new Router({
prefix: '/events'
Expand Down Expand Up @@ -87,7 +87,7 @@ eventsRouter
let chartData;
switch(chartType) {
case 'checkIns':
// chartData = await getEventCheckins(ctx.params.id);
chartData = await getEventCheckins(ctx.params.id);
break;

case 'openingSales':
Expand Down
29 changes: 26 additions & 3 deletions lib/services/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export async function getEventExtendedStats(id) {
}
}

export async function getEventDailyTickets(id) {
export async function getEventDailyTickets(id: string) {
try {
const chart = (await sql`
SELECT
Expand All @@ -344,9 +344,9 @@ export async function getEventDailyTickets(id) {
}
}

export async function getOpeningSales(id) {
export async function getOpeningSales(id: string) {
try {
const chart = (await sql`
const chart = (await sql<{minuteCreated: string; tickets: string}[]>`
SELECT
DATE_TRUNC('minute', (o.created AT TIME ZONE 'UTC')) AS minute_created,
SUM(oi.quantity) as tickets
Expand All @@ -368,6 +368,29 @@ export async function getOpeningSales(id) {
}));


return chart;
} catch(e) {
throw new EventsServiceError('Could not query event extended stats', 'UNKNOWN', e);
}
}

export async function getEventCheckins(id: string) {
try {
const chart = (await sql<{minuteCheckedIn: string; checkins: string}[]>`
SELECT
date_bin('15 minutes', (g.check_in_time AT TIME ZONE 'UTC'), TIMESTAMP '2010-01-01') AS minute_checked_in,
count(g.id) as checkins
FROM guests AS g
WHERE g.event_id = ${id}
AND g.status = 'checked_in'
GROUP BY minute_checked_in
ORDER BY 1 ASC;
`).map(row => ({
...row,
checkins: Number(row.checkins)
}));


return chart;
} catch(e) {
throw new EventsServiceError('Could not query event extended stats', 'UNKNOWN', e);
Expand Down

0 comments on commit 7cf1dc2

Please sign in to comment.