Persist document processing outcomes separately from upload success
This commit is contained in:
+10
-2
@@ -98,12 +98,15 @@ export function openDb() {
|
||||
if (!columns.has(column)) db.exec(`ALTER TABLE belgeler ADD COLUMN ${column} TEXT`);
|
||||
}
|
||||
if (!columns.has('tur')) db.exec("ALTER TABLE belgeler ADD COLUMN tur TEXT NOT NULL DEFAULT 'firma'");
|
||||
if (!columns.has('isleme')) db.exec('ALTER TABLE belgeler ADD COLUMN isleme TEXT');
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_belge_ikn ON belgeler(email, ikn)');
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS schema_migrations (version TEXT PRIMARY KEY, applied_at TEXT NOT NULL)`);
|
||||
db.prepare('INSERT OR IGNORE INTO schema_migrations VALUES (?,?)')
|
||||
.run('20260906_document_columns', new Date().toISOString());
|
||||
db.prepare('INSERT OR IGNORE INTO schema_migrations VALUES (?,?)')
|
||||
.run('20260906_document_type', new Date().toISOString());
|
||||
db.prepare('INSERT OR IGNORE INTO schema_migrations VALUES (?,?)')
|
||||
.run('20260906_document_processing', new Date().toISOString());
|
||||
db.exec('COMMIT');
|
||||
} catch (error) {
|
||||
try { db.exec('ROLLBACK'); } catch { /* original error is authoritative */ }
|
||||
@@ -269,11 +272,16 @@ export function saveDocumentFile(email, metadata, bytes) {
|
||||
}
|
||||
|
||||
export function listDocuments(email, { ikn } = {}) {
|
||||
const alanlar = 'id, ad, kategori, boyut, mime, son_kullanma, ikn, olusturma, dosya, tur';
|
||||
const alanlar = 'id, ad, kategori, boyut, mime, son_kullanma, ikn, olusturma, dosya, tur, isleme';
|
||||
return withDb((db) => (ikn
|
||||
? db.prepare(`SELECT ${alanlar} FROM belgeler WHERE email=? AND ikn=? ORDER BY olusturma DESC`).all(email, ikn)
|
||||
: db.prepare(`SELECT ${alanlar} FROM belgeler WHERE email=? ORDER BY olusturma DESC`).all(email)
|
||||
).map(({dosya,...record}) => ({...record, erisilebilir: fs.existsSync(path.join(BELGE_DIR,dosya))})), []);
|
||||
).map(({dosya,isleme,...record}) => ({...record, isleme:isleme ? JSON.parse(isleme) : null, erisilebilir: fs.existsSync(path.join(BELGE_DIR,dosya))})), []);
|
||||
}
|
||||
|
||||
export function setDocumentProcessing(email,id,processing) {
|
||||
return withDb(db=>db.prepare('UPDATE belgeler SET isleme=? WHERE id=? AND email=?')
|
||||
.run(JSON.stringify({...processing,updatedAt:now()}),id,email).changes>0);
|
||||
}
|
||||
|
||||
export function getDocument(email, id) {
|
||||
|
||||
Reference in New Issue
Block a user