Merged PR 1933: fix(remission-data-access): replace hardcoded values with dynamic helper func...

fix(remission-data-access): replace hardcoded values with dynamic helper functions

Replace hardcoded assortment and retail price values in RemissionSearchService
with proper helper functions. Add getAssortmentFromItem and getRetailPriceFromItem
helpers to dynamically extract values from Item objects instead of using
static fallbacks.

Also fix potential undefined reference errors in remission list resource
by adding proper null checks for response merging operations.

Ref: #5321
This commit is contained in:
Nino Righi
2025-09-03 13:15:57 +00:00
committed by Andreas Schickinger
parent fa8e601660
commit c41355bcdf
5 changed files with 64 additions and 7 deletions

View File

@@ -0,0 +1,21 @@
import { Item } from '@isa/catalogue/data-access';
/**
* Helper function to extract the assortment string from an Item object.
* The assortment is constructed by concatenating the value and the last character of the key
* for each feature in the item's features array.
* @param {Item} item - The item object from which to extract the assortment
* @returns {string} The constructed assortment string
*/
export const getAssortmentFromItem = (item: Item): string => {
if (!item.features || item.features.length === 0) {
return '';
}
return item.features.reduce((acc, feature) => {
const value = feature.value ?? '';
const key = feature.key ?? '';
const lastChar = key.slice(-1); // gibt '' zurück, wenn key leer ist
return acc + `${value}|${lastChar}`;
}, '');
};

View File

@@ -0,0 +1,24 @@
import { Item } from '@isa/catalogue/data-access';
import { Price } from '../models';
/**
* Helper function to extract the retail price from an Item object.
* The function first checks for store-specific availabilities and falls back to the catalog availability if none are found.
* @param {Item} item - The item object from which to extract the retail price
* @returns {Price | undefined} The retail price if available, otherwise undefined
*/
export const getRetailPriceFromItem = (item: Item): Price | undefined => {
let availability = item?.storeAvailabilities?.find((f) => !!f);
if (!availability) {
availability = item?.catalogAvailability;
}
if (!availability.price) {
return {
value: { value: 0, currency: 'EUR' },
};
}
return availability.price as Price;
};

View File

@@ -7,3 +7,5 @@ export * from './get-receipt-item-quantity-from-return.helper';
export * from './get-receipt-number-from-return.helper';
export * from './get-receipt-items-from-return.helper';
export * from './get-package-numbers-from-return.helper';
export * from './get-retail-price-from-item.helper';
export * from './get-assortment-from-item.helper';

View File

@@ -26,6 +26,7 @@ import {
import { logger } from '@isa/core/logging';
import { Item } from '@isa/catalogue/data-access';
import { RemissionStockService } from './remission-stock.service';
import { getAssortmentFromItem, getRetailPriceFromItem } from '../helpers';
/**
* Service responsible for remission search operations.
@@ -387,9 +388,9 @@ export class RemissionSearchService {
let req = this.#remiService.RemiCanAddReturnItem({
data: items.map((i) => ({
product: i.item.product,
assortment: 'Basissortiment|B',
assortment: getAssortmentFromItem(i.item),
predefinedReturnQuantity: i.quantity,
retailPrice: i.item.catalogAvailability.price,
retailPrice: getRetailPriceFromItem(i.item),
source: 'manually-added',
returnReason: i.reason,
stock: { id: stock.id },
@@ -427,9 +428,9 @@ export class RemissionSearchService {
...i.item.product,
catalogProductNumber: String(i.item.id),
},
assortment: 'Basissortiment|B',
assortment: getAssortmentFromItem(i.item),
predefinedReturnQuantity: i.quantity,
retailPrice: i.item.catalogAvailability.price,
retailPrice: getRetailPriceFromItem(i.item),
source: 'manually-added',
returnReason: i.reason,
stock: { id: stock.id },

View File

@@ -114,15 +114,24 @@ export const createRemissionListResource = (
},
abortSignal,
);
console.log(res);
if (res) {
// Merge results if both lists are fetched
res.result = [
...(res.result || []),
...(fetchDepartmentListResponse.result || []),
];
res.hits += fetchDepartmentListResponse.hits;
res.skip += fetchDepartmentListResponse.skip;
res.take += fetchDepartmentListResponse.take;
if (fetchDepartmentListResponse?.hits) {
res.hits += fetchDepartmentListResponse.hits;
}
if (fetchDepartmentListResponse?.skip) {
res.skip += fetchDepartmentListResponse?.skip;
}
if (fetchDepartmentListResponse?.take) {
res.take += fetchDepartmentListResponse?.take;
}
} else {
res = fetchDepartmentListResponse;
}