From cd6594a2fd4d595c49f5e8d64ee1a606d0ff27aa Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 9 Apr 2024 18:30:26 +0800 Subject: [PATCH] add logs --- packages/api/src/apollo.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/api/src/apollo.ts b/packages/api/src/apollo.ts index b2c748921..26d255e5d 100644 --- a/packages/api/src/apollo.ts +++ b/packages/api/src/apollo.ts @@ -131,9 +131,14 @@ export function makeApolloServer(app: Express): ApolloServer { const userId = contextValue.context.claims?.uid const action = 'replyToEmail' if (userId && query?.includes(action)) { + logger.info('checking usage limit for user', { userId, action }) // get the user's email sent count from the DB const emailSentCount = await countDailyServiceUsage(userId, action) if (emailSentCount >= MAX_SENT_EMAIL_PER_DAY) { + logger.info('user has reached the daily email limit', { + userId, + action, + }) // if the user has reached the limit, throw an error throw new Error('You have reached the daily email limit') } @@ -149,6 +154,10 @@ export function makeApolloServer(app: Express): ApolloServer { !requestContext.response.errors && !requestContext.response.data?.replyToEmail?.errorCodes ) { + logger.info('incrementing usage count for user', { + userId, + action, + }) await createServiceUsage(userId, action) } },