feat: 优化目标创建逻辑,处理日期和时间字段的空值情况

- 更新目标创建逻辑,确保在创建目标时,startDate、startTime和endTime字段可以处理空值,提升数据的灵活性和安全性。
This commit is contained in:
richarjiang
2025-08-22 11:22:55 +08:00
parent acf8d0c48c
commit 062a78a839

View File

@@ -30,10 +30,10 @@ export class GoalsService {
const goal = await Goal.create({ const goal = await Goal.create({
userId, userId,
...createGoalDto, ...createGoalDto,
startDate: new Date(createGoalDto.startDate), startDate: createGoalDto.startDate ? new Date(createGoalDto.startDate) : null,
endDate: createGoalDto.endDate ? new Date(createGoalDto.endDate) : null, endDate: createGoalDto.endDate ? new Date(createGoalDto.endDate) : null,
startTime: createGoalDto.startTime, startTime: createGoalDto.startTime ? createGoalDto.startTime : null,
endTime: createGoalDto.endTime, endTime: createGoalDto.endTime ? createGoalDto.endTime : null,
}); });
this.logger.log(`用户 ${userId} 创建了目标: ${goal.title}`); this.logger.log(`用户 ${userId} 创建了目标: ${goal.title}`);