diff --git a/server/src/db/repositories/VacayEntries.repository.ts b/server/src/db/repositories/VacayEntries.repository.ts index acfb60ed6..2961af676 100644 --- a/server/src/db/repositories/VacayEntries.repository.ts +++ b/server/src/db/repositories/VacayEntries.repository.ts @@ -203,6 +203,12 @@ export class VacayEntriesRepository extends TrekRepository { await this.nativeDelete({ id }); } + /** `DELETE FROM vacay_entries WHERE id IN (dynamic)`, the leave days `shiftOwnerEntriesForTripWindow` drops in one statement; a bound list. */ + async deleteByIds(ids: number[]): Promise { + if (ids.length === 0) return; + await this.nativeDelete({ id: { $in: ids } }); + } + /** VC116 — `UPDATE vacay_entries SET fraction = ?, kind = ? WHERE id = ?` (`toggleEntry`'s in-place conversion). */ async updateFractionKind(id: number, fraction: number, kind: string): Promise { await this.nativeUpdate({ id }, { fraction, kind }); diff --git a/server/src/nest/vacay/vacay.service.ts b/server/src/nest/vacay/vacay.service.ts index dc0da9c1c..af55b2068 100644 --- a/server/src/nest/vacay/vacay.service.ts +++ b/server/src/nest/vacay/vacay.service.ts @@ -398,15 +398,15 @@ export class VacayService { const companyFractions = new Map(companyHolidays.map(h => [h.date, h.fraction] as const)); const moves: { id: number; date: string; fraction: number }[] = []; - for (const row of moving) { - const date = shiftIsoDate(row.date, offset); + const dropped: number[] = []; + for (const { id, date: from, fraction } of moving) { + const date = shiftIsoDate(from, offset); const company = companyFractions.get(date); - if (standing.has(date) || isBlockedWeekend(plan, date) || (company !== undefined && company >= 1)) { - await this.entries.deleteById(row.id); - } else { - moves.push({ id: row.id, date, fraction: company !== undefined && row.fraction > 0.5 ? 0.5 : row.fraction }); - } + const drops = standing.has(date) || isBlockedWeekend(plan, date) || (company ?? 0) >= 1; + if (drops) dropped.push(id); + else moves.push({ id, date, fraction: company === undefined ? fraction : Math.min(fraction, 0.5) }); } + await this.entries.deleteByIds(dropped); // Rows move in the direction of travel, so each target is already free of // the moving row that held it when the next one arrives: (user, plan, date) // is unique.