fixed settings

This commit is contained in:
2025-10-20 02:30:40 +02:00
parent e80bb81b5d
commit ec28c061a0
11 changed files with 280 additions and 102 deletions

View File

@@ -1,25 +1,51 @@
// backend/src/models/helpers/employeeHelpers.ts
import { Employee, CreateEmployeeRequest, EmployeeAvailability } from '../Employee.js';
// Simplified validation - use schema validation instead
// Email generation function (same as in controllers)
function generateEmail(firstname: string, lastname: string): string {
// Convert German umlauts to their expanded forms
const convertUmlauts = (str: string): string => {
return str
.toLowerCase()
.replace(/ü/g, 'ue')
.replace(/ö/g, 'oe')
.replace(/ä/g, 'ae')
.replace(/ß/g, 'ss');
};
// Remove any remaining special characters and convert to lowercase
const cleanFirstname = convertUmlauts(firstname).replace(/[^a-z0-9]/g, '');
const cleanLastname = convertUmlauts(lastname).replace(/[^a-z0-9]/g, '');
return `${cleanFirstname}.${cleanLastname}@sp.de`;
}
// UPDATED: Validation for new employee model
export function validateEmployeeData(employee: CreateEmployeeRequest): string[] {
const errors: string[] = [];
if (!employee.email?.includes('@')) {
errors.push('Valid email is required');
}
// Email is now auto-generated, so no email validation needed
if (employee.password?.length < 6) {
errors.push('Password must be at least 6 characters long');
}
if (!employee.name?.trim() || employee.name.trim().length < 2) {
errors.push('Name is required and must be at least 2 characters long');
if (!employee.firstname?.trim() || employee.firstname.trim().length < 2) {
errors.push('First name is required and must be at least 2 characters long');
}
if (!employee.lastname?.trim() || employee.lastname.trim().length < 2) {
errors.push('Last name is required and must be at least 2 characters long');
}
return errors;
}
// Generate email for employee (new helper function)
export function generateEmployeeEmail(firstname: string, lastname: string): string {
return generateEmail(firstname, lastname);
}
// Simplified business logic helpers
export const isManager = (employee: Employee): boolean =>
employee.employeeType === 'manager';
@@ -38,3 +64,26 @@ export const canEmployeeWorkAlone = (employee: Employee): boolean =>
export const getEmployeeWorkHours = (employee: Employee): number =>
isManager(employee) ? 999 : (employee.contractType === 'small' ? 1 : 2);
// New helper for full name display
export const getFullName = (employee: { firstname: string; lastname: string }): string =>
`${employee.firstname} ${employee.lastname}`;
// Helper for availability validation
export function validateAvailabilityData(availability: Omit<EmployeeAvailability, 'id' | 'employeeId'>): string[] {
const errors: string[] = [];
if (!availability.planId) {
errors.push('Plan ID is required');
}
if (!availability.shiftId) {
errors.push('Shift ID is required');
}
if (![1, 2, 3].includes(availability.preferenceLevel)) {
errors.push('Preference level must be 1, 2, or 3');
}
return errors;
}