-
Notifications
You must be signed in to change notification settings - Fork 71
last commit #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
last commit #200
Conversation
WalkthroughUpdates import paths across NFT module files to point to relocated interfaces/entities under application/domain directories. No code logic or public API signatures are changed. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
✨ 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (4)
src/modules/nft/infrastructure/nft.repository.ts (4)
18-26: Method signature mismatch with interface (create should accept INFT).Class claims to implement INFTRepository, but create(nft: NFT) violates the contract create(nft: INFT). This will not type-check.
- async create(nft: NFT): Promise<NFT> { - const newNFT = (await this.prisma.nFT.create({ + async create(nft: INFT): Promise<NFT> { + const newNFT = await this.prisma.nFT.create({ data: { userId: nft.userId, organizationId: nft.organizationId, description: nft.description, - }, - })) as unknown as PrismaNFT; + }, + select: { + id: true, + userId: true, + organizationId: true, + description: true, + createdAt: true, + }, + });
5-13: Avoid local Prisma model re-definition and unsafe casts.Duplicating Prisma types via PrismaNFT + casting with as unknown as risks drift and defeats type safety. Use Prisma’s generated types or SELECT what you need.
Option A (preferred): keep SELECTs as in the create/find/update diffs and drop PrismaNFT entirely.
-interface PrismaNFT { - id: string; - createdAt: Date; - updatedAt: Date; - userId: string; - organizationId: string; - description: string; -} +// rely on Prisma SELECT return types (no local duplication)
36-49: Use SELECT and remove unsafe cast in findById.Improves type-safety and reduces over-fetching.
- const nft = (await this.prisma.nFT.findUnique({ - where: { id }, - })) as unknown as PrismaNFT | null; + const nft = await this.prisma.nFT.findUnique({ + where: { id }, + select: { + id: true, + userId: true, + organizationId: true, + description: true, + createdAt: true, + }, + });
83-95: Whitelist updateable fields; don’t pass domain object directly to Prisma.Passing Partial as data risks attempting to write read-only/unknown fields (e.g., id, createdAt) and breaks type-safety.
- async update(id: string, nft: Partial<NFT>): Promise<NFT> { - const updatedNFT = (await this.prisma.nFT.update({ - where: { id }, - data: nft, - })) as unknown as PrismaNFT; + async update(id: string, nft: Partial<NFT>): Promise<NFT> { + const updatedNFT = await this.prisma.nFT.update({ + where: { id }, + data: { + ...(nft.userId !== undefined ? { userId: nft.userId } : {}), + ...(nft.organizationId !== undefined ? { organizationId: nft.organizationId } : {}), + ...(nft.description !== undefined ? { description: nft.description } : {}), + }, + select: { + id: true, + userId: true, + organizationId: true, + description: true, + createdAt: true, + }, + });
🧹 Nitpick comments (9)
src/modules/nft/infrastructure/nft.repository.ts (2)
51-66: Add input validation for pagination and use SELECT; remove cast.Prevent negative skip/zero pageSize and avoid fetching unnecessary columns.
- ): Promise<{ nfts: NFT[]; total: number }> { - const skip = (page - 1) * pageSize; + ): Promise<{ nfts: NFT[]; total: number }> { + const safePage = Math.max(1, Math.floor(page || 1)); + const safePageSize = Math.max(1, Math.min(100, Math.floor(pageSize || 10))); + const skip = (safePage - 1) * safePageSize; @@ - this.prisma.nFT.findMany({ + this.prisma.nFT.findMany({ where: { userId }, skip, - take: pageSize, + take: safePageSize, orderBy: { createdAt: "desc" }, + select: { + id: true, + userId: true, + organizationId: true, + description: true, + createdAt: true, + }, }), @@ - nfts: (nfts as unknown as PrismaNFT[]).map( + nfts: nfts.map(Also applies to: 68-80
15-16: Prefer DI for PrismaClient to avoid excess connections.Instantiate PrismaClient once (or inject per-request scope) instead of per-repository field.
-export class NFTRepository implements INFTRepository { - private prisma = new PrismaClient(); +export class NFTRepository implements INFTRepository { + constructor(private readonly prisma: PrismaClient = new PrismaClient()) {}src/modules/nft/application/repositories/INFTRepository.ts (1)
12-13: Decouple update input from domain class.Consider Partial instead of Partial to avoid leaking the concrete domain class into the repository boundary.
- update(id: string, nft: Partial<NFT>): Promise<NFT>; + update(id: string, nft: Partial<INFT>): Promise<NFT>;src/modules/nft/use-cases/deleteNFT.ts (1)
6-8: Remove redundant await and add explicit return type.Cleaner and avoids an extra microtask.
- async execute(id: string) { - return await this.nftRepository.delete(id); + async execute(id: string): Promise<void> { + return this.nftRepository.delete(id);src/modules/nft/use-cases/getNFT.ts (1)
6-8: Remove redundant await.No behavioral change; just cleaner.
- async execute(id: string) { - return await this.nftRepository.findById(id); + async execute(id: string) { + return this.nftRepository.findById(id);src/modules/nft/use-cases/getNFTByUserId.ts (1)
6-8: Use a descriptive parameter name and remove redundant await.Parameter represents a userId, not a generic id.
- async execute(id: string, page: number, pageSize: number) { - return await this.nftRepository.findByUserId(id, page, pageSize); + async execute(userId: string, page: number, pageSize: number) { + return this.nftRepository.findByUserId(userId, page, pageSize);src/modules/nft/use-cases/createNFT.ts (3)
16-17: Drop redundant await in return
return awaitadds an extra tick without benefit here.- return await this.nftRepository.create(nft); + return this.nftRepository.create(nft);
8-15: Optional: minimal DTO validation before constructing the entityIf invariants aren’t enforced in the domain constructor, add quick guards (empty/whitespace).
async execute(data: CreateNFTDto): Promise<NFT> { + if (!data.userId?.trim() || !data.organizationId?.trim() || !data.description?.trim()) { + throw new Error("userId, organizationId, and description are required."); + } const nft = new NFT(I can wire this to domain-specific errors and add unit tests if you want.
10-10: Replace time-based ID withcrypto.randomUUID()
Dockerfile’sFROM node:18base supportscrypto.randomUUID()(Node ≥14.17), which avoids collision risks under concurrency and prevents timestamp leakage.Apply in src/modules/nft/use-cases/createNFT.ts:
import { INFTRepository } from "../application/repositories/INFTRepository"; +import { randomUUID } from "crypto"; @@ use-cases/createNFT.ts:10 - Date.now().toString(), + randomUUID(),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (6)
src/modules/nft/application/repositories/INFTRepository.ts(1 hunks)src/modules/nft/infrastructure/nft.repository.ts(1 hunks)src/modules/nft/use-cases/createNFT.ts(1 hunks)src/modules/nft/use-cases/deleteNFT.ts(1 hunks)src/modules/nft/use-cases/getNFT.ts(1 hunks)src/modules/nft/use-cases/getNFTByUserId.ts(1 hunks)
🔇 Additional comments (3)
src/modules/nft/infrastructure/nft.repository.ts (1)
19-20: No changes needed: Prisma accessor is correct. Schema definesmodel NFT, soprisma.nFTis the proper client accessor.src/modules/nft/application/repositories/INFTRepository.ts (1)
1-2: LGTM on path updates.Imports look consistent with module layout.
src/modules/nft/use-cases/createNFT.ts (1)
1-1: Import path relocation verified—no stale imports remain and interface file is present.
| import { PrismaClient } from "@prisma/client"; | ||
| import { INFTRepository } from "./INFTRepository"; | ||
| import { NFTDomain as NFT } from "../domain/entities/nft.entity"; | ||
| import { NFTDomain as NFT } from "../../domain/entities/nft.entity"; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect import paths and add missing type import.
Repository is under infrastructure/, while INFTRepository lives under application/repositories and domain under nft/domain. Adjust paths and import INFT to align with INFTRepository’s signature.
import { PrismaClient } from "@prisma/client";
-import { INFTRepository } from "./INFTRepository";
-import { NFTDomain as NFT } from "../../domain/entities/nft.entity";
+import { INFTRepository } from "../application/repositories/INFTRepository";
+import { INFT } from "../domain/interfaces/nft.interface";
+import { NFTDomain as NFT } from "../domain/entities/nft.entity";📝 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.
| import { PrismaClient } from "@prisma/client"; | |
| import { INFTRepository } from "./INFTRepository"; | |
| import { NFTDomain as NFT } from "../domain/entities/nft.entity"; | |
| import { NFTDomain as NFT } from "../../domain/entities/nft.entity"; | |
| import { PrismaClient } from "@prisma/client"; | |
| import { INFTRepository } from "../application/repositories/INFTRepository"; | |
| import { INFT } from "../domain/interfaces/nft.interface"; | |
| import { NFTDomain as NFT } from "../domain/entities/nft.entity"; |
🤖 Prompt for AI Agents
In src/modules/nft/infrastructure/nft.repository.ts around lines 1 to 4, the
import paths are wrong and a required INFT type is missing; update the
INFTRepository import to the correct application path (e.g. import {
INFTRepository } from "../../application/repositories/INFTRepository";) and
change the domain entity import to the correct domain path (e.g. import {
NFTDomain as NFT } from "../../domain/nft/entities/nft.entity";), and add the
missing INFT type import from its module so the repository signature matches
INFTRepository (e.g. import { INFT } from "../../domain/nft/types/INFT";).
Ensure relative paths are adjusted based on actual folder structure and exports.
🚀 Volunchain Pull Request
Mark with an
xall the checkboxes that apply (like[x])📌 Type of Change
📝 Changes description
Create and implement repository files
⏰ Time spent breakdown
Summary by CodeRabbit
Refactor
Chores