f034_sqlite_database #19

Merged
jared merged 34 commits from f034_sqlite_database into development 2025-07-24 14:34:39 +02:00
2 changed files with 29 additions and 4 deletions
Showing only changes of commit 873a382f69 - Show all commits

View File

@@ -39,6 +39,14 @@ export const getVorgang = function (caseId: string) {
return res; return res;
}; };
export const getVorgangByName = function (caseName: string) {
let getVorgangByName_stmt = `SELECT token, name, pw FROM cases WHERE name = ?`;
const stmt = db.prepare(getVorgangByName_stmt);
const res = stmt.get(caseName);
return res;
};
/** /**
* Fetches list of vorgänge from s3 bucket * Fetches list of vorgänge from s3 bucket
* @returns list of available cases * @returns list of available cases

View File

@@ -5,6 +5,7 @@ import { fail } from '@sveltejs/kit';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { db } from '$lib/server/dbService'; import { db } from '$lib/server/dbService';
import { getVorgangByName, vorgangExists, vorgangNameExists } from '$lib/server/vorgangService';
const isRequiredFieldValid = (value: unknown) => { const isRequiredFieldValid = (value: unknown) => {
if (value == null) return false; if (value == null) return false;
@@ -24,11 +25,27 @@ export const actions = {
const fileName = data.get('fileName'); const fileName = data.get('fileName');
// store case in database // store case in database
// skip if Vorgang exists and token not changed
let token = uuidv4(); const vorgang_exists = vorgangNameExists(vorgang);
let insert_stmt = `INSERT INTO cases (token, name, pw) VALUES (?, ?, ?)`; let token;
const stmt = db.prepare(insert_stmt);
stmt.run(token, vorgang, code); if (!vorgang_exists) {
token = uuidv4();
let insert_stmt = `INSERT INTO cases (token, name, pw) VALUES (?, ?, ?)`;
const stmt = db.prepare(insert_stmt);
stmt.run(token, vorgang, code);
} else {
// vorgang exists
// check if PW was changed, and update DB if it was
const vorg = getVorgangByName(vorgang);
token = vorg.token;
if (vorg.pw != code) {
let update_stmt = `UPDATE cases SET pw = ? WHERE name = ?`;
const stmt = db.prepare(update_stmt);
stmt.run(code, vorgang);
}
}
let objectName = `${token}/${name}`; let objectName = `${token}/${name}`;
switch (type) { switch (type) {