Fix: autor_name denormalisiert speichern statt expand (viewRule-Konflikt)

This commit is contained in:
rene 2026-05-21 20:03:55 +02:00
parent 74c3aa11b0
commit 0aca72af53
3 changed files with 19 additions and 6 deletions

View file

@ -48,12 +48,12 @@ export interface Neuigkeit {
id: string; id: string;
verein_id: string; verein_id: string;
autor_id: string; autor_id: string;
autor_name?: string;
text?: string; text?: string;
medien: string[]; medien: string[];
gruppe_ids: string[]; gruppe_ids: string[];
termin_id?: string; termin_id?: string;
created: string; created: string;
expand?: { autor_id?: { id: string; name: string } };
} }
export interface Reaktion { export interface Reaktion {

View file

@ -33,7 +33,7 @@
// Queries einzeln damit ein Fehler sichtbar wird // Queries einzeln damit ein Fehler sichtbar wird
const [nList, gList] = await Promise.all([ const [nList, gList] = await Promise.all([
pb.collection('neuigkeiten').getFullList<Neuigkeit>({ pb.collection('neuigkeiten').getFullList<Neuigkeit>({
sort: '-created', expand: 'autor_id', sort: '-created',
}), }),
pb.collection('gruppen').getFullList<Gruppe>({ sort: 'name' }), pb.collection('gruppen').getFullList<Gruppe>({ sort: 'name' }),
]); ]);
@ -100,6 +100,7 @@
const form = new FormData(); const form = new FormData();
form.append('verein_id', vid); form.append('verein_id', vid);
form.append('autor_id', userId()); form.append('autor_id', userId());
form.append('autor_name', pb.authStore.record?.name ?? '');
if (fText.trim()) form.append('text', fText.trim()); if (fText.trim()) form.append('text', fText.trim());
if (fTerminId) form.append('termin_id', fTerminId); if (fTerminId) form.append('termin_id', fTerminId);
for (const id of fGruppeIds) form.append('gruppe_ids', id); for (const id of fGruppeIds) form.append('gruppe_ids', id);
@ -107,9 +108,7 @@
for (const file of Array.from(fDateien)) form.append('medien', file); for (const file of Array.from(fDateien)) form.append('medien', file);
} }
const neu = await pb.collection('neuigkeiten').create<Neuigkeit>(form, { const neu = await pb.collection('neuigkeiten').create<Neuigkeit>(form);
expand: 'autor_id',
});
neuigkeiten = [neu, ...neuigkeiten]; neuigkeiten = [neu, ...neuigkeiten];
showForm = false; showForm = false;
fText = ''; fGruppeIds = []; fTerminId = ''; fDateien = null; previews = []; fText = ''; fGruppeIds = []; fTerminId = ''; fDateien = null; previews = [];
@ -161,7 +160,7 @@
} }
function autorName(n: Neuigkeit): string { function autorName(n: Neuigkeit): string {
return (n.expand?.autor_id?.name) ?? 'Unbekannt'; return n.autor_name || 'Unbekannt';
} }
function terminName(id: string): string { function terminName(id: string): string {

View file

@ -0,0 +1,14 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const c = app.findCollectionByNameOrId("pbc_neuigkeiten")
c.fields.addAt(99, new Field({
"type": "text", "id": "text2001000206", "name": "autor_name",
"help": "", "hidden": false, "presentable": false, "required": false, "system": false,
"autogeneratePattern": "", "min": 0, "max": 0, "pattern": ""
}))
app.save(c)
}, (app) => {
const c = app.findCollectionByNameOrId("pbc_neuigkeiten")
c.fields.removeById("text2001000206")
app.save(c)
})