State and State History
Overview ๐ฏ๐๐ก
In the system, documents such as orders or customers are represented as JavaScript objects (e.g., {object: 'OrderDto'}
). Each document contains a state
property and a stateHistory
property to track its lifecycle.
State Property ๐๐โ๏ธ
The state
property represents the current status of a document. It can have one of the following values:
active โ The document is currently in use and operational.
inactive โ The document exists but is not currently active.
archived โ The document is stored for historical reference but is not active.
deleted โ The document is marked as removed but still exists in the system.
Important Note: โ ๏ธ๐๐๏ธ
Our system never deletes any data. Instead, when a document is marked as deleted, it means that the user will no longer see the document, but it remains stored in the database for historical and auditing purposes.
Example: ๐๐โ
State History Property ๐๐๐
The stateHistory
property is an array that tracks all state changes of the document. Each entry in the array contains:
state
: The state the document was in.setAt
: The timestamp when the state was set (in ISO format).
Example: ๐โณ๐
How It Works โก๐๐
The
state
property always reflects the latest state of the document.The
stateHistory
property logs all past state changes in chronological order.Developers should ensure that every state change is recorded in the
stateHistory
array.
Changing State ๐งโ๏ธ๐ ๏ธ
When updating the state of a document, developers must:
Append the previous state to the
stateHistory
array before updating thestate
property.Update the
state
property to the new state.
Example of Updating State in JavaScript: ๐ป๐๐๏ธ
Expected Output: ๐ฅ๏ธโ
๐
Developer Guidelines ๐โ
๐ ๏ธ
Always ensure state changes are meaningful and necessary.
Always append the previous state to
stateHistory
before updating thestate
property.Use ISO 8601 format for timestamps.
Do not remove or alter previous
stateHistory
entries.Handle state transitions in a controlled and documented manner to maintain system integrity.
Remember that deleted documents are not removed from the system; they are simply hidden from users.
By following these guidelines, developers can ensure a reliable and traceable state management system for documents. ๐ฏ๐๐
Last updated
Was this helpful?