@@ -5,7 +5,7 @@ import TeamMemberId from '../../../../client/shared/gqlIds/TeamMemberId'
55import { USER_AI_TOKENS_MONTHLY_LIMIT } from '../../../postgres/constants'
66import getKysely from '../../../postgres/getKysely'
77import { analytics } from '../../../utils/analytics/analytics'
8- import { getUserId } from '../../../utils/authorization'
8+ import { getUserId , isSuperUser } from '../../../utils/authorization'
99import { makeMeetingInsightInput } from '../../../utils/makeMeetingInsightInput'
1010import OpenAIServerManager from '../../../utils/OpenAIServerManager'
1111import isValid from '../../isValid'
@@ -24,17 +24,19 @@ export const pageInsights: NonNullable<UserResolvers['pageInsights']> = async (
2424 if ( meetingIds . length === 0 ) throw new GraphQLError ( 'No meetings selected' )
2525 if ( ! prompt || prompt . length < 10 ) throw new GraphQLError ( 'Prompt too short' )
2626 const pg = getKysely ( )
27- const aiUsage = await pg
28- . selectFrom ( 'AIRequest' )
29- . select ( pg . fn . coalesce ( pg . fn . sum < bigint > ( 'tokenCost' ) , sql `0` ) . as ( 'tokenUsage' ) )
30- . where ( 'userId' , '=' , viewerId )
31- . where ( 'createdAt' , '>=' , sql < Date > `NOW() - INTERVAL '30 days'` )
32- . executeTakeFirstOrThrow ( )
33- const { tokenUsage} = aiUsage
34- if ( Number ( tokenUsage ) >= USER_AI_TOKENS_MONTHLY_LIMIT ) {
35- throw new GraphQLError (
36- 'You have exceeded your AI request quota. Please contact sales to increase'
37- )
27+ if ( ! isSuperUser ( authToken ) ) {
28+ const aiUsage = await pg
29+ . selectFrom ( 'AIRequest' )
30+ . select ( pg . fn . coalesce ( pg . fn . sum < bigint > ( 'tokenCost' ) , sql `0` ) . as ( 'tokenUsage' ) )
31+ . where ( 'userId' , '=' , viewerId )
32+ . where ( 'createdAt' , '>=' , sql < Date > `NOW() - INTERVAL '30 days'` )
33+ . executeTakeFirstOrThrow ( )
34+ const { tokenUsage} = aiUsage
35+ if ( Number ( tokenUsage ) >= USER_AI_TOKENS_MONTHLY_LIMIT ) {
36+ throw new GraphQLError (
37+ 'You have exceeded your AI request quota. Please contact sales to increase'
38+ )
39+ }
3840 }
3941 const meetings = ( await dataLoader . get ( 'newMeetings' ) . loadMany ( meetingIds ) ) . filter ( isValid )
4042 const teamIds = [ ...new Set ( meetings . map ( ( { teamId} ) => teamId ) ) ]
0 commit comments