mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-24 17:41:27 -04:00
Add /stats
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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<k>} = {
|
||||
'rsvp-event': rsvpEvent,
|
||||
'update-event': updateEvent,
|
||||
health: health,
|
||||
stats: stats,
|
||||
me: getMe,
|
||||
'get-user-and-profile': getUserAndProfileHandler,
|
||||
report: report,
|
||||
|
||||
19
backend/api/src/stats.ts
Normal file
19
backend/api/src/stats.ts
Normal file
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user