Erweitere Dry-Run-Ausgabe für Mitarbeiterimport
This commit is contained in:
@@ -29,6 +29,8 @@ type CliOptions = {
|
|||||||
branchMap: Record<string, number>
|
branchMap: Record<string, number>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ImportAction = "create" | "update"
|
||||||
|
|
||||||
function printHelp() {
|
function printHelp() {
|
||||||
console.log(`
|
console.log(`
|
||||||
Importiert die Excel-Datei "Mitarbeiterliste.xlsm" in auth_profiles.
|
Importiert die Excel-Datei "Mitarbeiterliste.xlsm" in auth_profiles.
|
||||||
@@ -262,6 +264,29 @@ function toWeeklyHours(monthlyHours: number | null) {
|
|||||||
return Math.round(((monthlyHours * 12) / 52) * 100) / 100
|
return Math.round(((monthlyHours * 12) / 52) * 100) / 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatValue(value: unknown) {
|
||||||
|
if (value == null) return "-"
|
||||||
|
if (typeof value === "object") return JSON.stringify(value)
|
||||||
|
return String(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectFieldChanges(existing: any, nextPayload: Record<string, unknown>) {
|
||||||
|
if (!existing) return []
|
||||||
|
|
||||||
|
const changes: string[] = []
|
||||||
|
for (const [field, nextValue] of Object.entries(nextPayload)) {
|
||||||
|
const currentValue = existing[field]
|
||||||
|
const currentFormatted = formatValue(currentValue)
|
||||||
|
const nextFormatted = formatValue(nextValue)
|
||||||
|
|
||||||
|
if (currentFormatted !== nextFormatted) {
|
||||||
|
changes.push(`${field}: ${currentFormatted} -> ${nextFormatted}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return changes
|
||||||
|
}
|
||||||
|
|
||||||
async function validateTenantAndBranches(
|
async function validateTenantAndBranches(
|
||||||
db: any,
|
db: any,
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
@@ -372,6 +397,7 @@ async function main() {
|
|||||||
|
|
||||||
let createdProfiles = 0
|
let createdProfiles = 0
|
||||||
let updatedProfiles = 0
|
let updatedProfiles = 0
|
||||||
|
const actionLogs: string[] = []
|
||||||
|
|
||||||
for (const row of preparedRows) {
|
for (const row of preparedRows) {
|
||||||
const nameParts = splitFullName(row.mitarbeiter)
|
const nameParts = splitFullName(row.mitarbeiter)
|
||||||
@@ -404,6 +430,21 @@ async function main() {
|
|||||||
active: existing?.active ?? true,
|
active: existing?.active ?? true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const action: ImportAction = existing ? "update" : "create"
|
||||||
|
const fieldChanges = existing ? collectFieldChanges(existing, payload) : []
|
||||||
|
const actionPrefix = action === "create" ? "ERSTELLEN" : "AKTUALISIEREN"
|
||||||
|
const branchLabel = `${row.betrieb} -> ${row.branchId}`
|
||||||
|
|
||||||
|
if (action === "create") {
|
||||||
|
actionLogs.push(
|
||||||
|
`[${actionPrefix}] ${row.mitarbeiter} | Branch ${branchLabel} | Vertrag ${row.anstellung || "-"} | Position ${row.position || "-"}`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
actionLogs.push(
|
||||||
|
`[${actionPrefix}] ${row.mitarbeiter} | Branch ${branchLabel} | Änderungen: ${fieldChanges.length ? fieldChanges.join("; ") : "keine"}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
if (!options.dryRun) {
|
if (!options.dryRun) {
|
||||||
const [created] = await db
|
const [created] = await db
|
||||||
@@ -458,6 +499,12 @@ async function main() {
|
|||||||
console.log(`[IMPORT MITARBEITER] Zeilen gelesen: ${rows.length}`)
|
console.log(`[IMPORT MITARBEITER] Zeilen gelesen: ${rows.length}`)
|
||||||
console.log(`[IMPORT MITARBEITER] Profile erstellt: ${createdProfiles}`)
|
console.log(`[IMPORT MITARBEITER] Profile erstellt: ${createdProfiles}`)
|
||||||
console.log(`[IMPORT MITARBEITER] Profile aktualisiert: ${updatedProfiles}`)
|
console.log(`[IMPORT MITARBEITER] Profile aktualisiert: ${updatedProfiles}`)
|
||||||
|
if (actionLogs.length) {
|
||||||
|
console.log("[IMPORT MITARBEITER] Details:")
|
||||||
|
for (const logLine of actionLogs) {
|
||||||
|
console.log(` ${logLine}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
console.log("")
|
console.log("")
|
||||||
} finally {
|
} finally {
|
||||||
await pool.end()
|
await pool.end()
|
||||||
|
|||||||
Reference in New Issue
Block a user