activity-log-module
v0.10.5
Published
Activity log module for HOCCO internal projects
Downloads
144
Readme
activity-log-module
Table of Contents
Installation
For npm
npm i --save activity-log-module
For yarn
yarn add activity-log-module
Usage
Import dynamic module
- In memory cache
import { ActivityLogModule } from 'activity-log-module';
@Module({
imports: [
ActivityLogModule.register(),
],
})
- MySQL
import { ActivityLogModule } from 'activity-log-module';
import * as mysql from 'mysql2/promise';
@Module({
imports: [
ScheduleModule.forRoot(), <-- For Injection SchedulerRegistry
ActivityLogModule.register({
storeFactory: async (schedulerRegistry: SchedulerRegistry) => {
const connection = await mysql.createConnection({
// ConnectionOptions
});
const keepAliveOption: keepAliveOption = {
enableKeepAlive: true,
schedulerRegistry,
cronJobName: 'example-cron-job'
} <-- Optional for cron ping DB connection
return new MysqlStore(connection, keepAliveOption);
},
inject: [SchedulerRegistry], <-- For Injection SchedulerRegistry
}),
],
})
Method
- Log
ActivityLogService.log(actionBy: ActionBy & ObjectLiteral, action: string, actionAt: ActionAt & ObjectLiteral, actionDetail?: Record<string, any>): Promise<void>
- Get by action
ActivityLogService.getByAction(action: string, from: Date, to: Date, searchOptions?: SearchOption): Promise<ActivityLogType[]>
- Get by actor
ActivityLogService.getByActor(id: string, from: Date, to: Date, searchOptions?: SearchOption): Promise<ActivityLogType[]>
Type Specification
Enums
- SortOrder
- ASC
- DESC
Types
SearchOption
- sortOrder: SortOrder
KeepAliveOption (For MySQL)
- enableKeepAlive: boolean
- schedulerRegistry: SchedulerRegistry
- cronJobName: string
ActionBy
- id: string
ActionAt
- time: Date
ActivityLogType
- actionBy: ActionBy
- action: string
- actionAt: ActionAt
- actionDetail?: Record<string, any>