mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 12:03:11 +00:00
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { isRealWoNumber } from "@/domain/work-orders/utils/wo-closability";
|
|
|
|
/** Board WO numbers are an 11-digit APM number or an SH placeholder of at most 11 characters. */
|
|
export const BOARD_WO_NUMBER_MAX_LENGTH = 11;
|
|
|
|
export const WO_NUMBER_FORMAT_MESSAGE =
|
|
"Work order number must be 11 digits or an SH number (e.g. SH00001)";
|
|
|
|
export const WO_NUMBER_DOWNGRADE_MESSAGE =
|
|
"Cannot replace an APM work order number with an internal number";
|
|
|
|
export function sanitizeBoardWoNumberInput(raw: string): string {
|
|
return raw
|
|
.replace(/[^a-zA-Z0-9]/g, "")
|
|
.toUpperCase()
|
|
.slice(0, BOARD_WO_NUMBER_MAX_LENGTH);
|
|
}
|
|
|
|
export function isProvisionalWoNumber(woNumber: string): boolean {
|
|
return /^SH/i.test(woNumber.trim());
|
|
}
|
|
|
|
export function isValidBoardWoNumber(woNumber: string): boolean {
|
|
return /^\d{11}$/.test(woNumber) || /^SH\d{1,9}$/i.test(woNumber);
|
|
}
|
|
|
|
/**
|
|
* SH-320: only an already-saved real APM number is protected from being replaced by an
|
|
* SH placeholder. A brand-new WO has no saved number, so the rule never applies there.
|
|
*/
|
|
export function isWoNumberDowngrade(savedWoNumber: string, nextWoNumber: string): boolean {
|
|
return isRealWoNumber(savedWoNumber) && isProvisionalWoNumber(nextWoNumber);
|
|
}
|