mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
AvailabilityService.mapToOlaAvailability()
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ItemDTO, StockInfoDTO } from '@swagger/cat';
|
||||
import { AvailabilityDTO, BranchDTO, StoreCheckoutService, SupplierDTO } from '@swagger/checkout';
|
||||
import { AvailabilityDTO, BranchDTO, OLAAvailabilityDTO, StoreCheckoutService, SupplierDTO } from '@swagger/checkout';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { AvailabilityService as SwaggerAvailabilityService } from '@swagger/availability';
|
||||
import { StockService } from '@swagger/cat';
|
||||
import { map, mergeMap, withLatestFrom } from 'rxjs/operators';
|
||||
import { isNullOrUndefined } from '@utils/common';
|
||||
import { map, mergeMap, shareReplay, withLatestFrom } from 'rxjs/operators';
|
||||
import { isNullOrUndefined, memorize } from '@utils/common';
|
||||
import { OrderService } from '@swagger/oms';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@@ -17,12 +17,15 @@ export class AvailabilityService {
|
||||
private orderService: OrderService
|
||||
) {}
|
||||
|
||||
@memorize()
|
||||
getTakeAwaySupplier(): Observable<SupplierDTO> {
|
||||
return this.storeCheckoutService
|
||||
.StoreCheckoutGetSuppliers({})
|
||||
.pipe(map(({ result }) => result.find((supplier) => supplier?.supplierNumber === 'F')));
|
||||
return this.storeCheckoutService.StoreCheckoutGetSuppliers({}).pipe(
|
||||
map(({ result }) => result.find((supplier) => supplier?.supplierNumber === 'F')),
|
||||
shareReplay()
|
||||
);
|
||||
}
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getTakeAwayAvailability({ item, branch, quantity }: { item: ItemDTO; quantity: number; branch: BranchDTO }): Observable<AvailabilityDTO> {
|
||||
const takeAwaySupplier$ = this.getTakeAwaySupplier();
|
||||
|
||||
@@ -57,10 +60,12 @@ export class AvailabilityService {
|
||||
};
|
||||
|
||||
return availability;
|
||||
})
|
||||
}),
|
||||
shareReplay()
|
||||
);
|
||||
}
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getPickUpAvailability({ item, branch, quantity }: { item: ItemDTO; quantity: number; branch: BranchDTO }): Observable<AvailabilityDTO> {
|
||||
return this.swaggerAvailabilityService
|
||||
.AvailabilityStoreAvailability([
|
||||
@@ -87,10 +92,12 @@ export class AvailabilityService {
|
||||
price: preferred?.price,
|
||||
};
|
||||
return availability;
|
||||
})
|
||||
}),
|
||||
shareReplay()
|
||||
);
|
||||
}
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getDeliveryAvailability({ item, quantity }: { item: ItemDTO; quantity: number }): Observable<AvailabilityDTO> {
|
||||
return this.swaggerAvailabilityService
|
||||
.AvailabilityShippingAvailability([
|
||||
@@ -116,10 +123,12 @@ export class AvailabilityService {
|
||||
price: preferred?.price,
|
||||
};
|
||||
return availability;
|
||||
})
|
||||
}),
|
||||
shareReplay()
|
||||
);
|
||||
}
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getDigDeliveryAvailability({ item, quantity }: { item: ItemDTO; quantity: number }): Observable<AvailabilityDTO> {
|
||||
return this.swaggerAvailabilityService
|
||||
.AvailabilityShippingAvailability([
|
||||
@@ -146,10 +155,12 @@ export class AvailabilityService {
|
||||
logistician: { id: preferred?.logisticianId },
|
||||
};
|
||||
return availability;
|
||||
})
|
||||
}),
|
||||
shareReplay()
|
||||
);
|
||||
}
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getB2bDeliveryAvailability({
|
||||
item,
|
||||
quantity,
|
||||
@@ -168,10 +179,12 @@ export class AvailabilityService {
|
||||
map(([availability, logistician]) => ({
|
||||
...availability,
|
||||
logistician: { id: logistician.id },
|
||||
}))
|
||||
})),
|
||||
shareReplay()
|
||||
);
|
||||
}
|
||||
|
||||
@memorize({ ttl: 10000 })
|
||||
getDownloadAvailability({ item }: { item: ItemDTO }): Observable<AvailabilityDTO> {
|
||||
return this.swaggerAvailabilityService
|
||||
.AvailabilityShippingAvailability([
|
||||
@@ -197,7 +210,37 @@ export class AvailabilityService {
|
||||
price: preferred?.price,
|
||||
};
|
||||
return availability;
|
||||
})
|
||||
}),
|
||||
shareReplay()
|
||||
);
|
||||
}
|
||||
|
||||
isAvailable({ availability }: { availability: AvailabilityDTO }) {
|
||||
return [2, 32, 256, 1024, 2048, 4096, 8192].some((code) => availability?.availabilityType === code);
|
||||
}
|
||||
|
||||
mapToOlaAvailability({
|
||||
availability,
|
||||
item,
|
||||
quantity,
|
||||
}: {
|
||||
availability: AvailabilityDTO;
|
||||
item: ItemDTO;
|
||||
quantity: number;
|
||||
}): OLAAvailabilityDTO {
|
||||
return {
|
||||
status: availability?.availabilityType,
|
||||
at: availability?.estimatedShippingDate,
|
||||
ean: item?.product?.ean,
|
||||
itemId: item?.id,
|
||||
format: item?.product?.format,
|
||||
isPrebooked: availability?.isPrebooked,
|
||||
logisticianId: availability?.logistician?.id,
|
||||
price: availability?.price,
|
||||
qty: quantity,
|
||||
ssc: availability?.ssc,
|
||||
sscText: availability?.sscText,
|
||||
supplierId: availability?.supplier?.id,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user