sequelize-activitylog
A sequelize plugin for logging activities
Install
$ npm install --save sequelize-activitylog
Usage
Define the Activity model
Create Activity
model named activity_log
and then use the model methods.
const Sequelize = const activitylog = const Activity =
Log an activity
This is the most basic way to log activity:
await
You can retrieve the activity using the Activity model.
const activity = await Activity // returns the last logged activityactivitydescription // returns 'Look mum, I logged something'
Set a subject
You can specify on which object the activity is performed by using performedOn
:
await const activity = await Activity // returns the last logged activityactivity // returns the model that was passed to `performedOn`
The performedOn()
function has a shorter alias name: on
Set a causer
You can set who or what caused the activity by using causedBy
:
await const activity = await Activity // returns the last logged activityactivity // returns the model that was passed to `causedBy`
The causedBy()
function has a shorter alias named: by
Set custom properties
You can add any property you want to an activity by using withProperties
:
await const activity = await Activity // returns the last logged activityactivityproperties // returns `{ key: 'value' }`activity // returns 'value'
The withProperties()
function has a shorter alias named: with
API
log()
: Promise
Log an activity.
performedOn()
: this
Specify on which object the activity is performed.
causedBy()
: this
Set who or what caused the activity.
withProperties()
: this
Add properties to the activity.
withProperty()
: this
Add a property to the activity by key.
useLog()
: this
Specify log name of the activity.
use()
: this
Alias of useLog()
.
on()
: this
Alias of performedOn()
.
by()
: this
Alias of causedBy()
.
with()
withproperties: object: thiswithkey: string value: any: this
Alias of withProperties()
/ withProperty()
.
Note
Inspired by laravel-activitylog
License
MIT © Chun-Kai Wang