feat: Optimize activity ordering and enhance plan item movement functionality
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 45s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 45s
This commit is contained in:
@@ -64,17 +64,8 @@ class DiaryDateActivityService {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
where: { diaryDateId: data.diaryDateId }
|
||||
});
|
||||
const newOrderId = maxOrderId !== null ? maxOrderId + 1 : 1;
|
||||
restData.orderId = newOrderId;
|
||||
@@ -125,6 +116,12 @@ class DiaryDateActivityService {
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of Object.keys(data)) {
|
||||
if (data[key] === undefined) {
|
||||
delete data[key];
|
||||
}
|
||||
}
|
||||
|
||||
return await activity.update(data);
|
||||
}
|
||||
|
||||
@@ -145,14 +142,12 @@ class DiaryDateActivityService {
|
||||
throw new Error('Activity not found');
|
||||
}
|
||||
const currentOrderId = activity.orderId;
|
||||
const scopeGroupId = activity.groupId || null;
|
||||
if (newOrderId < currentOrderId) {
|
||||
await DiaryDateActivity.increment(
|
||||
{ orderId: 1 },
|
||||
{
|
||||
where: {
|
||||
diaryDateId: activity.diaryDateId,
|
||||
groupId: scopeGroupId,
|
||||
orderId: { [Op.gte]: newOrderId, [Op.lt]: currentOrderId },
|
||||
},
|
||||
}
|
||||
@@ -163,7 +158,6 @@ class DiaryDateActivityService {
|
||||
{
|
||||
where: {
|
||||
diaryDateId: activity.diaryDateId,
|
||||
groupId: scopeGroupId,
|
||||
orderId: { [Op.lte]: newOrderId, [Op.gt]: currentOrderId },
|
||||
},
|
||||
}
|
||||
@@ -308,10 +302,7 @@ class DiaryDateActivityService {
|
||||
|
||||
devLog(predefinedActivity);
|
||||
const maxOrderId = await DiaryDateActivity.max('orderId', {
|
||||
where: {
|
||||
diaryDateId,
|
||||
groupId: Number(groupId)
|
||||
}
|
||||
where: { diaryDateId }
|
||||
});
|
||||
const nextOrderId = Number.isFinite(maxOrderId) ? (maxOrderId + 1) : 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user