Enhance addGroupActivity method to support predefined activities in diary date activities
This commit updates the addGroupActivity method in the DiaryDateActivityService to accept a predefinedActivityId, allowing for the retrieval or creation of predefined activities based on the provided ID or activity name. Additionally, the frontend DiaryView is modified to include predefinedActivityId in the new plan item, improving the handling of group activities.
This commit is contained in:
@@ -310,7 +310,7 @@ class DiaryDateActivityService {
|
||||
return activitiesWithImages;
|
||||
}
|
||||
|
||||
async addGroupActivity(userToken, clubId, diaryDateId, groupId, activity, timeblockId = null) {
|
||||
async addGroupActivity(userToken, clubId, diaryDateId, groupId, activity, predefinedActivityId = null, timeblockId = null) {
|
||||
await checkAccess(userToken, clubId);
|
||||
let diaryDateActivity;
|
||||
|
||||
@@ -350,11 +350,37 @@ class DiaryDateActivityService {
|
||||
console.error('Group diaryDateId:', group.diaryDateId, 'Activity diaryDateId:', diaryDateActivity.diaryDateId);
|
||||
throw new Error('Group isn\'t related to date');
|
||||
}
|
||||
const [predefinedActivity, created] = await PredefinedActivity.findOrCreate({
|
||||
where: {
|
||||
name: activity
|
||||
|
||||
let predefinedActivity = null;
|
||||
|
||||
// 1. Versuche zuerst, die PredefinedActivity per ID zu finden
|
||||
if (predefinedActivityId) {
|
||||
predefinedActivity = await PredefinedActivity.findByPk(predefinedActivityId);
|
||||
}
|
||||
|
||||
// 2. Falls nicht gefunden, suche nach Name oder Code
|
||||
if (!predefinedActivity) {
|
||||
const normalized = (activity || '').trim();
|
||||
if (normalized) {
|
||||
predefinedActivity = await PredefinedActivity.findOne({
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{ name: normalized },
|
||||
{ code: normalized }
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 3. Falls immer noch nicht gefunden, erstelle eine neue
|
||||
if (!predefinedActivity) {
|
||||
predefinedActivity = await PredefinedActivity.create({
|
||||
name: activity || '',
|
||||
code: activity || '',
|
||||
});
|
||||
}
|
||||
|
||||
devLog(predefinedActivity);
|
||||
const activityData = {
|
||||
diaryDateActivity: diaryDateActivity.id,
|
||||
|
||||
Reference in New Issue
Block a user