mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merged PR 2018: add reward points (Prämie) display and label
Related work items: #5413
This commit is contained in:
committed by
Nino Righi
parent
9c989055cb
commit
4a7b74a6c5
@@ -1,6 +1,6 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { LogisticianDTO } from '@generated/swagger/oms-api';
|
||||
import { Order } from '../models';
|
||||
import { DisplayOrder } from '../models';
|
||||
import { OrderCreationService } from '../services';
|
||||
|
||||
/**
|
||||
@@ -22,7 +22,7 @@ export class OrderCreationFacade {
|
||||
* @returns Promise resolving to array of created orders
|
||||
* @throws {Error} If checkoutId is invalid or order creation fails
|
||||
*/
|
||||
async createOrdersFromCheckout(checkoutId: number): Promise<Order[]> {
|
||||
async createOrdersFromCheckout(checkoutId: number): Promise<DisplayOrder[]> {
|
||||
return this.#orderCreationService.createOrdersFromCheckout(checkoutId);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './return-process';
|
||||
export * from './reward';
|
||||
export * from './get-main-actions.helper';
|
||||
export * from './order';
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { OrderItemDTO, DisplayOrderItemDTO } from '@generated/swagger/oms-api';
|
||||
|
||||
export function getOrderItemRewardFeatureHelper(
|
||||
orderItem: OrderItemDTO | DisplayOrderItemDTO | undefined,
|
||||
): undefined | number {
|
||||
if (!orderItem || !orderItem.features) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Return 12.345 as string needs to be converted to number. Remove . to avoid issues with different locales.
|
||||
const rewardFeature = orderItem.features['praemie'];
|
||||
|
||||
return rewardFeature
|
||||
? Number(rewardFeature.replace('.', '').replace(',', '.'))
|
||||
: undefined;
|
||||
}
|
||||
1
libs/oms/data-access/src/lib/helpers/order/index.ts
Normal file
1
libs/oms/data-access/src/lib/helpers/order/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { getOrderItemRewardFeatureHelper as getOrderItemRewardFeature } from './get-order-item-reward-feature.helper';
|
||||
@@ -1,15 +1,15 @@
|
||||
import { DisplayOrderDTO } from '@generated/swagger/oms-api';
|
||||
|
||||
/**
|
||||
* Order model representing a completed checkout order.
|
||||
* This is an alias to the OMS API's DisplayOrderDTO.
|
||||
*
|
||||
* @remarks
|
||||
* DisplayOrderDTO contains:
|
||||
* - Order metadata (orderNumber, orderDate, orderType, orderValue)
|
||||
* - Customer information (buyer, payer, shippingAddress)
|
||||
* - Order items and their details
|
||||
* - Payment information
|
||||
* - Branch and delivery information
|
||||
*/
|
||||
export type Order = DisplayOrderDTO;
|
||||
import { DisplayOrderDTO } from '@generated/swagger/oms-api';
|
||||
|
||||
/**
|
||||
* Order model representing a completed checkout order.
|
||||
* This is an alias to the OMS API's DisplayOrderDTO.
|
||||
*
|
||||
* @remarks
|
||||
* DisplayOrderDTO contains:
|
||||
* - Order metadata (orderNumber, orderDate, orderType, orderValue)
|
||||
* - Customer information (buyer, payer, shippingAddress)
|
||||
* - Order items and their details
|
||||
* - Payment information
|
||||
* - Branch and delivery information
|
||||
*/
|
||||
export type DisplayOrder = DisplayOrderDTO;
|
||||
@@ -1,9 +1,9 @@
|
||||
export * from './address-type';
|
||||
export * from './buyer';
|
||||
export * from './can-return';
|
||||
export * from './display-order';
|
||||
export * from './eligible-for-return';
|
||||
export * from './logistician';
|
||||
export * from './order';
|
||||
export * from './processing-status-state';
|
||||
export * from './quantity';
|
||||
export * from './receipt-item-list-item';
|
||||
|
||||
@@ -69,5 +69,3 @@ export const DisplayOrderSchema = z
|
||||
TermsOfDeliverySchema.describe('Terms of delivery').optional(),
|
||||
})
|
||||
.extend(EntitySchema.shape);
|
||||
|
||||
export type DisplayOrder = z.infer<typeof DisplayOrderSchema>;
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import {
|
||||
OrderCheckoutService,
|
||||
LogisticianService,
|
||||
LogisticianDTO,
|
||||
} from '@generated/swagger/oms-api';
|
||||
import { ResponseArgsError, takeUntilAborted } from '@isa/common/data-access';
|
||||
import { logger } from '@isa/core/logging';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { Order } from '../models';
|
||||
|
||||
/**
|
||||
* Service for creating orders from checkout.
|
||||
*
|
||||
* @remarks
|
||||
* This service handles order creation operations that are part of the OMS domain.
|
||||
* It provides methods to:
|
||||
* - Create orders from a completed checkout
|
||||
* - Retrieve logistician information
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class OrderCreationService {
|
||||
#logger = logger(() => ({ service: 'OrderCreationService' }));
|
||||
readonly #orderCheckoutService = inject(OrderCheckoutService);
|
||||
readonly #logisticianService = inject(LogisticianService);
|
||||
|
||||
/**
|
||||
* Creates orders from a checkout.
|
||||
*
|
||||
* @param checkoutId - The ID of the checkout to create orders from
|
||||
* @returns Promise resolving to array of created orders
|
||||
* @throws {Error} If checkoutId is invalid or order creation fails
|
||||
*/
|
||||
async createOrdersFromCheckout(checkoutId: number): Promise<Order[]> {
|
||||
if (!checkoutId) {
|
||||
throw new Error(`Invalid checkoutId: ${checkoutId}`);
|
||||
}
|
||||
|
||||
const req$ = this.#orderCheckoutService.OrderCheckoutCreateOrderPOST({
|
||||
checkoutId,
|
||||
});
|
||||
|
||||
const res = await firstValueFrom(req$);
|
||||
|
||||
if (res.error) {
|
||||
const error = new ResponseArgsError(res);
|
||||
this.#logger.error('Failed to create orders', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res.result as Order[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves logistician information.
|
||||
*
|
||||
* @param logisticianNumber - The logistician number to retrieve (defaults to '2470')
|
||||
* @param abortSignal - Optional signal to abort the operation
|
||||
* @returns Promise resolving to logistician data
|
||||
* @throws {Error} If logistician is not found or request fails
|
||||
*/
|
||||
async getLogistician(
|
||||
logisticianNumber = '2470',
|
||||
abortSignal?: AbortSignal,
|
||||
): Promise<LogisticianDTO> {
|
||||
let req$ = this.#logisticianService.LogisticianGetLogisticians({});
|
||||
if (abortSignal) req$ = req$.pipe(takeUntilAborted(abortSignal));
|
||||
|
||||
const res = await firstValueFrom(req$);
|
||||
|
||||
if (res.error) {
|
||||
const error = new ResponseArgsError(res);
|
||||
this.#logger.error('Failed to get logistician', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const logistician = res.result?.find(
|
||||
(l) => l.logisticianNumber === logisticianNumber,
|
||||
);
|
||||
|
||||
if (!logistician) {
|
||||
throw new Error(`Logistician ${logisticianNumber} not found`);
|
||||
}
|
||||
|
||||
return logistician;
|
||||
}
|
||||
}
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import {
|
||||
OrderCheckoutService,
|
||||
LogisticianService,
|
||||
LogisticianDTO,
|
||||
} from '@generated/swagger/oms-api';
|
||||
import { ResponseArgsError, takeUntilAborted } from '@isa/common/data-access';
|
||||
import { logger } from '@isa/core/logging';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { DisplayOrder } from '../models';
|
||||
|
||||
/**
|
||||
* Service for creating orders from checkout.
|
||||
*
|
||||
* @remarks
|
||||
* This service handles order creation operations that are part of the OMS domain.
|
||||
* It provides methods to:
|
||||
* - Create orders from a completed checkout
|
||||
* - Retrieve logistician information
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class OrderCreationService {
|
||||
#logger = logger(() => ({ service: 'OrderCreationService' }));
|
||||
readonly #orderCheckoutService = inject(OrderCheckoutService);
|
||||
readonly #logisticianService = inject(LogisticianService);
|
||||
|
||||
/**
|
||||
* Creates orders from a checkout.
|
||||
*
|
||||
* @param checkoutId - The ID of the checkout to create orders from
|
||||
* @returns Promise resolving to array of created orders
|
||||
* @throws {Error} If checkoutId is invalid or order creation fails
|
||||
*/
|
||||
async createOrdersFromCheckout(checkoutId: number): Promise<DisplayOrder[]> {
|
||||
if (!checkoutId) {
|
||||
throw new Error(`Invalid checkoutId: ${checkoutId}`);
|
||||
}
|
||||
|
||||
const req$ = this.#orderCheckoutService.OrderCheckoutCreateOrderPOST({
|
||||
checkoutId,
|
||||
});
|
||||
|
||||
const res = await firstValueFrom(req$);
|
||||
|
||||
if (res.error) {
|
||||
const error = new ResponseArgsError(res);
|
||||
this.#logger.error('Failed to create orders', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res.result as DisplayOrder[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves logistician information.
|
||||
*
|
||||
* @param logisticianNumber - The logistician number to retrieve (defaults to '2470')
|
||||
* @param abortSignal - Optional signal to abort the operation
|
||||
* @returns Promise resolving to logistician data
|
||||
* @throws {Error} If logistician is not found or request fails
|
||||
*/
|
||||
async getLogistician(
|
||||
logisticianNumber = '2470',
|
||||
abortSignal?: AbortSignal,
|
||||
): Promise<LogisticianDTO> {
|
||||
let req$ = this.#logisticianService.LogisticianGetLogisticians({});
|
||||
if (abortSignal) req$ = req$.pipe(takeUntilAborted(abortSignal));
|
||||
|
||||
const res = await firstValueFrom(req$);
|
||||
|
||||
if (res.error) {
|
||||
const error = new ResponseArgsError(res);
|
||||
this.#logger.error('Failed to get logistician', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const logistician = res.result?.find(
|
||||
(l) => l.logisticianNumber === logisticianNumber,
|
||||
);
|
||||
|
||||
if (!logistician) {
|
||||
throw new Error(`Logistician ${logisticianNumber} not found`);
|
||||
}
|
||||
|
||||
return logistician;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user