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
57
app/models/activity.ts
Normal file
57
app/models/activity.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// app/models/activity.ts
|
||||
import { DateTime } from 'luxon';
|
||||
import { belongsTo, column } from '@adonisjs/lucid/orm';
|
||||
import BaseModel from './base_model.js';
|
||||
import type { BelongsTo } from '@adonisjs/lucid/types/relations';
|
||||
import User from '#models/user';
|
||||
import { SnakeCaseNamingStrategy } from '@adonisjs/lucid/orm';
|
||||
|
||||
export default class Activity extends BaseModel {
|
||||
public static namingStrategy = new SnakeCaseNamingStrategy();
|
||||
public static primaryKey = 'id';
|
||||
public static table = 'activities';
|
||||
|
||||
@column({ isPrimary: true })
|
||||
declare id: number;
|
||||
|
||||
@column()
|
||||
declare type: string;
|
||||
|
||||
@column()
|
||||
declare userId: number | null;
|
||||
|
||||
@column()
|
||||
declare subjectType: string | null;
|
||||
|
||||
@column()
|
||||
declare subjectId: number | null;
|
||||
|
||||
@column()
|
||||
declare description: string;
|
||||
|
||||
// Manual JSON (de)serialization keeps this working on SQLite/MySQL.
|
||||
// On Postgres json/jsonb the driver already parses — drop the `consume`
|
||||
// JSON.parse there to avoid double-handling.
|
||||
// @column({
|
||||
// prepare: (value: Record<string, any> | null) => (value ? JSON.stringify(value) : null),
|
||||
// consume: (value: string | null) => (value ? JSON.parse(value) : null),
|
||||
// })
|
||||
// declare properties: Record<string, any> | null;
|
||||
|
||||
@column()
|
||||
declare properties: Record<string, any> | null;
|
||||
|
||||
@column.dateTime({ autoCreate: true })
|
||||
declare createdAt: DateTime;
|
||||
|
||||
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||
declare updatedAt: DateTime;
|
||||
|
||||
// @belongsTo(() => User)
|
||||
// declare user: BelongsTo<typeof User>;
|
||||
|
||||
@belongsTo(() => User, {
|
||||
foreignKey: 'userId',
|
||||
})
|
||||
declare user: BelongsTo<typeof User>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue