Skip to content
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

restored checkin graph with 15 minute intervals #88

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading