Feat/asset assignment module#336
Merged
yusuftomilola merged 2 commits intoDistinctCodes:mainfrom Oct 2, 2025
Merged
Conversation
|
@Tinna23 is attempting to deploy a commit to the naijabuz's projects Team on Vercel. A member of the Team first needs to authorize it. |
yusuftomilola
approved these changes
Oct 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: feat(assets): implement asset assignment module with history tracking
Closes #293
Description
This pull request introduces a new
AssetAssignmentsModuleto manage the assignment of assets to employees, departments, or branches. This provides a clear and auditable chain of custody for all company assets.A key architectural feature of this module is its non-destructive data model. Instead of deleting or overwriting records, the system maintains a full, immutable history of every assignment an asset has ever had. This is achieved by marking old assignments as inactive rather than removing them, which is critical for auditing and asset lifecycle management.
Implementation Details
Core Components
AssetAssignmentEntity: A new TypeORM entity that defines theasset_assignmentstable. It includes anunassignmentDatecolumn, which, whenNULL, indicates the assignment is currently active.AssetAssignmentsService:assign(): Creates a new assignment record. It includes a crucial check to prevent an asset from being actively assigned to more than one entity at the same time.unassign(): Finds the current active assignment for an asset and sets itsunassignmentDateto the current time, effectively closing the assignment while preserving the record.getHistoryForAsset(): Retrieves all historical and current assignment records for a specific asset, sorted with the most recent first.AssetAssignmentsController: Exposes clear, intention-driven endpoints for managing assignments.Endpoints Implemented
POST /asset-assignments/assign: Assigns an asset to a user or department.PATCH /asset-assignments/unassign/:assetId: Unassigns an asset, closing its current assignment period.GET /asset-assignments/history/:assetId: Retrieves the full assignment history of an asset.GET /asset-assignments/current/:assetId: Retrieves only the current, active assignment for an asset.How to Test
1. Setup
AssetAssignmentsModuleinto your mainapp.module.ts.asset_assignmentstable.2. Test the Full Lifecycle
Assign: Make a
POSTrequest to/asset-assignments/assign:{ "assetId": "LAPTOP-001", "assignedToUserId": "user-123" }Verify that a new assignment record is created and returned.
Attempt Re-assignment (Failure): Immediately make another
POSTrequest to assign the same asset (LAPTOP-001) to someone else.Observe: The API should return a
409 Conflicterror with a message that the asset is already assigned.Unassign: Make a
PATCHrequest to/asset-assignments/unassign/LAPTOP-001.Observe: The original assignment record should be returned, but now with the
unassignmentDatefield populated.Re-assign (Success): Now that the asset is free, repeat the
POSTrequest from step 1, but assign it to a different user (user-456).Observe: The request should now succeed, creating a new active assignment.
Check History: Make a
GETrequest to/asset-assignments/history/LAPTOP-001.Observe: The API should return an array containing two records: the new, active assignment for
user-456and the previous, historical assignment foruser-123.