feat:新增活动日志模块,包括控制器、服务、模型及数据传输对象,更新应用模块以引入新模块,并在打卡和训练计划模块中集成活动日志记录功能。

This commit is contained in:
richarjiang
2025-08-14 15:43:29 +08:00
parent 24924e5d81
commit bc8a52852d
15 changed files with 373 additions and 20 deletions

View File

@@ -0,0 +1,67 @@
import { BelongsTo, Column, DataType, ForeignKey, Index, Model, Table } from 'sequelize-typescript';
import { User } from '../../users/models/user.model';
export enum ActivityEntityType {
USER = 'USER',
USER_PROFILE = 'USER_PROFILE',
CHECKIN = 'CHECKIN',
TRAINING_PLAN = 'TRAINING_PLAN',
}
export enum ActivityActionType {
CREATE = 'CREATE',
UPDATE = 'UPDATE',
DELETE = 'DELETE',
}
@Table({
tableName: 't_activity_logs',
underscored: true,
})
export class ActivityLog extends Model {
@Column({
type: DataType.UUID,
primaryKey: true,
defaultValue: DataType.UUIDV4,
})
declare id: string;
@ForeignKey(() => User)
@Column({ type: DataType.STRING, allowNull: false, comment: '用户ID' })
declare userId: string;
@BelongsTo(() => User)
declare user?: User;
@Column({
type: DataType.ENUM('USER', 'USER_PROFILE', 'CHECKIN', 'TRAINING_PLAN'),
allowNull: false,
comment: '实体类型',
})
declare entityType: ActivityEntityType;
@Column({
type: DataType.ENUM('CREATE', 'UPDATE', 'DELETE'),
allowNull: false,
comment: '动作类型',
})
declare action: ActivityActionType;
@Column({ type: DataType.STRING, allowNull: true, comment: '实体ID' })
declare entityId: string | null;
@Column({ type: DataType.JSON, allowNull: true, comment: '变更详情或前后快照' })
declare changes: Record<string, any> | null;
@Column({ type: DataType.JSON, allowNull: true, comment: '附加信息(来源、设备等)' })
declare metadata: Record<string, any> | null;
@Column({ type: DataType.DATE, defaultValue: DataType.NOW, comment: '发生时间' })
declare createdAt: Date;
@Column({ type: DataType.DATE, defaultValue: DataType.NOW })
declare updatedAt: Date;
}