diff --git a/backend/api/package.json b/backend/api/package.json index 3aea242a..2fe980f8 100644 --- a/backend/api/package.json +++ b/backend/api/package.json @@ -1,6 +1,6 @@ { "name": "@compass/api", - "version": "1.23.0", + "version": "1.24.0", "private": true, "description": "Backend API endpoints", "main": "src/serve.ts", diff --git a/backend/api/src/app.ts b/backend/api/src/app.ts index bf115f37..7aa10dfc 100644 --- a/backend/api/src/app.ts +++ b/backend/api/src/app.ts @@ -89,6 +89,7 @@ import {setCompatibilityAnswer} from './set-compatibility-answer' import {setLastOnlineTime} from './set-last-online-time' import {shipProfiles} from './ship-profiles' import {starProfile} from './star-profile' +import {stats} from './stats' import {updateEvent} from './update-event' import {updateMe} from './update-me' import {updateNotifSettings} from './update-notif-setting' @@ -662,6 +663,7 @@ const handlers: {[k in APIPath]: APIHandler} = { 'rsvp-event': rsvpEvent, 'update-event': updateEvent, health: health, + stats: stats, me: getMe, 'get-user-and-profile': getUserAndProfileHandler, report: report, diff --git a/backend/api/src/stats.ts b/backend/api/src/stats.ts new file mode 100644 index 00000000..3faa60c1 --- /dev/null +++ b/backend/api/src/stats.ts @@ -0,0 +1,19 @@ +import {createSupabaseDirectClient} from 'shared/supabase/init' + +import {APIHandler} from './helpers/endpoint' + +export const stats: APIHandler<'stats'> = async (_, _auth) => { + const pg = createSupabaseDirectClient() + + const [userCount, profileCount, eventsCount] = await Promise.all([ + pg.one(`SELECT COUNT(*)::int as count FROM users`), + pg.one(`SELECT COUNT(*)::int as count FROM profiles`), + pg.one(`SELECT COUNT(*)::int as count FROM events WHERE event_start_time > now()`), + ]) + + return { + users: userCount.count, + profiles: profileCount.count, + upcomingEvents: eventsCount.count, + } +} diff --git a/common/src/api/schema.ts b/common/src/api/schema.ts index 87a80a2d..d1694cda 100644 --- a/common/src/api/schema.ts +++ b/common/src/api/schema.ts @@ -138,6 +138,25 @@ export const API = (_apiTypeCheck = { summary: 'Check whether the API server is running', tag: 'General', }, + /** + * Get platform statistics + * Returns public statistics about the platform including user count and other metrics + * + * @returns Object containing various platform statistics + */ + stats: { + method: 'GET', + authed: false, + rateLimited: true, + props: z.object({}), + returns: {} as { + users: number + profiles: number + upcomingEvents: number + }, + summary: 'Get platform statistics', + tag: 'General', + }, /** * Get Supabase JWT token * Returns a JWT token for authenticated clients to access Supabase directly