Skip to content

Scan Batches API#57

Merged
tinak25 merged 10 commits into
masterfrom
Jaykumar677/feature/scan-batches-api
May 17, 2026
Merged

Scan Batches API#57
tinak25 merged 10 commits into
masterfrom
Jaykumar677/feature/scan-batches-api

Conversation

@Jaykumar677
Copy link
Copy Markdown
Collaborator

PR Summary — Scan Batches API

Overview

Implemented the complete Scan Batches API module with:

  • Role-based access control
  • Validation and business logic
  • Swagger documentation
  • Unit tests
  • Integration tests
  • Lint fixes and controller/route improvements

Features Added

Endpoints Implemented

Method Endpoint Description
GET /scan-batches Retrieve paginated scan batches
GET /scan-batches/:id Retrieve single scan batch
POST /scan-batches Upload a new scan batch
DELETE /scan-batches/:id Delete a scan batch

Role-Based Access Control

Admin

  • View all scan batches
  • View single scan batch
  • Delete scan batches

Manager

  • View scan batches from assigned projects only
  • View scan batch by ID for assigned projects

Inspector

  • Upload scan batches
  • View only their own scan batches

Validation Rules Added

Implemented validations for:

  • Inspector existence and role validation
  • Active inspector account validation
  • Project existence and active status
  • Inspector-project assignment
  • Farmer existence and role validation
  • Farmer-project assignment
  • Species existence validation
  • Species-project assignment
  • Measurement limits
  • Coordinates validation
  • Estimated planted month validation
  • Planted date validation

Delete Protection

Implemented protection to prevent deleting scan batches that contain related tree scans.


Swagger Documentation

Added complete Swagger documentation with:

  • Request/response schemas
  • Query parameters
  • Error responses
  • Authorization requirements
  • Example payloads

Testing

Unit Tests

Implemented unit tests for:

  • Success scenarios
  • Validation failures
  • Authorization checks
  • Pagination
  • Delete restrictions
  • Multi-scan validation

Result

30/30 unit tests passing

Evidence

Unit Test Results

Scan Batches API Unit Tests

Integration Tests

Implemented integration tests for:

  • Authentication checks
  • Authorization rules
  • Successful API flows
  • Validation errors
  • Conflict handling
  • Filtering and pagination

Result

31/31 integration tests passing

Evidence

Integration Test Results

Scan Batches API Integration Tests

Swagger API Evidence

GET /scan-batches

Request Example

GET Scan Batches Request

Success Response

GET Scan Batches Success Response

GET /scan-batches/:id

Success Response

GET Scan Batch By ID

POST /scan-batches

Request Example

POST Scan Batch Request

Success Response

POST Scan Batch Success Response

DELETE /scan-batches/:id

Conflict Validation

DELETE Scan Batch Validation

Technical Improvements

Controller Improvements

  • Removed unsafe non-null assertions
  • Improved request safety
  • Fixed ESLint issues

Route Improvements

  • Fixed async middleware lint issues
  • Improved route readability

General Cleanup

  • Improved consistency across module layers
  • Added structured error handling
  • Improved constants organization

Final Status

Swagger Documentation Completed
Role-Based Authorization Implemented
Validation Rules Added
Unit Tests Passing
Integration Tests Passing
ESLint Issues Fixed
Scan Batches API Ready for Review

@Jaykumar677 Jaykumar677 requested review from AKV2703 and tinak25 May 17, 2026 08:57
Copy link
Copy Markdown
Collaborator

@AKV2703 AKV2703 left a comment

Choose a reason for hiding this comment

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

Approving. Overall the implementation structure, validation flow, role-based access handling, and test coverage are solid.

@tinak25
Copy link
Copy Markdown
Collaborator

tinak25 commented May 17, 2026

approved, all good to go!

Copy link
Copy Markdown
Collaborator

@tinak25 tinak25 left a comment

Choose a reason for hiding this comment

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

All good to go!

@tinak25 tinak25 merged commit 3175160 into master May 17, 2026
1 check 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