|
|
|
@@ -1,25 +1,39 @@ |
|
|
|
import { Injectable } from '@angular/core'; |
|
|
|
import { MALLS } from '../mocks/malls'; |
|
|
|
import CartItem from '../models/cart-item'; |
|
|
|
import Mall, { IMall } from '../models/mall'; |
|
|
|
import { OfferService } from './offer.service'; |
|
|
|
import { OutletService } from './outlet.service'; |
|
|
|
|
|
|
|
@Injectable({ |
|
|
|
providedIn: 'root' |
|
|
|
}) |
|
|
|
export class MallService { |
|
|
|
malls: Array<IMall>; |
|
|
|
cart: Array<CartItem> = []; |
|
|
|
|
|
|
|
constructor() { |
|
|
|
this.malls = MALLS; |
|
|
|
constructor( |
|
|
|
private offerService: OfferService, |
|
|
|
private outletService: OutletService |
|
|
|
) { |
|
|
|
this.fetchMalls(); |
|
|
|
} |
|
|
|
|
|
|
|
public async getAllMalls() { |
|
|
|
return this.malls; |
|
|
|
private async getDenormalizedMall(mall: Mall) { |
|
|
|
const offers = await Promise.all(mall.offers.map(offer_id => this.offerService.getOfferByID(offer_id))); |
|
|
|
const outlets = await Promise.all(mall.outlets.map(outlet_id => this.outletService.getOutletByID(outlet_id))); |
|
|
|
|
|
|
|
return { |
|
|
|
...mall, |
|
|
|
offers, |
|
|
|
outlets, |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
public async getCartItems() { |
|
|
|
return this.cart; |
|
|
|
private async fetchMalls() { |
|
|
|
this.malls = await Promise.all(MALLS.map(this.getDenormalizedMall)); |
|
|
|
} |
|
|
|
|
|
|
|
public async getAllMalls() { |
|
|
|
return this.malls; |
|
|
|
} |
|
|
|
|
|
|
|
public async getMallByID(id: string) { |
|
|
|
|