fix: opening balance direction, safe return paths, backup failure detection, review fixes
- opening balance: "person 2 owes person 1" was stored the wrong way round - retour param: reject backslash/control chars (open redirect) - backup: pipefail + check dump completeness, failed dumps no longer logged OK - deleting a recurring occurrence marks it skipped so sync does not recreate it - editing a charge regenerates future occurrences of incomes allocated to it - settlements (incl. opening balance) listed in settings and deletable Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a0bcea4eb1
commit
5b402691f0
15 files changed
+222
-15
No files matched your search
@@ -7,6 +7,7 @@ import { fromIsoDate, todayParis, toIsoDate } from "@/lib/dates";
|
||||
import { prisma } from "../db";
|
||||
import { splitRows } from "../mappers";
|
||||
import { syncRecurrings } from "../sync";
|
||||
import { dropPlannedWithAllocations } from "./recurrings";
|
||||
import type { Result } from "./operations";
|
||||
|
||||
const isoDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Date invalide.");
|
||||
@@ -137,7 +138,7 @@ export async function saveLoan(input: LoanFormInput, today: string = todayParis(
|
||||
return { loanId, recurringId: rec.id };
|
||||
});
|
||||
|
||||
await prisma.operation.deleteMany({ where: { recurringId, status: "PLANNED", date: { gte: fromIsoDate(today) } } });
|
||||
await dropPlannedWithAllocations(recurringId, today);
|
||||
await syncRecurrings(today);
|
||||
return { ok: true, id: loanId };
|
||||
}
|
||||
|
||||
@@ -105,8 +105,18 @@ export async function saveOperation(raw: OperationInput, currentUserId: string):
|
||||
return { ok: true, id };
|
||||
}
|
||||
|
||||
/** Une occurrence de récurrent est marquée ignorée (sinon la synchro la recréerait) ; le reste est supprimé. */
|
||||
export async function deleteOperation(id: string): Promise<Result> {
|
||||
await prisma.operation.delete({ where: { id } });
|
||||
const op = await prisma.operation.findUnique({ where: { id } });
|
||||
if (!op) return { ok: true };
|
||||
if (op.recurringId) {
|
||||
await prisma.$transaction([
|
||||
prisma.operation.updateMany({ where: { allocatedToOperationId: id }, data: { allocatedToOperationId: null } }),
|
||||
prisma.operation.update({ where: { id }, data: { status: "SKIPPED" } }),
|
||||
]);
|
||||
} else {
|
||||
await prisma.operation.delete({ where: { id } });
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
@@ -152,3 +162,8 @@ export async function saveSettlement(input: {
|
||||
});
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
export async function deleteSettlement(id: string): Promise<Result> {
|
||||
await prisma.settlement.deleteMany({ where: { id } });
|
||||
return { ok: true };
|
||||
}
|
||||
@@ -32,6 +32,21 @@ async function dropPlannedFrom(recurringId: string, from: string) {
|
||||
await prisma.operation.deleteMany({ where: { recurringId, status: "PLANNED", date: { gte: fromIsoDate(from) } } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Après modification d'une charge : ses occurrences prévues et celles des entrées qui lui sont affectées
|
||||
* (dont la répartition copie celle de la charge) sont régénérées par la prochaine synchro.
|
||||
*/
|
||||
export async function dropPlannedWithAllocations(recurringId: string, from: string) {
|
||||
const allocated = await prisma.recurring.findMany({ where: { allocatedToRecurringId: recurringId }, select: { id: true } });
|
||||
await prisma.operation.deleteMany({
|
||||
where: {
|
||||
recurringId: { in: [recurringId, ...allocated.map((r) => r.id)] },
|
||||
status: "PLANNED",
|
||||
date: { gte: fromIsoDate(from) },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveRecurring(raw: RecurringInput, today: string = todayParis()): Promise<Result<{ id: string }>> {
|
||||
const parsed = recurringSchema.safeParse(raw);
|
||||
if (!parsed.success) return { ok: false, error: parsed.error.issues[0]?.message ?? "Données invalides." };
|
||||
@@ -73,7 +88,7 @@ export async function saveRecurring(raw: RecurringInput, today: string = todayPa
|
||||
return (await tx.recurring.create({ data: { ...data, splits: { create: splitRows(input.split as Split) } } })).id;
|
||||
});
|
||||
|
||||
await dropPlannedFrom(id, today);
|
||||
await dropPlannedWithAllocations(id, today);
|
||||
await syncRecurrings(today);
|
||||
return { ok: true, id };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user