Skip to content

Conversation

@jappyjan
Copy link
Collaborator

@jappyjan jappyjan commented Jun 8, 2025

Summary

This PR implements additional custom fields for resource management as key-value pairs to allow user-definable fields like externalID for MRP system integration.

Changes Made

Backend Changes

  • Resource Entity: Added customFields JSON column to store key-value pairs
  • DTOs: Updated CreateResourceDto and UpdateResourceDto to include optional customFields property
  • Service Layer: Modified ResourcesService to handle custom fields in create and update operations
  • Database Migration: Added migration 1749397000000-add-resource-custom-fields.ts to add the new column
  • Tests: Updated all test mocks to include the new customFields property

API Changes

  • Resources can now be created and updated with custom fields
  • Custom fields are returned in all resource API responses
  • Validation ensures custom fields are objects when provided

Example Usage

Creating a resource with custom fields:

{
  "name": "3D Printer",
  "description": "High-precision 3D printer",
  "customFields": {
    "externalID": "MRP-001",
    "category": "printer",
    "location": "room-a",
    "vendor": "Prusa"
  }
}

Updating custom fields:

{
  "customFields": {
    "externalID": "MRP-002",
    "maintenanceDate": "2025-01-15"
  }
}

Benefits

  • MRP Integration: Resources can now be linked to external MRP systems via externalID field
  • Flexible Metadata: Administrators can add any custom metadata as needed
  • Backward Compatible: Existing resources work without modification (customFields defaults to null)
  • Type Safe: Full TypeScript support with proper validation

Testing

  • ✅ All existing tests pass
  • ✅ New functionality tested with updated test mocks
  • ✅ Database migration applied successfully
  • ✅ API builds and starts without errors

Related Issues

Resolves #133

Migration Notes

The database migration adds a nullable JSON column customFields to the resource table. No data migration is required as existing resources will have customFields set to null.

Description by Korbit AI

What change is being made?

Add support for custom fields in the resource entity by modifying the database schema, DTOs, service, and API client to handle custom field data as key-value pairs in JSON format.

Why are these changes being made?

These changes introduce the ability to store additional, user-defined data on resources through custom fields, improving flexibility and extensibility of resource data handling. This approach allows for scalable data customization without altering the fundamental database schema for each new data requirement, while ensuring consistent validation and integration across all relevant application layers.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

- Add customFields JSON column to Resource entity
- Update CreateResourceDto and UpdateResourceDto to support custom fields
- Update ResourcesService to handle custom fields in create/update operations
- Add database migration for customFields column
- Fix all test mocks to include customFields property
- Support key-value pairs for integration with external MRP systems

Resolves #133
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Error Handling Missing Migration Error Context ▹ view 🧠 Incorrect
Files scanned
File Path Reviewed
apps/api/src/database/migrations/1749397000000-add-resource-custom-fields.ts
apps/api/src/database/migrations/index.ts
apps/api/src/resources/dtos/createResource.dto.ts
apps/api/src/resources/dtos/updateResource.dto.ts
libs/database-entities/src/lib/entities/resource.entity.ts
apps/api/src/resources/resources.service.ts
libs/react-query-client/src/lib/requests/schemas.gen.ts
libs/react-query-client/src/lib/requests/types.gen.ts
libs/api-client/src/generated/Api.ts

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

cursor[bot]

This comment was marked as outdated.

@github-actions
Copy link

github-actions bot commented Jun 8, 2025

🐳 Docker images built and pushed:

GitHub Container Registry: ghcr.io/fabinfra/attraccess:pr-136-530c445
Docker Hub: fabaccess/attraccess:pr-136-530c445

Image Digest: sha256:d58f456a305f95986aebc17443d9e3d61b1d288878677f98bd0c4081a7088be3

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Custom Fields Validation Mismatch

The customFields property in CreateResourceDto and UpdateResourceDto is typed as Record<string, string> but only validated with @IsObject(). This allows non-string values (e.g., numbers, booleans, nested objects) to pass validation, violating the type contract and causing runtime issues when string values are expected. This inconsistency is further compounded by broader client-side type definitions (e.g., object or { [key: string]: unknown }). The validation should either enforce string values or the type should be Record<string, any> to align with the intended data.

apps/api/src/resources/dtos/createResource.dto.ts#L80-L83

https://github.com/FabInfra/Attraccess/blob/1f8eb16384599c42b502d7fe536c14d3c6307d3d/apps/api/src/resources/dtos/createResource.dto.ts#L80-L83

apps/api/src/resources/dtos/updateResource.dto.ts#L91-L94

https://github.com/FabInfra/Attraccess/blob/1f8eb16384599c42b502d7fe536c14d3c6307d3d/apps/api/src/resources/dtos/updateResource.dto.ts#L91-L94

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

@github-actions
Copy link

github-actions bot commented Jun 8, 2025

🐳 Docker images built and pushed:

GitHub Container Registry: ghcr.io/fabinfra/attraccess:pr-136-cffa11a
Docker Hub: fabaccess/attraccess:pr-136-cffa11a

Image Digest: sha256:2a80f14daf4ec8b33b865edf502733161bbeb717039ca0141679eb7344b126fb

@jappyjan jappyjan changed the title feat(GH-133): Add custom fields support for resources WIP: feat(GH-133): Add custom fields support for resources Jun 8, 2025
@jappyjan jappyjan added the needs-refinement The issue does not contain enough information or needs to be further discussed label Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-refinement The issue does not contain enough information or needs to be further discussed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Additional custom fields for ressouce-management

3 participants