mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-01-28 23:51:01 -05:00
24 lines
653 B
TypeScript
24 lines
653 B
TypeScript
import { createSupabaseDirectClient } from 'shared/supabase/init'
|
|
import { APIHandler } from 'api/helpers/endpoint'
|
|
import { Notification } from 'common/notifications'
|
|
|
|
export const getNotifications: APIHandler<'get-notifications'> = async (
|
|
props,
|
|
auth
|
|
) => {
|
|
const { limit, after } = props
|
|
const pg = createSupabaseDirectClient()
|
|
const query = `
|
|
select data from user_notifications
|
|
where user_id = $1
|
|
and ($3 is null or (data->'createdTime')::bigint > $3)
|
|
order by (data->'createdTime')::bigint desc
|
|
limit $2
|
|
`
|
|
return await pg.map(
|
|
query,
|
|
[auth.uid, limit, after],
|
|
(row) => row.data as Notification
|
|
)
|
|
}
|