Files
Compass/backend/api/src/has-free-like.ts
Martin Braquet ba9b3cfb06 Add pretty formatting (#29)
* Test

* Add pretty formatting

* Fix Tests

* Fix Tests

* Fix Tests

* Fix

* Add pretty formatting fix

* Fix

* Test

* Fix tests

* Clean typeckech

* Add prettier check

* Fix api tsconfig

* Fix api tsconfig

* Fix tsconfig

* Fix

* Fix

* Prettier
2026-02-20 17:32:27 +01:00

27 lines
892 B
TypeScript

import {type APIHandler} from 'api/helpers/endpoint'
import {createSupabaseDirectClient} from 'shared/supabase/init'
export const hasFreeLike: APIHandler<'has-free-like'> = async (_props, auth) => {
return {
status: 'success',
hasFreeLike: await getHasFreeLike(auth.uid),
}
}
export const getHasFreeLike = async (userId: string) => {
const pg = createSupabaseDirectClient()
const likeGivenToday = await pg.oneOrNone<object>(
`
select 1
from profile_likes
where creator_id = $1
and created_time at time zone 'UTC' at time zone 'America/Los_Angeles' >= (now() at time zone 'UTC' at time zone 'America/Los_Angeles')::date
and created_time at time zone 'UTC' at time zone 'America/Los_Angeles' < ((now() at time zone 'UTC' at time zone 'America/Los_Angeles')::date + interval '1 day')
limit 1
`,
[userId],
)
return !likeGivenToday
}