feat:新增活动日志模块,包括控制器、服务、模型及数据传输对象,更新应用模块以引入新模块,并在打卡和训练计划模块中集成活动日志记录功能。
This commit is contained in:
@@ -4,10 +4,12 @@ import { TrainingPlansService } from './training-plans.service';
|
||||
import { TrainingPlansController } from './training-plans.controller';
|
||||
import { TrainingPlan } from './models/training-plan.model';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
import { ActivityLogsModule } from '../activity-logs/activity-logs.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
UsersModule,
|
||||
ActivityLogsModule,
|
||||
SequelizeModule.forFeature([TrainingPlan]),
|
||||
],
|
||||
controllers: [TrainingPlansController],
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user