Conversation
WalkthroughRemoved 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
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)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
|
There was a problem hiding this comment.
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
surnamedefaulting to'', which groups them first and yields non‑deterministic order. Add a secondary sort bynamefor 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 shadowingpartnersimport/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. UseIntl.Collatorand 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.namein 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
apiKeyormodelProis 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
📒 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.



Summary by CodeRabbit
Bug Fixes
Chores