Skip to main content

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

NameDescription
_idActivity ID
userReference to User model
projectReference to Project model
itemDynamic reference to the item based on itemType
itemTypeType of item ('canvas', 'Notebook', 'asset', 'userInputForm')
lastOpenedTimestamp when item was last opened
lastModifiedTimestamp when item was last modified (null if not modified)
createdAtRecord creation timestamp
updateDateRecord 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
nametypedata typedescription
AuthorizationrequiredstringBearer token
Query String
nametypedata typedescription
limitoptionalnumberMaximum 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 codecontent-typeresponse
200application/json{ err: false, data: RecentActivity[] }
403application/json{ err: true, message: "No permission access" }
500application/json{ err: true, message: "Error message" }

Track Recent Activity

POST /recent (Track a recent activity)
Headers
nametypedata typedescription
AuthorizationrequiredstringBearer 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 codecontent-typeresponse
200application/json{ err: false, message: "Activity tracked successfully" }
403application/json{ err: true, message: "No permission access" }
500application/json{ err: true, message: "Error message" }

Implementation Details

Sorting Logic

Recent activities are sorted with the following priority:

  1. Items are sorted by lastModified date in descending order if available
  2. If lastModified is null (item was only opened, not modified), then lastOpened date is used
  3. 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.