Skip to content

chore: some updates#165

Merged
hmbanan666 merged 1 commit intomainfrom
chore
Sep 16, 2025
Merged

chore: some updates#165
hmbanan666 merged 1 commit intomainfrom
chore

Conversation

@hmbanan666
Copy link
Copy Markdown
Collaborator

@hmbanan666 hmbanan666 commented Sep 16, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Partner list is now consistently sorted by legal entity name for easier browsing.
    • Active users list is now sorted by surname (A–Z) for improved findability.
  • Chores

    • Disabled Telegram delivery for daily AI reports; reports no longer post to Telegram.

@hmbanan666 hmbanan666 self-assigned this Sep 16, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Sep 16, 2025

Walkthrough

Removed Telegram/Atrium posting from the daily-report task, keeping OpenAI generation and flow item creation. Partner repository now awaits results and returns locale-sorted partners by legalEntity.name. User repository adds surname ascending ordering for active users.

Changes

Cohort / File(s) Change Summary
Daily report task Telegram removal
apps/web-app/server/tasks/ai/daily-report.ts
Stripped Telegram/Atrium integration and related runtime config/destructuring; removed message composition/sending logic; retained OpenAI interaction and flow item creation; eliminated usage of flow item id.
Repository sorting updates
packages/database/src/repository/partner.ts, packages/database/src/repository/user.ts
Partner.listWithData now awaits, sorts by legalEntity.name via localeCompare, and returns the sorted array; User.list adds orderBy by surname asc while preserving existing filters/includes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Cron as Scheduler
  participant Task as daily-report task
  participant AI as OpenAI API
  participant DB as Database

  Cron->>Task: Trigger daily report
  Task->>AI: Generate report content
  AI-->>Task: finalMessage
  Task->>DB: Create flow item (daily report)
  Note over Task: Telegram/Atrium send removed<br/>(no outbound bot message)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I nibble lines where bots once spoke,
Snip the wires, a gentle stroke.
Surnames line up, partners too,
Neat as rows of morning dew.
Carrot logs and tidy sort—
A rabbit’s clean and quiet report. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The title "chore: some updates" is overly generic and does not convey the primary changes in this changeset; the diff shows concrete edits (removal of Telegram/Atrium integration from daily-report and sorting/order changes in partner.ts and user.ts). Because it uses a vague phrase rather than summarizing the main functional change, it does not meet the requirement for clarity and specificity. Reviewers scanning history would not understand the primary intent from this title alone. Please update the PR title to clearly state the main change, for example: "chore: remove Telegram integration from daily-report and add sorting to partner/user queries." If the changes are unrelated, consider splitting them into separate PRs or explicitly list the secondary fixes in the title/body so reviewers can quickly grasp intent.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (8)
packages/database/src/repository/user.ts (2)

72-75: Stabilize sorting; add tie-breaker by name and avoid clumping empty surnames at the top.

Many rows have surname defaulting to '', which groups them first and yields non‑deterministic order. Add a secondary sort by name for stability.

Apply this diff:

-      orderBy: (users, { asc }) => asc(users.surname),
+      orderBy: (users, { asc }) => [asc(users.surname), asc(users.name)],

70-78: Consider an index for frequent listing.

If User.list() is used in hot paths, add a composite index on (is_active, surname, name) to keep the sort cheap.

packages/database/src/repository/partner.ts (3)

35-51: Avoid shadowing partners import/params; rename local result.

const partners = await ... shadows the imported table and the callback param, hurting readability.

Apply this diff:

-    const partners = await useDatabase().query.partners.findMany({
+    const rows = await useDatabase().query.partners.findMany({
       where: (partners, { eq }) => eq(partners.isActive, true),
       with: {
         kitchens: true,
         legalEntity: {
           with: {
             agreements: {
               with: {
                 files: true,
               },
             },
           },
         },
         users: true,
       },
     })

52-57: Deterministic, locale/case‑insensitive sort; put missing names last.

localeCompare() without options depends on runtime locale and case. Use Intl.Collator and handle empty names consistently.

Apply this diff:

-    // Order by name of legal entity
-    return partners.sort((a, b) => {
-      const aName = a.legalEntity?.name || ''
-      const bName = b.legalEntity?.name || ''
-      return aName.localeCompare(bName)
-    })
+    // Order by legal entity name (case-insensitive, numbers-aware). Empty names go last.
+    const collator = new Intl.Collator(undefined, { sensitivity: 'base', numeric: true })
+    return rows.sort((a, b) => {
+      const aName = a.legalEntity?.name || ''
+      const bName = b.legalEntity?.name || ''
+      if (!aName && bName) return 1
+      if (aName && !bName) return -1
+      return collator.compare(aName, bName)
+    })

34-58: If the dataset grows, push the ordering to SQL.

In‑memory sort scales as O(n log n) after pulling all rows. Consider a join/CTE to order by partner_legal_entities.name in the query when record counts increase.

apps/web-app/server/tasks/ai/daily-report.ts (3)

10-13: Update task description to match current behavior (no Telegram post).

The task no longer posts to Telegram; the description should reflect that to avoid confusion.

Apply this diff:

-    description: 'Prepare and post daily report to Telegram group',
+    description: 'Prepare daily report and save it to Flow',

21-22: Guard against missing AI runtime config and skip gracefully.

Fail fast if apiKey or modelPro is absent to prevent noisy errors.

Apply this diff:

-      const { ai } = useRuntimeConfig()
+      const { ai } = useRuntimeConfig()
+      if (!ai?.apiKey || !ai?.modelPro) {
+        logger.warn('AI config missing; skipping daily report')
+        return { result: true }
+      }

63-80: Remove dead commented Telegram code.

Large commented blocks add noise; rely on git history if needed.

Apply this diff to delete the block:

-      // const separator = 'zzzzz'
-      // const startAppData = `flow${separator}${flowItem?.id}`
-
-      // // Get first words
-      // const messageIntro = finalMessage.split(' ').slice(0, 40).join(' ')
-      // const preparedMessage = `${messageIntro}...\n\nПродолжение внутри Атриума? 🙃`
-
-      // await useAtriumBot().api.sendMessage(telegram.teamGroupId, preparedMessage, {
-      //   link_preview_options: {
-      //     is_disabled: true,
-      //   },
-      //   reply_markup: {
-      //     inline_keyboard: [[{
-      //       text: '👉 Открыть Атриум',
-      //       url: `https://t.me/sushi_atrium_bot/app?startapp=${startAppData}`,
-      //     }]],
-      //   },
-      // })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e70670 and e535947.

📒 Files selected for processing (3)
  • apps/web-app/server/tasks/ai/daily-report.ts (2 hunks)
  • packages/database/src/repository/partner.ts (2 hunks)
  • packages/database/src/repository/user.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/database/src/repository/user.ts (1)
packages/database/src/tables.ts (1)
  • users (75-93)
packages/database/src/repository/partner.ts (1)
packages/database/src/tables.ts (1)
  • partners (95-104)
apps/web-app/server/tasks/ai/daily-report.ts (1)
packages/database/src/repository/index.ts (1)
  • repository (63-63)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
apps/web-app/server/tasks/ai/daily-report.ts (1)

55-61: LGTM: Flow item creation kept; result no longer required.

Creating the Flow item without storing the id aligns with removal of the Telegram follow‑up.

@hmbanan666 hmbanan666 merged commit 15f9b77 into main Sep 16, 2025
8 checks passed
@hmbanan666 hmbanan666 deleted the chore branch September 16, 2025 15:47
This was referenced Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant