refactor 'Datei zu Vorgang hinzufügen': Add model files to existing cases

This commit is contained in:
2025-07-14 13:54:08 +02:00
parent fa59db7a88
commit 873a382f69
2 changed files with 29 additions and 4 deletions

View File

@@ -39,6 +39,14 @@ export const getVorgang = function (caseId: string) {
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
* @returns list of available cases

View File

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