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

@@ -2,12 +2,15 @@ import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectModel } from '@nestjs/sequelize';
import { TrainingPlan } from './models/training-plan.model';
import { CreateTrainingPlanDto } from './dto/training-plan.dto';
import { ActivityLogsService } from '../activity-logs/activity-logs.service';
import { ActivityActionType, ActivityEntityType } from '../activity-logs/models/activity-log.model';
@Injectable()
export class TrainingPlansService {
constructor(
@InjectModel(TrainingPlan)
private trainingPlanModel: typeof TrainingPlan,
private readonly activityLogsService: ActivityLogsService,
) { }
async create(userId: string, dto: CreateTrainingPlanDto) {
@@ -25,11 +28,27 @@ export class TrainingPlansService {
startWeightKg: dto.startWeightKg ?? null,
preferredTimeOfDay: dto.preferredTimeOfDay ?? '',
});
await this.activityLogsService.record({
userId,
entityType: ActivityEntityType.TRAINING_PLAN,
action: ActivityActionType.CREATE,
entityId: plan.id,
changes: plan.toJSON(),
});
return plan.toJSON();
}
async remove(userId: string, id: string) {
const count = await this.trainingPlanModel.destroy({ where: { id, userId } });
if (count > 0) {
await this.activityLogsService.record({
userId,
entityType: ActivityEntityType.TRAINING_PLAN,
action: ActivityActionType.DELETE,
entityId: id,
changes: null,
});
}
return { success: count > 0 };
}