All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 44s
27 lines
No EOL
787 B
TypeScript
27 lines
No EOL
787 B
TypeScript
// 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')
|
|
}
|
|
} |