From bde0d53ba305880144fc008196d6ba3e6fdaa215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Eduardo=20Garc=C3=ADa=20M=C3=A1rquez?= Date: Thu, 8 Jan 2026 00:30:09 -0500 Subject: [PATCH] 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. --- .../core/constants/enrollment.constants.ts | 15 +++++++ .../constants/error-messages.constants.ts | 42 +++++++++++++++++++ src/frontend/src/app/core/constants/index.ts | 2 + 3 files changed, 59 insertions(+) create mode 100644 src/frontend/src/app/core/constants/enrollment.constants.ts create mode 100644 src/frontend/src/app/core/constants/error-messages.constants.ts create mode 100644 src/frontend/src/app/core/constants/index.ts diff --git a/src/frontend/src/app/core/constants/enrollment.constants.ts b/src/frontend/src/app/core/constants/enrollment.constants.ts new file mode 100644 index 0000000..081db8c --- /dev/null +++ b/src/frontend/src/app/core/constants/enrollment.constants.ts @@ -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; diff --git a/src/frontend/src/app/core/constants/error-messages.constants.ts b/src/frontend/src/app/core/constants/error-messages.constants.ts new file mode 100644 index 0000000..85040fb --- /dev/null +++ b/src/frontend/src/app/core/constants/error-messages.constants.ts @@ -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 = { + [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 = { + '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', +}; diff --git a/src/frontend/src/app/core/constants/index.ts b/src/frontend/src/app/core/constants/index.ts new file mode 100644 index 0000000..f6b109c --- /dev/null +++ b/src/frontend/src/app/core/constants/index.ts @@ -0,0 +1,2 @@ +export * from './enrollment.constants'; +export * from './error-messages.constants';