feat: implement activity logging for user actions and create activities table
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 44s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 44s
This commit is contained in:
parent
6c75efbc28
commit
7e2f320b4f
12 changed files with 420 additions and 160 deletions
27
app/services/activity_logger.ts
Normal file
27
app/services/activity_logger.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// app/services/activity_logger.ts
|
||||
import Activity from '#models/activity'
|
||||
|
||||
interface LogOptions {
|
||||
type: string
|
||||
description: string
|
||||
userId?: number | null
|
||||
subjectType?: string | null
|
||||
subjectId?: number | string | null
|
||||
properties?: Record<string, any>
|
||||
}
|
||||
|
||||
export default class ActivityLogger {
|
||||
static async log(options: LogOptions): Promise<void> {
|
||||
await Activity.create({
|
||||
type: options.type,
|
||||
description: options.description,
|
||||
userId: options.userId ?? null,
|
||||
subjectType: options.subjectType ?? null,
|
||||
subjectId: options.subjectId != null ? Number(options.subjectId) : null,
|
||||
properties: options.properties ?? null,
|
||||
})
|
||||
|
||||
// Invalidate the cache if you add one (see Redis section).
|
||||
// await redis.del('activities:recent')
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue