Skip to content

Commit

Permalink
fixup! fixup! feat: switch customer REST resource depending on applic…
Browse files Browse the repository at this point in the history
…ation and customer type (#302)
  • Loading branch information
dhhyi committed Jul 27, 2020
1 parent 8304e8f commit 68f2617
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/app/core/services/address/address.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { concatMap, map, mapTo } from 'rxjs/operators';
import { concatMap, first, map, mapTo } from 'rxjs/operators';

import { AppFacade } from 'ish-core/facades/app.facade';
import { AddressMapper } from 'ish-core/models/address/address.mapper';
Expand All @@ -22,6 +22,7 @@ export class AddressService {
*/
getCustomerAddresses(customerId: string = '-'): Observable<Address[]> {
return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService.get(`${restResource}/${customerId}/addresses`).pipe(
unpackEnvelope<Link>(),
Expand All @@ -45,6 +46,7 @@ export class AddressService {
};

return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService
.post(`${restResource}/${customerId}/addresses`, customerAddress)
Expand All @@ -65,6 +67,7 @@ export class AddressService {
};

return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService
.put(`${restResource}/${customerId}/addresses/${address.id}`, customerAddress)
Expand All @@ -81,6 +84,7 @@ export class AddressService {
*/
deleteCustomerAddress(customerId: string = '-', addressId: string): Observable<string> {
return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService.delete(`${restResource}/${customerId}/addresses/${addressId}`).pipe(mapTo(addressId))
)
Expand Down
5 changes: 4 additions & 1 deletion src/app/core/services/payment/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { Observable, of, throwError } from 'rxjs';
import { concatMap, map, mapTo, withLatestFrom } from 'rxjs/operators';
import { concatMap, first, map, mapTo, withLatestFrom } from 'rxjs/operators';

import { AppFacade } from 'ish-core/facades/app.facade';
import { Basket } from 'ish-core/models/basket/basket.model';
Expand Down Expand Up @@ -250,6 +250,7 @@ export class PaymentService {
}

return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService.get(`${restResource}/${customer.customerNo}/payments`).pipe(
unpackEnvelope<Link>(),
Expand Down Expand Up @@ -295,6 +296,7 @@ export class PaymentService {
};

return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService
.post(`${restResource}/${customerNo}/payments`, body)
Expand All @@ -317,6 +319,7 @@ export class PaymentService {
}

return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService.delete<void>(`${restResource}/${customerNo}/payments/${paymentInstrumentId}`)
)
Expand Down
5 changes: 4 additions & 1 deletion src/app/core/services/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import b64u from 'b64u';
import { pick } from 'lodash-es';
import { EMPTY, Observable, of, throwError } from 'rxjs';
import { catchError, concatMap, map, withLatestFrom } from 'rxjs/operators';
import { catchError, concatMap, first, map, withLatestFrom } from 'rxjs/operators';

import { AppFacade } from 'ish-core/facades/app.facade';
import { Address } from 'ish-core/models/address/address.model';
Expand Down Expand Up @@ -119,6 +119,7 @@ export class UserService {
}

return this.appFacade.isAppTypeREST$.pipe(
first(),
concatMap(isAppTypeRest =>
this.apiService.post<void>(
AppFacade.getCustomerRestResource(body.customer.isBusinessCustomer, isAppTypeRest),
Expand Down Expand Up @@ -153,6 +154,7 @@ export class UserService {
};

return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
body.customer.isBusinessCustomer
? this.apiService.put<User>('customers/-/users/-', changedUser).pipe(map(UserMapper.fromData))
Expand Down Expand Up @@ -183,6 +185,7 @@ export class UserService {
}

return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService.put<void>(
customer.isBusinessCustomer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { Observable, forkJoin, throwError } from 'rxjs';
import { concatMap, defaultIfEmpty, map, switchMap } from 'rxjs/operators';
import { concatMap, defaultIfEmpty, first, map, switchMap } from 'rxjs/operators';

import { AppFacade } from 'ish-core/facades/app.facade';
import { ApiService, unpackEnvelope } from 'ish-core/services/api/api.service';
Expand All @@ -19,6 +19,7 @@ export class WishlistService {
*/
getWishlists(): Observable<Wishlist[]> {
return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService.get(`${restResource}/-/wishlists`).pipe(
unpackEnvelope(),
Expand All @@ -42,6 +43,7 @@ export class WishlistService {
return throwError('getWishlist() called without wishlistId');
}
return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService
.get<WishlistData>(`${restResource}/-/wishlists/${wishlistId}`)
Expand All @@ -57,6 +59,7 @@ export class WishlistService {
*/
createWishlist(wishlistData: WishlistHeader): Observable<Wishlist> {
return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService
.post(`${restResource}/-/wishlists`, wishlistData)
Expand All @@ -75,6 +78,7 @@ export class WishlistService {
return throwError('deleteWishlist() called without wishlistId');
}
return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource => this.apiService.delete<void>(`${restResource}/-/wishlists/${wishlistId}`))
);
}
Expand All @@ -86,6 +90,7 @@ export class WishlistService {
*/
updateWishlist(wishlist: Wishlist): Observable<Wishlist> {
return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService
.put(`${restResource}/-/wishlists/${wishlist.id}`, wishlist)
Expand All @@ -109,6 +114,7 @@ export class WishlistService {
return throwError('addProductToWishlist() called without sku');
}
return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService
.post(`${restResource}/-/wishlists/${wishlistId}/products/${sku}`, { quantity })
Expand All @@ -131,6 +137,7 @@ export class WishlistService {
return throwError('removeProductFromWishlist() called without sku');
}
return this.appFacade.customerRestResource$.pipe(
first(),
concatMap(restResource =>
this.apiService
.delete(`${restResource}/-/wishlists/${wishlistId}/products/${sku}`)
Expand Down

1 comment on commit 68f2617

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Azure Demo Servers are available:

Please sign in to comment.