diff --git a/packages/trigger/google-calendar-sync.ts b/packages/trigger/google-calendar-sync.ts index 5093a4e28..3badb5385 100644 --- a/packages/trigger/google-calendar-sync.ts +++ b/packages/trigger/google-calendar-sync.ts @@ -162,11 +162,9 @@ export const syncGoogleCalendarEvents = async () => { try { const calendar = google.calendar({ version: 'v3', auth }); - const startOfCurrentWeek = dayjs().startOf('week'); - const timeMin = startOfCurrentWeek.toDate(); - const timeMax = startOfCurrentWeek - .add(BACKGROUND_SYNC_RANGE, 'day') - .toDate(); + const now = dayjs().utc(); + const timeMin = now.toDate(); + const timeMax = now.add(BACKGROUND_SYNC_RANGE, 'day'); const response = await calendar.events.list({ calendarId: 'primary', diff --git a/packages/types/src/supabase.ts b/packages/types/src/supabase.ts index e13ae1580..d30084af8 100644 --- a/packages/types/src/supabase.ts +++ b/packages/types/src/supabase.ts @@ -7749,12 +7749,12 @@ export type Database = { }; count_search_users: { Args: + | { search_query: string } | { - enabled_filter?: boolean; - role_filter?: string; search_query: string; - } - | { search_query: string }; + role_filter?: string; + enabled_filter?: boolean; + }; Returns: number; }; create_ai_chat: { @@ -7771,26 +7771,26 @@ export type Database = { } | { p_user_id: string; - p_session_data?: Json; - p_expiry_seconds?: number; - p_target_app: string; p_origin_app: string; + p_target_app: string; + p_expiry_seconds?: number; + p_session_data?: Json; }; Returns: string; }; get_challenge_stats: { - Args: { user_id_param: string; challenge_id_param: string }; + Args: { challenge_id_param: string; user_id_param: string }; Returns: { total_score: number; problems_attempted: number; }[]; }; get_daily_income_expense: { - Args: { past_days?: number; _ws_id: string }; + Args: { _ws_id: string; past_days?: number }; Returns: { day: string; - total_expense: number; total_income: number; + total_expense: number; }[]; }; get_daily_prompt_completion_tokens: { @@ -7839,22 +7839,22 @@ export type Database = { }; get_inventory_products: { Args: { - _has_unit?: boolean; - _warehouse_ids?: string[]; - _ws_id?: string; _category_ids?: string[]; + _ws_id?: string; + _warehouse_ids?: string[]; + _has_unit?: boolean; }; Returns: { + id: string; + name: string; + manufacturer: string; + unit: string; unit_id: string; category: string; price: number; amount: number; ws_id: string; created_at: string; - manufacturer: string; - name: string; - id: string; - unit: string; }[]; }; get_inventory_products_count: { @@ -7874,18 +7874,18 @@ export type Database = { Returns: number; }; get_monthly_income_expense: { - Args: { past_months?: number; _ws_id: string }; + Args: { _ws_id: string; past_months?: number }; Returns: { - total_expense: number; - total_income: number; month: string; + total_income: number; + total_expense: number; }[]; }; get_monthly_prompt_completion_tokens: { Args: { past_months?: number }; Returns: { - total_prompt_tokens: number; month: string; + total_prompt_tokens: number; total_completion_tokens: number; }[]; }; @@ -7894,40 +7894,41 @@ export type Database = { Returns: number; }; get_possible_excluded_groups: { - Args: { included_groups: string[]; _ws_id: string }; + Args: { _ws_id: string; included_groups: string[] }; Returns: { - name: string; id: string; - amount: number; + name: string; ws_id: string; + amount: number; }[]; }; get_possible_excluded_tags: { Args: { _ws_id: string; included_tags: string[] }; Returns: { - amount: number; - ws_id: string; - name: string; id: string; + name: string; + ws_id: string; + amount: number; }[]; }; get_session_statistics: { Args: Record; Returns: { - active_count: number; - latest_session_date: string; - completed_count: number; total_count: number; unique_users_count: number; + active_count: number; + completed_count: number; + latest_session_date: string; }[]; }; get_session_templates: { Args: { - limit_count?: number; - user_id_param: string; workspace_id: string; + user_id_param: string; + limit_count?: number; }; Returns: { + title: string; description: string; category_id: string; task_id: string; @@ -7938,73 +7939,72 @@ export type Database = { usage_count: number; avg_duration: number; last_used: string; - title: string; }[]; }; get_submission_statistics: { Args: Record; Returns: { - latest_submission_date: string; total_count: number; + latest_submission_date: string; unique_users_count: number; }[]; }; get_transaction_categories_with_amount: { Args: Record; Returns: { + id: string; + name: string; is_expense: boolean; ws_id: string; created_at: string; amount: number; - id: string; - name: string; }[]; }; get_user_role: { - Args: { ws_id: string; user_id: string }; + Args: { user_id: string; ws_id: string }; Returns: string; }; get_user_session_stats: { Args: { user_id: string }; Returns: { + total_sessions: number; active_sessions: number; current_session_age: unknown; - total_sessions: number; }[]; }; get_user_sessions: { Args: { user_id: string }; Returns: { + session_id: string; created_at: string; updated_at: string; user_agent: string; ip: string; is_current: boolean; - session_id: string; }[]; }; get_user_tasks: { Args: { _board_id: string }; Returns: { - board_id: string; + id: string; + name: string; description: string; priority: number; completed: boolean; start_date: string; end_date: string; list_id: string; - id: string; - name: string; + board_id: string; }[]; }; get_user_whitelist_status: { Args: { user_id_param: string }; Returns: { is_whitelisted: boolean; - allow_manage_all_challenges: boolean; + enabled: boolean; allow_challenge_management: boolean; + allow_manage_all_challenges: boolean; allow_role_management: boolean; - enabled: boolean; }[]; }; get_workspace_drive_size: { @@ -8020,20 +8020,20 @@ export type Database = { Returns: number; }; get_workspace_transactions_count: { - Args: { end_date?: string; start_date?: string; ws_id: string }; + Args: { ws_id: string; start_date?: string; end_date?: string }; Returns: number; }; get_workspace_user_groups: { Args: { _ws_id: string; - search_query: string; - excluded_tags: string[]; included_tags: string[]; + excluded_tags: string[]; + search_query: string; }; Returns: { - notes: string; - name: string; id: string; + name: string; + notes: string; ws_id: string; tags: string[]; tag_count: number; @@ -8046,8 +8046,8 @@ export type Database = { }; get_workspace_users: { Args: { - included_groups: string[]; _ws_id: string; + included_groups: string[]; excluded_groups: string[]; search_query: string; }; @@ -8083,19 +8083,19 @@ export type Database = { Returns: number; }; get_workspace_wallets_expense: { - Args: { start_date?: string; ws_id: string; end_date?: string }; + Args: { ws_id: string; start_date?: string; end_date?: string }; Returns: number; }; get_workspace_wallets_income: { - Args: { end_date?: string; start_date?: string; ws_id: string }; + Args: { ws_id: string; start_date?: string; end_date?: string }; Returns: number; }; has_other_owner: { - Args: { _user_id: string; _ws_id: string }; + Args: { _ws_id: string; _user_id: string }; Returns: boolean; }; insert_ai_chat_message: { - Args: { source: string; message: string; chat_id: string }; + Args: { message: string; chat_id: string; source: string }; Returns: undefined; }; is_list_accessible: { @@ -8115,11 +8115,11 @@ export type Database = { Returns: boolean; }; is_nova_user_email_in_team: { - Args: { _team_id: string; _user_email: string }; + Args: { _user_email: string; _team_id: string }; Returns: boolean; }; is_nova_user_id_in_team: { - Args: { _team_id: string; _user_id: string }; + Args: { _user_id: string; _team_id: string }; Returns: boolean; }; is_org_member: { @@ -8139,7 +8139,7 @@ export type Database = { Returns: boolean; }; is_user_task_in_board: { - Args: { _task_id: string; _user_id: string }; + Args: { _user_id: string; _task_id: string }; Returns: boolean; }; is_user_whitelisted: { @@ -8155,11 +8155,11 @@ export type Database = { Returns: Json; }; nova_get_user_daily_sessions: { - Args: { user_id: string; challenge_id: string }; + Args: { challenge_id: string; user_id: string }; Returns: number; }; nova_get_user_total_sessions: { - Args: { user_id: string; challenge_id: string }; + Args: { challenge_id: string; user_id: string }; Returns: number; }; revoke_all_cross_app_tokens: { @@ -8185,13 +8185,6 @@ export type Database = { enabled_filter?: boolean; }; Returns: { - allow_challenge_management: boolean; - allow_manage_all_challenges: boolean; - allow_role_management: boolean; - email: string; - new_email: string; - birthday: string; - team_name: string[]; id: string; display_name: string; deleted: boolean; @@ -8201,6 +8194,13 @@ export type Database = { created_at: string; user_id: string; enabled: boolean; + allow_challenge_management: boolean; + allow_manage_all_challenges: boolean; + allow_role_management: boolean; + email: string; + new_email: string; + birthday: string; + team_name: string[]; }[]; }; search_users_by_name: { @@ -8210,11 +8210,11 @@ export type Database = { min_similarity?: number; }; Returns: { + id: string; handle: string; - relevance: number; - avatar_url: string; display_name: string; - id: string; + avatar_url: string; + relevance: number; }[]; }; sum_quiz_scores: { @@ -8228,7 +8228,7 @@ export type Database = { Returns: boolean; }; transactions_have_same_amount: { - Args: { transaction_id_2: string; transaction_id_1: string }; + Args: { transaction_id_1: string; transaction_id_2: string }; Returns: boolean; }; update_expired_sessions: { @@ -8246,8 +8246,8 @@ export type Database = { validate_cross_app_token_with_session: { Args: { p_token: string; p_target_app: string }; Returns: { - session_data: Json; user_id: string; + session_data: Json; }[]; }; }; diff --git a/packages/utils/src/calendar-sync-coordination.ts b/packages/utils/src/calendar-sync-coordination.ts index 3e4da6f5a..323e66700 100644 --- a/packages/utils/src/calendar-sync-coordination.ts +++ b/packages/utils/src/calendar-sync-coordination.ts @@ -83,28 +83,25 @@ export const canProceedWithSync = async ( }; /** - * Check if a date range is within 4 weeks from the current week + * Check if a date range is within 4 weeks from now * @param startDate - Start date to check * @param endDate - End date to check - * @returns boolean - true if within 4 weeks from current week, false otherwise + * @returns boolean - true if within 4 weeks from now, false otherwise */ export const isWithinBackgroundSyncRange = ( startDate: dayjs.Dayjs, endDate: dayjs.Dayjs ): boolean => { - const now = dayjs(); - const startOfCurrentWeek = now.startOf('week'); - const endOfBackgroundSyncRange = startOfCurrentWeek.add( - BACKGROUND_SYNC_RANGE, - 'day' - ); + const startOfBackgroundSyncRange = dayjs(); + const endOfBackgroundSyncRange = dayjs().add(BACKGROUND_SYNC_RANGE, 'day'); const start = dayjs(startDate); const end = dayjs(endDate); - // Check if the date range overlaps with the 4-week period from current week + // Check if the date range overlaps with the 4-week period from now const isWithinRange = - start.isBefore(endOfBackgroundSyncRange) && end.isAfter(startOfCurrentWeek); + start.isBefore(endOfBackgroundSyncRange) && + end.isAfter(startOfBackgroundSyncRange); return isWithinRange; };