fix(export): exclude soft-deleted measurements in export bundle reads

v1.4.41 W-DELETED-2 — full-backup JSON, per-type CSV, and the legacy
/api/export endpoint now scope reads to deletedAt: null so iOS undo
or pending-sync rows never reach the user's downloaded file or the
admin restore round-trip.
This commit is contained in:
Marc-André Bombeck committed 2026-05-21 17:12:31 +02:00
1 parent bba38b8c66
commit a62b94983b
3 files changed
+22 -4

No files matched your search

+4 -1
View File
@@ -36,7 +36,10 @@ export const GET = apiHandler(async (request: NextRequest) => {
const [measurements, medications, intakeEvents, moodEntries] =
await Promise.all([
prisma.measurement.findMany({
where: { userId: user.id },
// v1.4.41 W-DELETED-2 — soft-deleted rows are excluded from the
// user-initiated backup bundle so the round-trip via admin
// restore does not resurrect deleted measurements.
where: { userId: user.id, deletedAt: null },
orderBy: { measuredAt: "desc" },
}),
// Explicit `select` on the schedule columns — see the matching
+14 -2
View File
@@ -89,9 +89,21 @@ function safeDate(value: string): Date | undefined {
function buildWhere(
userId: string,
range: { since?: Date; until?: Date },
): { userId: string; measuredAt?: { gte?: Date; lte?: Date } } {
const where: { userId: string; measuredAt?: { gte?: Date; lte?: Date } } = {
): {
userId: string;
deletedAt: null;
measuredAt?: { gte?: Date; lte?: Date };
} {
// v1.4.41 W-DELETED-2 — soft-deleted measurements stay out of every
// per-type CSV download so an undo or pending-sync row never reaches
// the user's local file.
const where: {
userId: string;
deletedAt: null;
measuredAt?: { gte?: Date; lte?: Date };
} = {
userId,
deletedAt: null,
};
if (range.since || range.until) {
where.measuredAt = {};
+4 -1
View File
@@ -55,7 +55,10 @@ export const GET = apiHandler(async (request: NextRequest) => {
if (type === "measurements" || type === "all") {
const measurements = await prisma.measurement.findMany({
where: { userId },
// v1.4.41 W-DELETED-2 — exclude soft-deleted measurements from
// the legacy /api/export endpoint so CSV + JSON downloads stay
// consistent with the live measurement reads.
where: { userId, deletedAt: null },
orderBy: { measuredAt: "desc" },
});
data.measurements =