Files
ISA-Frontend/libs/oms/data-access/src/lib/helpers/reward/get-processing-status-state.helper.ts
Nino Righi a49ea25fd0 Merged PR 1993: feat(action-handler, printing, schemas)
1 commit: Bestellbestätigung drucken
2. commit: Schemas
3. commit: Action/Command handler

feat(action-handler, printing, schemas): add handle command service for automated action execution

Implement HandleCommandService and facade to execute order actions automatically
after reward collection. Add action handler infrastructure with 23 handlers
(Accepted, Arrived, Assembled, etc.). Integrate automatic receipt fetching for
print commands. Add schema validation for command handling and receipt queries.
Update reward confirmation to trigger actions after successful collection.

- Add HandleCommandService with command orchestration
- Add HandleCommandFacade as public API layer
- Create schemas: HandleCommandSchema, FetchReceiptsByOrderItemSubsetIdsSchema
- Add helpers: getMainActions, buildItemQuantityMap
- Register 23 action handlers in reward confirmation routes
- Support PRINT_SHIPPINGNOTE and PRINT_SMALLAMOUNTINVOICE auto-fetching
- Update CoreCommandModule for forRoot/forChild patterns
- Add comprehensive unit tests for new services and helpers
- Apply prettier formatting to command and printing modules

Ref: #5394
2025-11-03 20:00:53 +00:00

57 lines
1.8 KiB
TypeScript

import { OrderItemProcessingStatusValue } from '../../schemas';
import { ProcessingStatusState } from '../../models';
/**
* Determines the completion status of order items based on their processing statuses.
*
* @param statuses - Array of processing status values to evaluate
* @returns The processing status state:
* - `ProcessingStatusState.Cancelled` if all items are cancelled
* - `ProcessingStatusState.NotFound` if all items are marked as not available
* - `ProcessingStatusState.Collected` if all items are collected
* - `undefined` if statuses don't match any completion state
*
* @example
* ```ts
* const statuses = [512, 1024]; // StorniertKunde, Storniert
* getProcessingStatusState(statuses); // ProcessingStatusState.Cancelled
* ```
*/
export const getProcessingStatusState = (
statuses: number[] | undefined,
): ProcessingStatusState | undefined => {
if (!statuses || statuses.length === 0) {
return undefined;
}
// Check if all statuses are cancelled
const allCancelled = statuses.every(
(status) =>
status === OrderItemProcessingStatusValue.StorniertKunde ||
status === OrderItemProcessingStatusValue.Storniert ||
status === OrderItemProcessingStatusValue.StorniertLieferant ||
status === OrderItemProcessingStatusValue.AnsLagerNichtAbgeholt,
);
if (allCancelled) {
return ProcessingStatusState.Cancelled;
}
// Check if all statuses are not available
const allNotFound = statuses.every(
(status) => status === OrderItemProcessingStatusValue.NichtLieferbar,
);
if (allNotFound) {
return ProcessingStatusState.NotFound;
}
// Check if all statuses are collected
const allCollected = statuses.every(
(status) => status === OrderItemProcessingStatusValue.Abgeholt,
);
if (allCollected) {
return ProcessingStatusState.Collected;
}
return undefined;
};