Recent Activity
Track user's recent document activities including last opened and last modified timestamps for Board, Notebook, Asset, and User Input Form documents.
RecentActivity Model
Name | Description |
---|---|
_id | Activity ID |
user | Reference to User model |
project | Reference to Project model |
item | Dynamic reference to the item based on itemType |
itemType | Type of item ('canvas', 'Notebook', 'asset', 'userInputForm') |
lastOpened | Timestamp when item was last opened |
lastModified | Timestamp when item was last modified (null if not modified) |
createdAt | Record creation timestamp |
updateDate | Record last update timestamp |
The model uses dynamic referencing through refPath
to reference different types of items based on the itemType
value. This allows for flexible referencing of various document types while maintaining data integrity.
API Endpoints
Get Recent Activities
GET
/recent
(Get user's recent activities)
Headers
name type data type description Authorization required string Bearer token
Query String
name type data type description limit optional number Maximum number of records (default: 10)
Response Data Structure
interface RecentActivity {
_id: string
user: string
project: {
_id: string
name: string
}
item: {
_id: string
name: string
createdAt: string
updateDate: string
owner: {
_id: string
firstName: string
lastName: string
username: string
}
project: {
_id: string
name: string
}
}
itemType: 'canvas' | 'Notebook' | 'asset' | 'userInputForm'
lastOpened: string
lastModified: string | null
}
Responses
http code content-type response 200
application/json
{ err: false, data: RecentActivity[] }
403
application/json
{ err: true, message: "No permission access" }
500
application/json
{ err: true, message: "Error message" }
Track Recent Activity
POST
/recent
(Track a recent activity)
Headers
name type data type description Authorization required string Bearer token
Request Body
interface TrackActivityRequest {
project: string // Project ID
item: string // Item ID
itemType: 'canvas' | 'Notebook' | 'asset' | 'userInputForm'
isModification: boolean // Whether this is a modification or just an open
}
Responses
http code content-type response 200
application/json
{ err: false, message: "Activity tracked successfully" }
403
application/json
{ err: true, message: "No permission access" }
500
application/json
{ err: true, message: "Error message" }
Implementation Details
Sorting Logic
Recent activities are sorted with the following priority:
- Items are sorted by
lastModified
date in descending order if available - If
lastModified
is null (item was only opened, not modified), thenlastOpened
date is used - This ensures the most recently interacted items appear first
trackActivity
recentActivityService.trackActivity({
user: "user id",
project: "project id",
item: "item id",
itemType: "canvas", // or 'notebook' or 'asset'
isModification: true // or false for just opening
})
Reference Population
When retrieving activities, the following references are automatically populated:
- Project name
- Item details (name, dates, owner, project)
- Owner details (name, username)
This provides all necessary information for displaying the activity in the UI without additional queries.