- Introduced `DivisionsModule` to manage organizational divisions, including read and write controllers. - Created database migrations for the `divisions` table and related constraints. - Implemented validation for division name and code with corresponding utility functions. - Added service and repository layers for handling division data operations. - Developed unit tests for the divisions service, repository, and controllers to ensure functionality and correctness. - Updated application module to include the new `ConfigurationModule` for better organization.
27 lines
737 B
TypeScript
27 lines
737 B
TypeScript
export const DIVISION_NAME_MAX_LENGTH = 64;
|
|
export const DIVISION_CODE_MAX_LENGTH = 16;
|
|
|
|
/** Letters with single spaces between words. */
|
|
export const DIVISION_NAME_PATTERN = /^[A-Za-z]+(?: [A-Za-z]+)*$/;
|
|
|
|
/** Alphanumeric and underscore; no spaces. */
|
|
export const DIVISION_CODE_PATTERN = /^[A-Za-z0-9_]+$/;
|
|
|
|
export function isValidDivisionName(raw: string): boolean {
|
|
return (
|
|
typeof raw === 'string' &&
|
|
raw.length > 0 &&
|
|
raw.length <= DIVISION_NAME_MAX_LENGTH &&
|
|
DIVISION_NAME_PATTERN.test(raw)
|
|
);
|
|
}
|
|
|
|
export function isValidDivisionCode(raw: string): boolean {
|
|
return (
|
|
typeof raw === 'string' &&
|
|
raw.length > 0 &&
|
|
raw.length <= DIVISION_CODE_MAX_LENGTH &&
|
|
DIVISION_CODE_PATTERN.test(raw)
|
|
);
|
|
}
|