fix: resolve lint errors for API consistency#205
fix: resolve lint errors for API consistency#205Cedarich wants to merge 2 commits intoStarShopCr:mainfrom
Conversation
WalkthroughStandardized Swagger decorators across controllers, introducing ApiSuccessResponse/ApiErrorResponse (and ApiAuthResponse for auth). Adjusted auth service to return { token } instead of { access_token }. Added optional token to AuthResponseDto. Tests now use global prefix /api/v1 and ResponseInterceptor. Fixed an OfferController import path. Added explicit return types in EscrowController. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor C as Client
participant AC as AuthController
participant AS as AuthService
participant RI as ResponseInterceptor
C->>AC: POST /api/v1/auth/login (wallet, signature)
AC->>AS: authenticateUser(walletAddress)
AS-->>AC: { token }
note over AC: Controller returns DTO payload (no cookie set directly)
AC-->>C: Response body (data)
activate RI
RI-->>C: Wraps response + sets token (e.g., header/cookie) per policy
deactivate RI
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🧰 Additional context used📓 Path-based instructions (4)src/**/*.ts📄 CodeRabbit inference engine (.cursorrules)
Files:
src/modules/**📄 CodeRabbit inference engine (.cursorrules)
Files:
src/modules/**/dto/**/*.dto.ts📄 CodeRabbit inference engine (.cursorrules)
Files:
src/modules/**/controllers/**/*.controller.ts📄 CodeRabbit inference engine (.cursorrules)
Files:
🧬 Code graph analysis (2)src/modules/offers/offer.controller.ts (1)
src/modules/auth/controllers/auth.controller.ts (2)
🔇 Additional comments (8)
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: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
src/modules/auth/services/auth.service.ts (2)
52-58: Replace console.log with NestJS Logger.Direct
console.logusage violates coding guidelines. Use the NestJS Logger for proper structured logging.As per coding guidelines, apply this pattern throughout the file:
+import { Injectable, UnauthorizedException, Inject, forwardRef, Logger } from '@nestjs/common'; + @Injectable() export class AuthService { + private readonly logger = new Logger(AuthService.name); private readonly CHALLENGE_MESSAGE = 'StarShop Authentication Challenge'; // In verifyStellarSignature method: - // eslint-disable-next-line no-console - console.log('Development mode: Bypassing signature verification for testing'); + this.logger.warn('Development mode: Bypassing signature verification for testing'); - // eslint-disable-next-line no-console - console.error('Signature verification error:', error); + this.logger.error('Signature verification error:', error);Also applies to: 67-68
162-163: Replace console.error with NestJS Logger.This
console.erroralso violates coding guidelines and should use the Logger instance.- // eslint-disable-next-line no-console - console.error('Failed to create default store for seller:', error); + this.logger.error('Failed to create default store for seller:', error);src/modules/coupons/controllers/coupon.controller.ts (1)
48-50: Restore a valid decorator here (compile error right now)
@ApiResponse(...)is still present, but you removed theApiResponseimport. That leaves an undefined identifier and TypeScript blows up. Either put the import back or (preferably) convert this block to the newApiSuccessResponse/ApiErrorResponsepattern the rest of the file uses.- @ApiResponse({ status: 200, description: 'Coupon found', type: Coupon }) - @ApiResponse({ status: 404, description: 'Coupon not found' }) + @ApiSuccessResponse(200, 'Coupon found', Coupon) + @ApiErrorResponse(404, 'Coupon not found')
🧹 Nitpick comments (1)
src/modules/users/controllers/user.controller.ts (1)
70-71: ReplaceObject as anywith the real auth response DTOPassing
Object as anythrows away the OpenAPI schema you just tried to standardize. Reuse the concreteAuthResponseDto(the same one the AuthController exposes) or create a dedicated DTO so the decorator can emit the contract for clients. Right now the documentation regresses to an untyped blob.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (14)
src/cache/controllers/cache.controller.ts(5 hunks)src/modules/attributes/controllers/attributes.controller.ts(7 hunks)src/modules/auth/controllers/auth.controller.ts(8 hunks)src/modules/auth/services/auth.service.ts(2 hunks)src/modules/coupons/controllers/coupon.controller.ts(4 hunks)src/modules/escrow/controllers/escrow.controller.ts(5 hunks)src/modules/notifications/controllers/notification.controller.ts(3 hunks)src/modules/offers/offfer.controller.ts(2 hunks)src/modules/products/controllers/product.controller.ts(6 hunks)src/modules/seller/controllers/seller.controller.ts(4 hunks)src/modules/seller/tests/seller.e2e.spec.ts(15 hunks)src/modules/stores/controllers/store.controller.ts(10 hunks)src/modules/users/controllers/user.controller.ts(7 hunks)test/auth.e2e-spec.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
src/**/*.ts
📄 CodeRabbit inference engine (.cursorrules)
src/**/*.ts: Do not access environment variables via process.env directly; import and use the config object from src/config/env
Provide explicit return types for all functions
Do not use the any type; use unknown or specific types instead
Create interfaces for complex object shapes
Type all function parameters explicitly
Do not use console.log; use proper logging (e.g., NestJS Logger)
Remove unused imports
Do not leave commented-out code in commits
Wrap risky operations in try-catch and handle errors appropriately
Add JSDoc comments for complex logic
Files:
src/modules/auth/services/auth.service.tssrc/modules/stores/controllers/store.controller.tssrc/modules/coupons/controllers/coupon.controller.tssrc/modules/offers/offfer.controller.tssrc/modules/seller/controllers/seller.controller.tssrc/modules/auth/controllers/auth.controller.tssrc/modules/products/controllers/product.controller.tssrc/modules/notifications/controllers/notification.controller.tssrc/modules/seller/tests/seller.e2e.spec.tssrc/cache/controllers/cache.controller.tssrc/modules/escrow/controllers/escrow.controller.tssrc/modules/users/controllers/user.controller.tssrc/modules/attributes/controllers/attributes.controller.ts
src/modules/**
📄 CodeRabbit inference engine (.cursorrules)
Follow NestJS module structure within src/modules/[module-name]/
Files:
src/modules/auth/services/auth.service.tssrc/modules/stores/controllers/store.controller.tssrc/modules/coupons/controllers/coupon.controller.tssrc/modules/offers/offfer.controller.tssrc/modules/seller/controllers/seller.controller.tssrc/modules/auth/controllers/auth.controller.tssrc/modules/products/controllers/product.controller.tssrc/modules/notifications/controllers/notification.controller.tssrc/modules/seller/tests/seller.e2e.spec.tssrc/modules/escrow/controllers/escrow.controller.tssrc/modules/users/controllers/user.controller.tssrc/modules/attributes/controllers/attributes.controller.ts
src/modules/**/services/**/*.service.ts
📄 CodeRabbit inference engine (.cursorrules)
Place business logic in services
Files:
src/modules/auth/services/auth.service.ts
src/modules/**/controllers/**/*.controller.ts
📄 CodeRabbit inference engine (.cursorrules)
Handle HTTP in controllers only
Files:
src/modules/stores/controllers/store.controller.tssrc/modules/coupons/controllers/coupon.controller.tssrc/modules/seller/controllers/seller.controller.tssrc/modules/auth/controllers/auth.controller.tssrc/modules/products/controllers/product.controller.tssrc/modules/notifications/controllers/notification.controller.tssrc/modules/escrow/controllers/escrow.controller.tssrc/modules/users/controllers/user.controller.tssrc/modules/attributes/controllers/attributes.controller.ts
src/**/*.spec.ts
📄 CodeRabbit inference engine (.cursorrules)
src/**/*.spec.ts: Create tests for new features
Mock external dependencies in tests
Test both success and error cases
Ensure tests are deterministic (no flakiness)
Files:
src/modules/seller/tests/seller.e2e.spec.ts
🧬 Code graph analysis (12)
src/modules/stores/controllers/store.controller.ts (2)
src/common/decorators/api-response.decorator.ts (1)
ApiSuccessResponse(12-43)src/modules/stores/dto/store.dto.ts (1)
StoreResponseDto(229-295)
src/modules/coupons/controllers/coupon.controller.ts (1)
src/common/decorators/api-response.decorator.ts (2)
ApiSuccessResponse(12-43)ApiErrorResponse(50-58)
src/modules/offers/offfer.controller.ts (1)
src/common/decorators/api-response.decorator.ts (2)
ApiSuccessResponse(12-43)ApiErrorResponse(50-58)
src/modules/seller/controllers/seller.controller.ts (3)
src/common/decorators/api-response.decorator.ts (2)
ApiSuccessResponse(12-43)ApiErrorResponse(50-58)src/modules/seller/dto/build-register.dto.ts (1)
BuildRegisterResponseDto(17-32)src/modules/seller/dto/submit-register.dto.ts (1)
SubmitRegisterResponseDto(14-30)
src/modules/auth/controllers/auth.controller.ts (2)
src/common/decorators/api-response.decorator.ts (3)
ApiSuccessResponse(12-43)ApiErrorResponse(50-58)ApiAuthResponse(66-92)src/modules/auth/dto/auth-response.dto.ts (4)
ChallengeResponseDto(3-23)AuthResponseDto(51-74)UserResponseDto(76-105)LogoutResponseDto(107-119)
src/modules/products/controllers/product.controller.ts (1)
src/common/decorators/api-response.decorator.ts (2)
ApiSuccessResponse(12-43)ApiErrorResponse(50-58)
src/modules/notifications/controllers/notification.controller.ts (1)
src/common/decorators/api-response.decorator.ts (1)
ApiSuccessResponse(12-43)
src/modules/seller/tests/seller.e2e.spec.ts (1)
src/common/interceptors/index.ts (1)
ResponseInterceptor(1-1)
src/cache/controllers/cache.controller.ts (1)
src/common/decorators/api-response.decorator.ts (2)
ApiSuccessResponse(12-43)ApiErrorResponse(50-58)
src/modules/escrow/controllers/escrow.controller.ts (2)
src/common/decorators/api-response.decorator.ts (2)
ApiSuccessResponse(12-43)ApiErrorResponse(50-58)src/modules/escrow/dto/release-funds-response.dto.ts (3)
ReleaseFundsResponseDto(5-29)EscrowAccountDto(63-93)MilestoneDto(31-61)
src/modules/users/controllers/user.controller.ts (2)
src/modules/auth/controllers/auth.controller.ts (1)
ApiTags(34-202)src/common/decorators/api-response.decorator.ts (3)
ApiAuthResponse(66-92)ApiSuccessResponse(12-43)ApiErrorResponse(50-58)
src/modules/attributes/controllers/attributes.controller.ts (2)
src/common/decorators/api-response.decorator.ts (2)
ApiSuccessResponse(12-43)ApiErrorResponse(50-58)src/modules/attributes/dto/attribute-response.dto.ts (2)
AttributeResponseDto(18-43)PaginatedAttributesResponseDto(45-62)
🔇 Additional comments (8)
test/auth.e2e-spec.ts (1)
6-6: LGTM! Test environment now mirrors production setup.The addition of
ResponseInterceptorand global API prefix aligns the test environment with production behavior, ensuring tests validate the actual response format clients will receive.Also applies to: 20-22
src/modules/auth/services/auth.service.ts (1)
313-313: LGTM! Token field rename improves API consistency.The rename from
access_tokentotokenaligns with the PR's objective to standardize response formats across the API.Also applies to: 353-353
src/modules/seller/tests/seller.e2e.spec.ts (1)
11-11: LGTM! Test setup properly aligned with production.The test configuration now correctly applies the global API prefix and ResponseInterceptor, and token extraction has been updated to match the interceptor's response structure. Path updates throughout the file are consistent.
Also applies to: 38-40, 45-58
src/modules/auth/controllers/auth.controller.ts (1)
21-21: LGTM! Decorator migration standardizes API documentation.The replacement of
ApiResponsewithApiSuccessResponse,ApiErrorResponse, andApiAuthResponsedecorators provides consistent, well-structured API documentation across all authentication endpoints.Also applies to: 51-52, 74-76, 112-114, 157-158, 194-195
src/modules/notifications/controllers/notification.controller.ts (1)
2-3: LGTM! Decorator migration is consistent.The replacement of
ApiResponsewithApiSuccessResponsealigns with the PR's standardization objectives. No business logic changes, only API documentation improvements.Also applies to: 31-31, 48-48
src/modules/offers/offfer.controller.ts (1)
2-3: LGTM! Decorator migration follows established pattern.The replacement of
ApiResponsedecorators withApiSuccessResponseandApiErrorResponseis consistent with changes across other controllers.Also applies to: 17-19
src/cache/controllers/cache.controller.ts (1)
2-3: LGTM! All cache endpoints now use standardized decorators.The migration from
ApiResponsetoApiSuccessResponseandApiErrorResponseis complete and consistent across all four cache management endpoints.Also applies to: 19-20, 29-30, 40-41, 51-52
src/modules/stores/controllers/store.controller.ts (1)
16-17: LGTM! Comprehensive decorator standardization across all store endpoints.All eight store endpoints now use
ApiSuccessResponseand/orApiErrorResponsedecorators. The proper use of theisArrayparameter for list endpoints (lines 56, 125, 137) ensures accurate OpenAPI documentation for array responses.Also applies to: 36-36, 56-56, 71-71, 88-88, 108-108, 125-125, 137-137, 156-156, 176-176
📖 PR: Standardize Api Responses & Token Handling
📝 Description
ApiSuccessResponseApiErrorResponseApiAuthResponsesetToken(res, token)in UserController soResponseInterceptorconsistently includes token.📂 Updated Controllers
src/modules/attributes/controllers/attributes.controller.tssrc/cache/controllers/cache.controller.tssrc/modules/notifications/controllers/notification.controller.tssrc/modules/escrow/controllers/escrow.controller.tssrc/modules/offers/offfer.controller.tssrc/modules/users/controllers/user.controller.ts📊 Impact
{ "success": true, "data": {}, "token": "optional" }Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests