feat(frontend): add centralized constants for enrollment limits
- Create enrollment.constants.ts with MAX_SUBJECTS, MAX_CREDITS, CREDITS_PER_SUBJECT - Create error-messages.constants.ts with ERROR_CODES and RESTRICTION_TRANSLATIONS - Remove empty folders: core/state, shared/directives, features/dashboard - Use 'as const' for type-safe constants This improves maintainability by having a single source of truth for business rules.
This commit is contained in:
parent
b234c9c5de
commit
bde0d53ba3
|
|
@ -0,0 +1,15 @@
|
||||||
|
/**
|
||||||
|
* Enrollment business rules constants.
|
||||||
|
* These values must match the backend domain rules.
|
||||||
|
*/
|
||||||
|
export const ENROLLMENT_LIMITS = {
|
||||||
|
/** Maximum number of subjects a student can enroll in */
|
||||||
|
MAX_SUBJECTS: 3,
|
||||||
|
/** Maximum total credits a student can have */
|
||||||
|
MAX_CREDITS: 9,
|
||||||
|
/** Credits per subject (fixed value) */
|
||||||
|
CREDITS_PER_SUBJECT: 3,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/** Type for enrollment limits to ensure type safety */
|
||||||
|
export type EnrollmentLimits = typeof ENROLLMENT_LIMITS;
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
/**
|
||||||
|
* Error codes returned by the GraphQL API.
|
||||||
|
*/
|
||||||
|
export const ERROR_CODES = {
|
||||||
|
MAX_ENROLLMENTS: 'MAX_ENROLLMENTS',
|
||||||
|
SAME_PROFESSOR: 'SAME_PROFESSOR',
|
||||||
|
STUDENT_NOT_FOUND: 'STUDENT_NOT_FOUND',
|
||||||
|
SUBJECT_NOT_FOUND: 'SUBJECT_NOT_FOUND',
|
||||||
|
DUPLICATE_ENROLLMENT: 'DUPLICATE_ENROLLMENT',
|
||||||
|
VALIDATION_ERROR: 'VALIDATION_ERROR',
|
||||||
|
NETWORK_ERROR: 'NETWORK_ERROR',
|
||||||
|
SERVER_ERROR: 'SERVER_ERROR',
|
||||||
|
UNKNOWN: 'UNKNOWN',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User-friendly error messages in Spanish.
|
||||||
|
* Maps API error codes to display messages.
|
||||||
|
*/
|
||||||
|
export const ERROR_MESSAGES: Record<ErrorCode, string> = {
|
||||||
|
[ERROR_CODES.MAX_ENROLLMENTS]: 'Has alcanzado el límite máximo de 3 materias',
|
||||||
|
[ERROR_CODES.SAME_PROFESSOR]: 'Ya tienes una materia con este profesor',
|
||||||
|
[ERROR_CODES.STUDENT_NOT_FOUND]: 'El estudiante no existe en el sistema',
|
||||||
|
[ERROR_CODES.SUBJECT_NOT_FOUND]: 'La materia seleccionada no existe',
|
||||||
|
[ERROR_CODES.DUPLICATE_ENROLLMENT]: 'Ya estás inscrito en esta materia',
|
||||||
|
[ERROR_CODES.VALIDATION_ERROR]: 'Los datos ingresados no son válidos',
|
||||||
|
[ERROR_CODES.NETWORK_ERROR]: 'No se pudo conectar con el servidor',
|
||||||
|
[ERROR_CODES.SERVER_ERROR]: 'Error interno del servidor',
|
||||||
|
[ERROR_CODES.UNKNOWN]: 'Ha ocurrido un error inesperado',
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translations for enrollment restriction reasons.
|
||||||
|
* Maps API English messages to Spanish display messages.
|
||||||
|
*/
|
||||||
|
export const RESTRICTION_TRANSLATIONS: Record<string, string> = {
|
||||||
|
'Already enrolled': 'Ya inscrito',
|
||||||
|
'Already have a subject with this professor': 'Ya tienes una materia con este profesor',
|
||||||
|
'Maximum 3 subjects reached': 'Máximo 3 materias alcanzado',
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './enrollment.constants';
|
||||||
|
export * from './error-messages.constants';
|
||||||
Loading…
Reference in New Issue