Skip to content

Conversation

@Harish-Naruto
Copy link
Member

@Harish-Naruto Harish-Naruto commented Oct 16, 2025

Summary by CodeRabbit

  • New Features

    • Member profiles can store an optional birth date (stored as a date).
    • Achievement views now include richer member details (name, email, profile photo) and creator/updater info.
  • Chores

    • Database migration adjusted to ensure the birth date column uses a proper date type.
  • Tests

    • Test data updated to include birth_date entries and minor formatting adjustments; no behavior changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

Walkthrough

Adds an optional birth_date field to Member (schema + two migrations changing column type), updates getAchievements to include related members, createdBy, and updatedBy data, and adjusts tests to include birth_date: null and minor formatting changes.

Changes

Cohort / File(s) Summary
Database migrations
prisma/migrations/20251016191132_birth_date_added_to_member/migration.sql, prisma/migrations/20251016193811_birth_date_type_fix/migration.sql
Introduces birth_date column on Member; first migration adds it (TEXT), second migration drops and re-adds it as DATE (includes a warning about data loss when dropping column).
Prisma schema
prisma/schema.prisma
Adds optional birth_date field to Member as DateTime? with @db.Date mapping.
Service Layer
src/services/achievement.service.ts
getAchievements now includes related members (selected id, name, email, profilePhoto) and createdBy / updatedBy (id, name) in its query.
Tests (data/formatting)
tests/Achievement.test.ts, tests/Member.test.ts
Test fixtures updated to include birth_date: null on members and minor stylistic/string formatting changes; no behavioral changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant AchievementService as Service
  participant DB

  Client->>Service: getAchievements(params)
  Note right of Service #E8F8F5: Build query with includes:\n- members (id,name,email,profilePhoto)\n- createdBy (id,name)\n- updatedBy (id,name)
  Service->>DB: SELECT ... WITH related includes
  DB-->>Service: achievements + included relations
  Service-->>Client: achievements[] (with members, createdBy, updatedBy)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • i-am-that-guy

Poem

"I nibbled through the schema dirt,
A birth_date planted—quietly pert,
Achievements now call their friends near,
Creators and updaters appear,
A rabbit cheers — a tiny schema spurt!" 🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Achivement endpoint update" directly refers to the achievement service modifications present in the changeset, specifically the getAchievements method enhancements to eagerly fetch related data. However, the title only partially captures the overall scope of the pull request, as the changeset also includes significant schema-related changes: adding a birth_date field to the Member model through two database migrations and corresponding schema updates, along with test adjustments. While the title accurately describes one real aspect of the changes (the achievement service update), it doesn't reflect the full scope or primary intent of the PR.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch achivement-endpoint-update

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 579cc53 and 593591e.

📒 Files selected for processing (2)
  • prisma/migrations/20251016193811_birth_date_type_fix/migration.sql (1 hunks)
  • prisma/schema.prisma (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • prisma/schema.prisma
🔇 Additional comments (1)
prisma/migrations/20251016193811_birth_date_type_fix/migration.sql (1)

1-9: Consider consolidating the two migrations or ensure data safety during type conversion.

This migration follows closely after a prior migration (20251016191132) that initially added birth_date as TEXT. The DROP COLUMN and ADD COLUMN pattern will lose existing data and relies on implicit type coercion.

Concerns:

  • If any data exists in the column and isn't in a valid DATE format, the migration will fail or truncate silently.
  • Having two consecutive migrations for the same column suggests a schema-migration synchronization issue that should be addressed earlier in the development cycle.
  • No explicit type casting or data migration logic is present.

Please verify:

  1. Whether the prior migration (20251016191132_birth_date_added_to_member) is already deployed to production or staging.
  2. Whether any data exists in the birth_date column before running this migration.
  3. If data does exist, provide a migration that safely converts TEXT to DATE (e.g., using a CAST or intermediate step).

If this is a development-only environment or the column is empty, this migration is safe to proceed. Consider using a single, correct migration going forward to avoid similar issues.


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.

Copy link
Contributor

@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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52b806d and e6169a5.

📒 Files selected for processing (3)
  • prisma/migrations/20251016191132_birth_date_added_to_member/migration.sql (1 hunks)
  • prisma/schema.prisma (1 hunks)
  • src/services/achievement.service.ts (1 hunks)
🔇 Additional comments (1)
src/services/achievement.service.ts (1)

5-32: Good optimization with eager loading.

The addition of include to eagerly load related entities (members, createdBy, updatedBy) is a good optimization that prevents N+1 query issues and provides richer data for the API response. The nested structure for members is correct since MemberAchievement is a join table.

Note: The newly added birth_date field from the Member model is not included in the select clause. If this field should be exposed through the achievement endpoint, add it to the member select at line 14:

  member: {
    select: {
      id: true,
      name: true,
      email: true,
      profilePhoto: true,
+     birth_date: true,
    },
  },

The same change would need to be applied to getAchievementById at line 75 for consistency.

Comment on lines +1 to +2
-- AlterTable
ALTER TABLE "Member" ADD COLUMN "birth_date" TEXT;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Use a proper date type instead of TEXT.

The migration adds birth_date as TEXT, which matches the String type in the Prisma schema but is not ideal for storing dates. After updating the schema to use DateTime (as suggested in prisma/schema.prisma), regenerate this migration to use a proper date type.

The updated migration should use either DATE or TIMESTAMP:

- ALTER TABLE "Member" ADD COLUMN     "birth_date" TEXT;
+ ALTER TABLE "Member" ADD COLUMN     "birth_date" DATE;

Use DATE if you only need to store the date (YYYY-MM-DD) without time information, or TIMESTAMP if you need date and time.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
-- AlterTable
ALTER TABLE "Member" ADD COLUMN "birth_date" TEXT;
-- AlterTable
ALTER TABLE "Member" ADD COLUMN "birth_date" DATE;
🤖 Prompt for AI Agents
In prisma/migrations/20251016191132_birth_date_added_to_member/migration.sql
lines 1–2, the new "birth_date" column is created as TEXT; update the migration
to use an appropriate date/time type (e.g., ALTER TABLE "Member" ADD COLUMN
"birth_date" DATE; or ADD COLUMN "birth_date" TIMESTAMP; depending on whether
you need time) that matches the Prisma schema DateTime, then regenerate or
replace the migration SQL so it uses DATE or TIMESTAMP for your database dialect
(Postgres/MySQL) and re-run prisma migrate so the schema and migration are
consistent.

Copy link
Contributor

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/Achievement.test.ts (1)

42-62: Replace any test doubles with typed helpers to satisfy no-explicit-any

Every const req/res: any = … (same pattern repeats throughout the file) violates @typescript-eslint/no-explicit-any, blocking lint. Please introduce lightweight typed builders—e.g., import type Request, Response from express and cast via as unknown as Request/Response, or wrap them in helper functions returning those types—so tests stay type-safe without relying on any.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6169a5 and 579cc53.

📒 Files selected for processing (2)
  • tests/Achievement.test.ts (15 hunks)
  • tests/Member.test.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/Member.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
tests/Achievement.test.ts (4)
src/utils/imageUtils.ts (2)
  • uploadImage (23-70)
  • deleteImage (72-85)
src/services/achievement.service.ts (5)
  • createAchievement (40-60)
  • getAchievementById (63-95)
  • updateAchievementById (98-116)
  • deleteAchievementById (132-136)
  • removeMemberFromAchievement (139-148)
src/controllers/achievement.controller.ts (5)
  • createAchievement (37-71)
  • getAchievementById (18-35)
  • updateAchievementById (74-134)
  • deleteAchievementById (137-159)
  • removeMemberFromAchievement (162-180)
src/utils/apiError.ts (1)
  • ApiError (6-17)
🪛 ESLint
tests/Achievement.test.ts

[error] 29-29: A require() style import is forbidden.

(@typescript-eslint/no-require-imports)


[error] 42-42: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 94-94: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 112-112: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 128-128: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 134-134: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 150-150: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 219-219: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 279-279: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 291-291: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 297-297: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 338-338: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 372-372: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 401-401: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 424-424: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 452-452: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 465-465: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 481-481: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 501-501: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 518-518: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 535-535: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 588-588: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 601-601: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 630-630: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 637-637: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 645-645: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 652-652: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

Comment on lines 27 to 31
return {
__esModule: true,
default: jest.fn(() => require('express').Router()),
default: jest.fn(() => require("express").Router()),
};
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix ESLint no-require-imports violation in achievements route mock

require("express") trips the project’s @typescript-eslint/no-require-imports rule, so the suite fails linting. Import Router (or express) once at the top and use it in the mock factory instead of require to keep the mock functional without breaking the rule.

🧰 Tools
🪛 ESLint

[error] 29-29: A require() style import is forbidden.

(@typescript-eslint/no-require-imports)

🤖 Prompt for AI Agents
In tests/Achievement.test.ts around lines 27 to 31, the mock uses
require("express") which violates @typescript-eslint/no-require-imports; fix by
importing Router (or express) at the top of the test file (e.g., import { Router
} from "express" or import express) and replace the require call in the
jest.mock factory with the imported Router/express reference so the mock no
longer uses require.

@i-am-that-guy i-am-that-guy merged commit ea2ffee into main Oct 16, 2025
2 checks passed
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.

3 participants