diff --git a/libs/checkout/data-access/src/lib/services/checkout.service.ts b/libs/checkout/data-access/src/lib/services/checkout.service.ts index 3e110c169..a61c0b769 100644 --- a/libs/checkout/data-access/src/lib/services/checkout.service.ts +++ b/libs/checkout/data-access/src/lib/services/checkout.service.ts @@ -7,16 +7,9 @@ import { StoreCheckoutPayerService, StoreCheckoutPaymentService, DestinationDTO, - BuyerDTO, - PayerDTO, - AvailabilityDTO, } from '@generated/swagger/checkout-api'; -import { - EntityContainer, - ResponseArgsError, - takeUntilAborted, -} from '@isa/common/data-access'; +import { EntityContainer, ResponseArgsError } from '@isa/common/data-access'; import { logger } from '@isa/core/logging'; import { firstValueFrom } from 'rxjs'; import { ShoppingCartService } from './shopping-cart.service'; @@ -29,7 +22,6 @@ import { PaymentType, } from '../schemas'; import { - Order, OrderOptionsAnalysis, CustomerTypeAnalysis, Checkout, @@ -155,7 +147,6 @@ export class CheckoutService { this.#logger.debug('Creating or refreshing checkout'); const initialCheckout = await this.refreshCheckout( validated.shoppingCartId, - abortSignal, ); const checkoutId = initialCheckout.id; @@ -169,7 +160,6 @@ export class CheckoutService { await this.updateDestinationsForCustomer( validated.shoppingCartId, validated.customerFeatures, - abortSignal, ); } @@ -188,7 +178,6 @@ export class CheckoutService { validated.shoppingCartId, shoppingCart.items, validated.specialComment, - abortSignal, ); } @@ -209,26 +198,25 @@ export class CheckoutService { // Step 9: Set buyer on checkout this.#logger.debug('Setting buyer on checkout'); - await this.setBuyerOnCheckout(checkoutId, validated.buyer, abortSignal); + await this.setBuyerOnCheckout(checkoutId, validated.buyer); // Step 10: Set notification channels this.#logger.debug('Setting notification channels'); await this.setNotificationChannelsOnCheckout( checkoutId, validated.notificationChannels ?? 0, - abortSignal, ); // Step 11: Set payer (conditional) if (needsPayer && validated.payer) { this.#logger.debug('Setting payer on checkout'); - await this.setPayerOnCheckout(checkoutId, validated.payer, abortSignal); + await this.setPayerOnCheckout(checkoutId, validated.payer); } // Step 12: Set payment type based on order types const paymentType = this.determinePaymentType(orderOptions); this.#logger.debug('Setting payment type'); - await this.setPaymentTypeOnCheckout(checkoutId, paymentType, abortSignal); + await this.setPaymentTypeOnCheckout(checkoutId, paymentType); // Step 13: Update destination shipping addresses (if delivery or download) // Refresh checkout only when we need the destinations data @@ -240,17 +228,13 @@ export class CheckoutService { validated.shippingAddress ) { this.#logger.debug('Refreshing checkout to get destinations'); - const checkout = await this.refreshCheckout( - validated.shoppingCartId, - abortSignal, - ); + const checkout = await this.refreshCheckout(validated.shoppingCartId); this.#logger.debug('Updating destination shipping addresses'); await this.updateDestinationShippingAddresses( checkoutId, checkout, validated.shippingAddress, - abortSignal, ); } @@ -330,9 +314,8 @@ export class CheckoutService { private async updateDestinationsForCustomer( shoppingCartId: number, customerFeatures: Record, - abortSignal?: AbortSignal, ): Promise { - let req$ = + const req$ = this.#shoppingCartService.StoreCheckoutShoppingCartSetLogisticianOnDestinationsByBuyer( { shoppingCartId, @@ -340,10 +323,6 @@ export class CheckoutService { }, ); - if (abortSignal) { - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res.error) { @@ -360,14 +339,13 @@ export class CheckoutService { shoppingCartId: number, items: EntityContainer[], comment: string, - abortSignal?: AbortSignal, ): Promise { // Update all items in parallel await Promise.all( items.map(async (item) => { if (!item.id) return; - let req$ = + const req$ = this.#shoppingCartService.StoreCheckoutShoppingCartUpdateShoppingCartItem( { shoppingCartId, @@ -376,10 +354,6 @@ export class CheckoutService { }, ); - if (abortSignal) { - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res.error) { @@ -394,17 +368,11 @@ export class CheckoutService { /** * Refreshes checkout to get latest state. */ - private async refreshCheckout( - shoppingCartId: number, - abortSignal?: AbortSignal, - ): Promise { - let req$ = this.#storeCheckoutService.StoreCheckoutCreateOrRefreshCheckout({ - shoppingCartId, - }); - - if (abortSignal) { - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } + private async refreshCheckout(shoppingCartId: number): Promise { + const req$ = + this.#storeCheckoutService.StoreCheckoutCreateOrRefreshCheckout({ + shoppingCartId, + }); const res = await firstValueFrom(req$); @@ -472,7 +440,7 @@ export class CheckoutService { const availabilityDTO = AvailabilityAdapter.fromAvailabilityApi(availability); - let updateReq$ = + const updateReq$ = this.#shoppingCartService.StoreCheckoutShoppingCartUpdateShoppingCartItemAvailability( { shoppingCartId, @@ -481,10 +449,6 @@ export class CheckoutService { }, ); - if (abortSignal) { - updateReq$ = updateReq$.pipe(takeUntilAborted(abortSignal)); - } - const updateRes = await firstValueFrom(updateReq$); if (updateRes.error) { @@ -582,7 +546,7 @@ export class CheckoutService { }; } - let req$ = + const req$ = this.#shoppingCartService.StoreCheckoutShoppingCartUpdateShoppingCartItem( { shoppingCartId, @@ -591,10 +555,6 @@ export class CheckoutService { }, ); - if (abortSignal) { - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res.error) { @@ -618,17 +578,12 @@ export class CheckoutService { private async setBuyerOnCheckout( checkoutId: number, buyerDTO: Buyer, - abortSignal?: AbortSignal, ): Promise { - let req$ = this.#buyerService.StoreCheckoutBuyerSetBuyerPOST({ + const req$ = this.#buyerService.StoreCheckoutBuyerSetBuyerPOST({ checkoutId, buyerDTO, }); - if (abortSignal) { - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res.error) { @@ -646,17 +601,12 @@ export class CheckoutService { private async setPayerOnCheckout( checkoutId: number, payer: Payer, - abortSignal?: AbortSignal, ): Promise { - let req$ = this.#payerService.StoreCheckoutPayerSetPayerPOST({ + const req$ = this.#payerService.StoreCheckoutPayerSetPayerPOST({ checkoutId, payerDTO: payer, }); - if (abortSignal) { - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res.error) { @@ -674,16 +624,12 @@ export class CheckoutService { private async setNotificationChannelsOnCheckout( checkoutId: number, channels: NotificationChannel, - abortSignal?: AbortSignal, ): Promise { - let req$ = this.#storeCheckoutService.StoreCheckoutSetNotificationChannels({ - checkoutId, - notificationChannel: channels, - }); - - if (abortSignal) { - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } + const req$ = + this.#storeCheckoutService.StoreCheckoutSetNotificationChannels({ + checkoutId, + notificationChannel: channels, + }); const res = await firstValueFrom(req$); @@ -702,17 +648,12 @@ export class CheckoutService { private async setPaymentTypeOnCheckout( checkoutId: number, paymentType: PaymentType, - abortSignal?: AbortSignal, ): Promise { - let req$ = this.#paymentService.StoreCheckoutPaymentSetPaymentType({ + const req$ = this.#paymentService.StoreCheckoutPaymentSetPaymentType({ checkoutId, paymentType: paymentType, }); - if (abortSignal) { - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res.error) { @@ -731,7 +672,6 @@ export class CheckoutService { checkoutId: number, checkout: Checkout, shippingAddress: ShippingAddress, - abortSignal?: AbortSignal, ): Promise { // Get shipping destinations (target 2 or 16) const destinations = filterDeliveryDestinations( @@ -751,16 +691,12 @@ export class CheckoutService { shippingAddress: { ...shippingAddress }, }; - let req$ = this.#storeCheckoutService.StoreCheckoutUpdateDestination({ + const req$ = this.#storeCheckoutService.StoreCheckoutUpdateDestination({ checkoutId, destinationId: dest.id, destinationDTO: updatedDestination, }); - if (abortSignal) { - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res.error) { diff --git a/libs/remission/data-access/src/lib/services/remission-return-receipt.service.ts b/libs/remission/data-access/src/lib/services/remission-return-receipt.service.ts index 9785e0997..9b91360b6 100644 --- a/libs/remission/data-access/src/lib/services/remission-return-receipt.service.ts +++ b/libs/remission/data-access/src/lib/services/remission-return-receipt.service.ts @@ -279,18 +279,13 @@ export class RemissionReturnReceiptService { returnGroup, })); - let req$ = this.#returnService.ReturnCreateReturn({ + const req$ = this.#returnService.ReturnCreateReturn({ data: { supplier: { id: firstSupplier.id }, returnGroup, }, }); - if (abortSignal) { - this.#logger.debug('Request configured with abort signal'); - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res?.error) { @@ -345,7 +340,7 @@ export class RemissionReturnReceiptService { receiptNumber, })); - let req$ = this.#returnService.ReturnCreateReceipt({ + const req$ = this.#returnService.ReturnCreateReceipt({ returnId, data: { receiptNumber, @@ -359,11 +354,6 @@ export class RemissionReturnReceiptService { }, }); - if (abortSignal) { - this.#logger.debug('Request configured with abort signal'); - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res?.error) { @@ -402,7 +392,6 @@ export class RemissionReturnReceiptService { */ async assignPackage( params: AssignPackage, - abortSignal?: AbortSignal, ): Promise | undefined> { this.#logger.debug('Assign package to return receipt', () => ({ params })); @@ -414,7 +403,7 @@ export class RemissionReturnReceiptService { packageNumber, })); - let req$ = this.#returnService.ReturnCreateAndAssignPackage({ + const req$ = this.#returnService.ReturnCreateAndAssignPackage({ returnId, receiptId, data: { @@ -422,11 +411,6 @@ export class RemissionReturnReceiptService { }, }); - if (abortSignal) { - this.#logger.debug('Request configured with abort signal'); - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res?.error) { @@ -703,7 +687,6 @@ export class RemissionReturnReceiptService { */ async addReturnItem( params: AddReturnItem, - abortSignal?: AbortSignal, ): Promise { this.#logger.debug('Adding return item', () => ({ params })); @@ -718,7 +701,7 @@ export class RemissionReturnReceiptService { inStock, })); - let req$ = this.#returnService.ReturnAddReturnItem({ + const req$ = this.#returnService.ReturnAddReturnItem({ returnId, receiptId, data: { @@ -728,11 +711,6 @@ export class RemissionReturnReceiptService { }, }); - if (abortSignal) { - this.#logger.debug('Request configured with abort signal'); - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res?.error) { @@ -775,7 +753,6 @@ export class RemissionReturnReceiptService { */ async addReturnSuggestionItem( params: AddReturnSuggestionItem, - abortSignal?: AbortSignal, ): Promise { this.#logger.debug('Adding return suggestion item', () => ({ params })); @@ -799,7 +776,7 @@ export class RemissionReturnReceiptService { remainingQuantity, })); - let req$ = this.#returnService.ReturnAddReturnSuggestion({ + const req$ = this.#returnService.ReturnAddReturnSuggestion({ returnId, receiptId, data: { @@ -811,11 +788,6 @@ export class RemissionReturnReceiptService { }, }); - if (abortSignal) { - this.#logger.debug('Request configured with abort signal'); - req$ = req$.pipe(takeUntilAborted(abortSignal)); - } - const res = await firstValueFrom(req$); if (res?.error) { @@ -853,22 +825,23 @@ export class RemissionReturnReceiptService { * receiptId: 456, * }); */ - async createRemission({ - returnGroup, - receiptNumber, - }: { - returnGroup: string | undefined; - receiptNumber: string | undefined; - }): Promise { + async createRemission( + { + returnGroup, + receiptNumber, + }: { + returnGroup: string | undefined; + receiptNumber: string | undefined; + }, + abortSignal?: AbortSignal, + ): Promise { this.#logger.debug('Create remission', () => ({ returnGroup, receiptNumber, })); const createdReturn: ResponseArgs | undefined = - await this.createReturn({ - returnGroup, - }); + await this.createReturn({ returnGroup }, abortSignal); if (!createdReturn || !createdReturn.result) { this.#logger.error('Failed to create return for remission'); @@ -876,10 +849,13 @@ export class RemissionReturnReceiptService { } const createdReceipt: ResponseArgs | undefined = - await this.createReceipt({ - returnId: createdReturn.result.id, - receiptNumber, - }); + await this.createReceipt( + { + returnId: createdReturn.result.id, + receiptNumber, + }, + abortSignal, + ); if (!createdReceipt || !createdReceipt.result) { this.#logger.error('Failed to create return receipt');