refactor(DiaryDateActivityService): improve orderId calculation logic for group activities
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 44s

- Updated the logic for determining the maximum orderId to handle cases with and without groupId more clearly.
- Enhanced code readability by consolidating the where clause for fetching max orderId based on group context.
This commit is contained in:
Torsten Schulz (local)
2026-05-08 14:02:25 +02:00
parent 808493c06e
commit be9caf92a4

View File

@@ -64,11 +64,17 @@ class DiaryDateActivityService {
}
}
const maxOrderId = await DiaryDateActivity.max('orderId', {
where: {
const maxOrderWhere = restData.groupId
? {
diaryDateId: data.diaryDateId,
groupId: restData.groupId
}
: {
// Globale Aktivitäten bei "Alle" sollen am Ende des gesamten Tagesplans landen.
diaryDateId: data.diaryDateId
};
const maxOrderId = await DiaryDateActivity.max('orderId', {
where: maxOrderWhere
});
const newOrderId = maxOrderId !== null ? maxOrderId + 1 : 1;
restData.orderId = newOrderId;