增强文章控制器的安全性,添加JWT身份验证守卫;优化训练计划服务,简化日志记录逻辑,确保使用计划创建训练会话时的准确性;更新训练会话模型,允许训练计划ID为可空字段。
This commit is contained in:
@@ -17,14 +17,12 @@ export class TrainingPlansService {
|
||||
) { }
|
||||
|
||||
async create(userId: string, dto: CreateTrainingPlanDto) {
|
||||
const id = `plan_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||
const createdAt = new Date();
|
||||
|
||||
// 检查用户是否有其他激活的训练计划
|
||||
const activePlans = await this.trainingPlanModel.findAll({ where: { userId, isActive: true, deleted: false } });
|
||||
|
||||
const plan = await this.trainingPlanModel.create({
|
||||
id,
|
||||
userId,
|
||||
name: dto.name ?? '',
|
||||
createdAt,
|
||||
@@ -37,10 +35,10 @@ export class TrainingPlansService {
|
||||
preferredTimeOfDay: dto.preferredTimeOfDay ?? '',
|
||||
isActive: activePlans.length === 0,
|
||||
});
|
||||
this.winstonLogger.info(`create plan ${id} for user ${userId} success`, {
|
||||
this.winstonLogger.info(`create plan ${plan.id} for user ${userId} success`, {
|
||||
context: 'TrainingPlansService',
|
||||
userId,
|
||||
id,
|
||||
planId: plan.id,
|
||||
});
|
||||
await this.activityLogsService.record({
|
||||
userId,
|
||||
@@ -49,10 +47,10 @@ export class TrainingPlansService {
|
||||
entityId: plan.id,
|
||||
changes: plan.toJSON(),
|
||||
});
|
||||
this.winstonLogger.info(`create plan ${id} for user ${userId} success`, {
|
||||
this.winstonLogger.info(`create plan ${plan.id} for user ${userId} success`, {
|
||||
context: 'TrainingPlansService',
|
||||
userId,
|
||||
id,
|
||||
planId: plan.id,
|
||||
});
|
||||
return plan.toJSON();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user