Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions backend/alembic/versions/d88681a7b3d0_add_tier_to_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('app_states')
op.drop_table('events')
op.drop_table('sessions')
op.drop_table('user_states')
conn = op.get_bind()
inspector = sa.inspect(conn)
existing = inspector.get_table_names()
for tbl in ('app_states', 'events', 'sessions', 'user_states'):
if tbl in existing:
op.drop_table(tbl)
with op.batch_alter_table('plans', schema=None) as batch_op:
batch_op.add_column(sa.Column('tier', sa.Integer(), server_default='0', nullable=False))

Expand Down
7 changes: 4 additions & 3 deletions frontend/src/app/dashboard/widget-settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ export default function WidgetSettingsPage() {
const res = await getBusinessProfile();
if (res.status === 'success' && res.data) {
setBusiness(res.data);
const d = res.data as unknown as Record<string, number | undefined>;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOW Unsafe type assertion

The code uses an unsafe type assertion as unknown as Record<string, number | undefined> on the data received from the getBusinessProfile API call. This assumes the API response will always have the expected shape and types. If the API response changes, this could lead to runtime errors or unexpected behavior.

Suggested change
const d = res.data as unknown as Record<string, number | undefined>;
// A better approach would be to use a type guard or a validation library (like Zod)
// to ensure the data has the correct shape before using it.
// For example:
const isBusinessProfile = (data: any): data is BusinessProfile => {
return (
typeof data === 'object' &&
data !== null &&
typeof data.allocated_messages_per_session === 'number' &&
typeof data.allocated_daily_sessions === 'number' &&
typeof data.allocated_whitelisted_domains === 'number'
);
};
if (isBusinessProfile(res.data)) {
setLimits({
allocated_messages_per_session: res.data.allocated_messages_per_session,
allocated_daily_sessions: res.data.allocated_daily_sessions,
allocated_whitelisted_domains: res.data.allocated_whitelisted_domains,
});
}

setLimits({
allocated_messages_per_session: (res.data as Record<string, unknown>).allocated_messages_per_session,
allocated_daily_sessions: (res.data as Record<string, unknown>).allocated_daily_sessions,
allocated_whitelisted_domains: (res.data as Record<string, unknown>).allocated_whitelisted_domains,
allocated_messages_per_session: d.allocated_messages_per_session,
allocated_daily_sessions: d.allocated_daily_sessions,
allocated_whitelisted_domains: d.allocated_whitelisted_domains,
});
Comment on lines +82 to 87

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The res.data object is already typed as BusinessProfile (returned by getBusinessProfile), which contains the optional fields allocated_messages_per_session, allocated_daily_sessions, and allocated_whitelisted_domains. Casting it to unknown and then to Record<string, number | undefined> is redundant and bypasses TypeScript's type safety. You can access these properties directly from res.data safely.

        setLimits({
          allocated_messages_per_session: res.data.allocated_messages_per_session,
          allocated_daily_sessions: res.data.allocated_daily_sessions,
          allocated_whitelisted_domains: res.data.allocated_whitelisted_domains,
        });

}
Comment on lines 83 to 88

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 This refactor is good for conciseness. To further improve type safety and make the expected data shape more explicit, you could use a more specific inline type for res.data instead of a generic Record.

Suggested change
setLimits({
allocated_messages_per_session: (res.data as Record<string, unknown>).allocated_messages_per_session,
allocated_daily_sessions: (res.data as Record<string, unknown>).allocated_daily_sessions,
allocated_whitelisted_domains: (res.data as Record<string, unknown>).allocated_whitelisted_domains,
allocated_messages_per_session: d.allocated_messages_per_session,
allocated_daily_sessions: d.allocated_daily_sessions,
allocated_whitelisted_domains: d.allocated_whitelisted_domains,
});
}
const data = res.data as {
allocated_messages_per_session?: number;
allocated_daily_sessions?: number;
allocated_whitelisted_domains?: number;
};
setLimits({
allocated_messages_per_session: data.allocated_messages_per_session,
allocated_daily_sessions: data.allocated_daily_sessions,
allocated_whitelisted_domains: data.allocated_whitelisted_domains,
});

} catch (e) { console.error(e); }
Expand Down
Loading