Update
This commit is contained in:
1 parent
911dcace72
commit
9c68c414d8
53 files changed
+2919
-469
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { getAllRows, getRowById, insertRow, updateRow } from '../crud'
|
||||
import type { Assignment, AssignmentType, Consultant } from '../../../src/db/types'
|
||||
|
||||
export const listAssignments = (): Assignment[] => getAllRows<Assignment>('assignments')
|
||||
export const listAssignmentsNewestFirst = (): Assignment[] =>
|
||||
getAllRows<Assignment>('assignments').sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
|
||||
export const getAssignment = (id: number): Assignment | undefined => getRowById<Assignment>('assignments', id)
|
||||
export const addAssignment = (a: Omit<Assignment, 'id'>): number => insertRow('assignments', a)
|
||||
export const updateAssignment = (id: number, patch: Partial<Assignment>): number => updateRow('assignments', id, patch)
|
||||
|
||||
export interface AssignmentWithDetails extends Assignment {
|
||||
typeName: string
|
||||
instituteeNames: string[]
|
||||
}
|
||||
|
||||
/** Für die Dashboard-Liste: Assignments mit aufgelöstem Typ- und Institutee-Namen, neueste zuerst. */
|
||||
export function listAssignmentsWithDetails(): AssignmentWithDetails[] {
|
||||
const raw = listAssignmentsNewestFirst()
|
||||
const types = getAllRows<AssignmentType>('assignmentTypes')
|
||||
const consultants = getAllRows<Consultant>('consultants')
|
||||
const typeMap = new Map<number, AssignmentType>(types.map(t => [t.id!, t]))
|
||||
const consMap = new Map<number, Consultant>(consultants.map(c => [c.id!, c]))
|
||||
return raw.map(a => ({
|
||||
...a,
|
||||
typeName: typeMap.get(a.assignmentTypeId)?.name ?? '—',
|
||||
instituteeNames: a.instituteeIds.map(id => {
|
||||
const c = consMap.get(id)
|
||||
return c ? `${c.firstName} ${c.lastName}` : '?'
|
||||
}),
|
||||
}))
|
||||
}
|
||||
Reference in new issue
Block a user