fix: validate document uploads and allow clearing expiry dates

This commit is contained in:
2026-09-06 09:14:43 +03:00
parent 0d2cf584e7
commit 43dc4feb31
5 changed files with 62 additions and 10 deletions
+6 -4
View File
@@ -262,12 +262,14 @@ export function getDocument(email, id) {
}
/** Belge üst verisi: son kullanma / kategori (süre takibi için). */
export function updateDocument(email, id, { sonKullanma, kategori } = {}) {
export function updateDocument(email, id, patch = {}) {
return withDb((db) => {
const hasDate = Object.hasOwn(patch,'sonKullanma');
const hasCategory = Object.hasOwn(patch,'kategori');
const r = db.prepare(`UPDATE belgeler SET
son_kullanma = COALESCE(?, son_kullanma),
kategori = COALESCE(?, kategori)
WHERE id=? AND email=?`).run(sonKullanma ?? null, kategori ?? null, id, email);
son_kullanma = CASE WHEN ? THEN ? ELSE son_kullanma END,
kategori = CASE WHEN ? THEN ? ELSE kategori END
WHERE id=? AND email=?`).run(Number(hasDate), patch.sonKullanma ?? null, Number(hasCategory), patch.kategori ?? null, id, email);
return r.changes > 0;
}, false);
}