@infrab4a/connect-angular 3.9.7 → 3.10.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/angular-connect.module.d.ts +19 -19
  2. package/angular-elastic-search.module.d.ts +9 -9
  3. package/angular-firebase-auth.module.d.ts +10 -10
  4. package/angular-firestore.module.d.ts +15 -15
  5. package/angular-hasura-graphql.module.d.ts +16 -16
  6. package/bundles/infrab4a-connect-angular.umd.js +2134 -2214
  7. package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
  8. package/consts/backend-url.const.d.ts +1 -1
  9. package/consts/default-shop.const.d.ts +1 -1
  10. package/consts/es-config.const.d.ts +1 -1
  11. package/consts/hasura-options.const.d.ts +1 -1
  12. package/consts/index.d.ts +4 -4
  13. package/esm2015/angular-connect.module.js +52 -52
  14. package/esm2015/angular-elastic-search.module.js +34 -34
  15. package/esm2015/angular-firebase-auth.module.js +113 -113
  16. package/esm2015/angular-firestore.module.js +394 -394
  17. package/esm2015/angular-hasura-graphql.module.js +156 -156
  18. package/esm2015/consts/backend-url.const.js +1 -1
  19. package/esm2015/consts/default-shop.const.js +2 -2
  20. package/esm2015/consts/es-config.const.js +2 -2
  21. package/esm2015/consts/hasura-options.const.js +2 -2
  22. package/esm2015/consts/index.js +5 -5
  23. package/esm2015/index.js +6 -6
  24. package/esm2015/infrab4a-connect-angular.js +4 -4
  25. package/esm2015/services/auth.service.js +42 -42
  26. package/esm2015/services/cart.service.js +268 -281
  27. package/esm2015/services/checkout-subscription.service.js +53 -53
  28. package/esm2015/services/checkout.service.js +70 -75
  29. package/esm2015/services/coupon.service.js +226 -246
  30. package/esm2015/services/home-shop.service.js +116 -116
  31. package/esm2015/services/index.js +9 -9
  32. package/esm2015/services/order.service.js +32 -32
  33. package/esm2015/services/shipping.service.js +98 -98
  34. package/esm2015/services/types/index.js +3 -3
  35. package/esm2015/services/types/required-checkout-data.type.js +2 -2
  36. package/esm2015/services/types/required-checkout-subscription-data.type.js +2 -2
  37. package/esm2015/services/types/shipping-methods.type.js +2 -2
  38. package/fesm2015/infrab4a-connect-angular.js +1532 -1584
  39. package/fesm2015/infrab4a-connect-angular.js.map +1 -1
  40. package/index.d.ts +5 -5
  41. package/infrab4a-connect-angular.d.ts +5 -5
  42. package/package.json +2 -2
  43. package/services/auth.service.d.ts +19 -19
  44. package/services/cart.service.d.ts +41 -42
  45. package/services/checkout-subscription.service.d.ts +18 -18
  46. package/services/checkout.service.d.ts +23 -23
  47. package/services/coupon.service.d.ts +27 -25
  48. package/services/home-shop.service.d.ts +25 -25
  49. package/services/index.d.ts +8 -8
  50. package/services/order.service.d.ts +13 -13
  51. package/services/shipping.service.d.ts +19 -19
  52. package/services/types/index.d.ts +2 -2
  53. package/services/types/required-checkout-data.type.d.ts +2 -2
  54. package/services/types/required-checkout-subscription-data.type.d.ts +2 -2
  55. package/services/types/shipping-methods.type.d.ts +12 -12
  56. package/esm2015/services/errors/group-invalid-coupon.error.js +0 -8
  57. package/esm2015/services/errors/index.js +0 -3
  58. package/esm2015/services/errors/invalid-coupon.error.js +0 -8
  59. package/services/errors/group-invalid-coupon.error.d.ts +0 -6
  60. package/services/errors/index.d.ts +0 -2
  61. package/services/errors/invalid-coupon.error.d.ts +0 -5
@@ -6,48 +6,47 @@ import { of, combineLatest, from, throwError, Subject, iif, forkJoin } from 'rxj
6
6
  import { catchError, map, mergeMap, concatMap, tap } from 'rxjs/operators';
7
7
  import { __awaiter } from 'tslib';
8
8
  import * as i3 from '@infrab4a/connect';
9
- import { Coupon, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository } from '@infrab4a/connect';
9
+ import { Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository } from '@infrab4a/connect';
10
10
  import cookie from 'js-cookie';
11
- import { CustomError } from 'ts-custom-error';
12
11
  import * as i1$1 from '@angular/fire/firestore';
13
12
  import { AngularFirestore } from '@angular/fire/firestore';
14
13
  import * as i1$2 from '@angular/common/http';
15
14
  import { FIREBASE_OPTIONS, FIREBASE_APP_NAME, AngularFireModule } from '@angular/fire';
16
15
 
17
- class AuthService {
18
- constructor(angularFireAuth, userRepository) {
19
- this.angularFireAuth = angularFireAuth;
20
- this.userRepository = userRepository;
21
- }
22
- getAuthstate() {
23
- const observables = [
24
- this.angularFireAuth.authState.pipe(catchError(() => of(null))),
25
- this.getUser().pipe(catchError(() => of(null))),
26
- ];
27
- return combineLatest(observables).pipe(map(([fireUser, user]) => {
28
- return {
29
- user,
30
- isAnonymous: fireUser === null || fireUser === void 0 ? void 0 : fireUser.isAnonymous,
31
- };
32
- }));
33
- }
34
- getUser() {
35
- return this.getFireUser().pipe(map((user) => user === null || user === void 0 ? void 0 : user.uid), mergeMap((id) => (id ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
36
- }
37
- getTokenId() {
38
- return this.angularFireAuth.idToken;
39
- }
40
- getFireUser() {
41
- return this.angularFireAuth.user.pipe(catchError(() => of(null)));
42
- }
43
- }
44
- AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, deps: [{ token: i1.AngularFireAuth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
45
- AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService });
46
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, decorators: [{
47
- type: Injectable
48
- }], ctorParameters: function () { return [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
49
- type: Inject,
50
- args: ['UserRepository']
16
+ class AuthService {
17
+ constructor(angularFireAuth, userRepository) {
18
+ this.angularFireAuth = angularFireAuth;
19
+ this.userRepository = userRepository;
20
+ }
21
+ getAuthstate() {
22
+ const observables = [
23
+ this.angularFireAuth.authState.pipe(catchError(() => of(null))),
24
+ this.getUser().pipe(catchError(() => of(null))),
25
+ ];
26
+ return combineLatest(observables).pipe(map(([fireUser, user]) => {
27
+ return {
28
+ user,
29
+ isAnonymous: fireUser === null || fireUser === void 0 ? void 0 : fireUser.isAnonymous,
30
+ };
31
+ }));
32
+ }
33
+ getUser() {
34
+ return this.getFireUser().pipe(map((user) => user === null || user === void 0 ? void 0 : user.uid), mergeMap((id) => (id ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
35
+ }
36
+ getTokenId() {
37
+ return this.angularFireAuth.idToken;
38
+ }
39
+ getFireUser() {
40
+ return this.angularFireAuth.user.pipe(catchError(() => of(null)));
41
+ }
42
+ }
43
+ AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, deps: [{ token: i1.AngularFireAuth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
44
+ AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService });
45
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, decorators: [{
46
+ type: Injectable
47
+ }], ctorParameters: function () { return [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
48
+ type: Inject,
49
+ args: ['UserRepository']
51
50
  }] }]; } });
52
51
 
53
52
  const BACKEND_URL = 'BACKEND_URL';
@@ -58,1578 +57,1527 @@ const ES_CONFIG = 'ES_CONFIG';
58
57
 
59
58
  const HASURA_OPTIONS = 'HASURA_OPTIONS';
60
59
 
61
- class InvalidCouponError extends CustomError {
62
- constructor(message) {
63
- super(message);
64
- this.message = message;
65
- }
66
- }
67
-
68
- class GroupInvalidCouponError extends CustomError {
69
- constructor(errors) {
70
- super('Many coupon errors throw');
71
- this.errors = errors;
72
- }
73
- }
74
-
75
- class CouponService {
76
- constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
77
- this.couponRepository = couponRepository;
78
- this.defaultShop = defaultShop;
79
- this.orderRepository = orderRepository;
80
- this.categoryRepository = categoryRepository;
81
- this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
82
- this.separateValidCoupons = (coupons, userEmail) => coupons
83
- .map((coupon) => {
84
- try {
85
- if (!(coupon instanceof Coupon))
86
- throw new InvalidCouponError('Cupom inválido.');
87
- if (this.isValidCoupon(coupon, userEmail))
88
- return coupon;
89
- }
90
- catch (error) {
91
- return error;
92
- }
93
- })
94
- .reduce((current, coupon) => (Object.assign(Object.assign({}, current), (coupon instanceof Coupon
95
- ? { valids: [...current.valids, coupon] }
96
- : { invalids: [...current.invalids, coupon] }))), {
97
- valids: [],
98
- invalids: [],
99
- });
100
- }
101
- checkCoupon(nickname, userEmail, checkoutType, plan, checkout, isSubscription) {
102
- return from(this.couponRepository.find({
103
- filters: {
104
- nickname: { operator: Where.EQUALS, value: nickname },
105
- active: { operator: Where.EQUALS, value: true },
106
- },
107
- })).pipe(concatMap((coupons) => this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription)), concatMap((coupon) => this.checkCouponUseAndLimit(coupon, userEmail, checkout)), map((coupon) => this.isValidCoupon(coupon, userEmail)), map((coupon) => coupon));
108
- }
109
- checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription) {
110
- // Caso não ache nenhum cupom, retorna erro
111
- if (coupons.count < 1) {
112
- return throwError('Cupom inválido.');
113
- }
114
- // Get Primeiro Cupom (o find do repository retorna um array)
115
- const coupon = coupons.data.shift();
116
- // Verifica se o cupom é aplicavel na loja
117
- const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
118
- // Cupon não aplicavel a loja retorna erro
119
- if (!isInShop)
120
- return throwError('Cupom inválido para loja.');
121
- // Verifica se o coupon é aplicado no checkout que está sendo realizado
122
- const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
123
- // Cupon não aplicavel ao checkout retorna erro
124
- if (!isCheckoutType)
125
- return throwError('Cupom inválido. Erro de checkout.');
126
- // Verifica se o cupom é ou pode ser aplicado para subscription
127
- if (checkoutType === CheckoutTypes.ALL || checkoutType === CheckoutTypes.SUBSCRIPTION) {
128
- // Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
129
- if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
130
- return throwError('Cupom inválido para sua assinatura.');
131
- }
132
- if (isSubscription)
133
- return of(coupon);
134
- // Verifica se possui o valor minimo de compra para utilização do cupom
135
- const hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
136
- // Se não tem valor mínimo atingido, retorna erro
137
- if (!hasMinSubTotal)
138
- return throwError(`Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`);
139
- return of(coupon);
140
- }
141
- isValidCoupon(coupon, userEmail) {
142
- // Verifica a data de inicio de validade do cupom
143
- if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) > new Date())
144
- throw new InvalidCouponError('Cupom ainda não liberado.');
145
- // Verifica a data de validade do cupom
146
- if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
147
- throw new InvalidCouponError('Cupom expirado.');
148
- return coupon;
149
- }
150
- checkCouponUseAndLimit(coupon, userEmail, checkout) {
151
- return __awaiter(this, void 0, void 0, function* () {
152
- const orders = yield this.orderRepository.find({
153
- filters: Object.assign({ coupon: { id: coupon.id }, payment: { status: 'paid' } }, (coupon.influencerEmail ? { user: { email: userEmail } } : {})),
154
- });
155
- // orders que usuario ja fez com o cupom
156
- const ordersUserCoupon = orders.data.filter((o) => o.user.email == userEmail);
157
- // Verifica o limite de uso de cupom por usuario
158
- if (coupon.useLimitPerUser && ordersUserCoupon.length)
159
- throw new InvalidCouponError('Limite de uso por usuário atingido.');
160
- // Verifica o limite de uso geral por usuario
161
- if (coupon.useLimit && orders.data.length >= coupon.useLimit)
162
- throw new InvalidCouponError('Limite de uso atingido.');
163
- const validUser = this.userValidationAndSubscriptionStatus(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
164
- if (!validUser)
165
- throw new InvalidCouponError('Usuário não elegível.');
166
- const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
167
- if (!hasProductCategories)
168
- throw 'Seu carrinho não possui produtos elegíveis para desconto.';
169
- return coupon;
170
- });
171
- }
172
- calcDiscountSubscription(coupon, checkout) {
173
- //
174
- let discount = 0;
175
- if (coupon.type === CouponTypes.ABSOLUTE)
176
- discount = coupon.discount;
177
- else if (coupon.type === CouponTypes.PERCENTAGE)
178
- discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount / 100);
179
- return of(discount);
180
- }
181
- calcDiscountShopping(coupon, checkout) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- let discount = 0;
184
- switch (coupon.type) {
185
- case CouponTypes.ABSOLUTE: {
186
- discount = coupon.discount;
187
- break;
188
- }
189
- case CouponTypes.PERCENTAGE: {
190
- discount = yield this.calcShoppingPercentageDiscount(coupon, checkout);
191
- break;
192
- }
193
- }
194
- return discount;
195
- });
196
- }
197
- calcShoppingPercentageDiscount(coupon, checkout) {
198
- var _a;
199
- return __awaiter(this, void 0, void 0, function* () {
200
- let discount = 0;
201
- const shop = checkout.shop;
202
- let lineItensDiscount = [];
203
- const couponCategories = yield this.getCouponCategoriesId(coupon);
204
- if (coupon.productsCategories && coupon.productsCategories.length) {
205
- lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
206
- var _a;
207
- if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
208
- return i.categories.some((c) => couponCategories.some((cat) => cat.id == c || cat.firestoreId == c));
209
- }
210
- return true;
211
- });
212
- }
213
- else {
214
- lineItensDiscount = checkout.lineItems;
215
- }
216
- const subTotal = lineItensDiscount.reduce((acc, curr) => {
217
- var _a, _b, _c;
218
- return ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber) && ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice)
219
- ? acc + ((_c = curr.price[shop]) === null || _c === void 0 ? void 0 : _c.subscriberPrice) * curr.quantity
220
- : acc + curr.pricePaid * curr.quantity;
221
- }, 0) || 0;
222
- discount = subTotal * (coupon.discount / 100);
223
- return discount;
224
- });
225
- }
226
- hasMinSubTotal(coupon, checkout) {
227
- var _a;
228
- if (!coupon.minSubTotalValue)
229
- return true;
230
- const shop = checkout.shop;
231
- let subTotal = ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.reduce((acc, curr) => {
232
- var _a, _b, _c;
233
- return ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber) && ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice)
234
- ? acc + ((_c = curr.price[shop]) === null || _c === void 0 ? void 0 : _c.subscriberPrice) * curr.quantity
235
- : acc + curr.pricePaid * curr.quantity;
236
- }, 0)) || 0;
237
- if (coupon.minSubTotalValue <= subTotal)
238
- return true;
239
- return false;
240
- }
241
- hasProductCategories(coupon, checkout) {
242
- var _a;
243
- return __awaiter(this, void 0, void 0, function* () {
244
- if (!coupon.productsCategories || !coupon.productsCategories.length) {
245
- return true;
246
- }
247
- const couponCategories = yield this.getCouponCategoriesId(coupon);
248
- const hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
249
- var _a;
250
- if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
251
- return true;
252
- return i.categories.some((c) => couponCategories.some((cat) => cat.id == c || cat.firestoreId == c));
253
- });
254
- return hasCategories.length ? true : false;
255
- });
256
- }
257
- userValidationAndSubscriptionStatus(coupon, user) {
258
- if (coupon.exclusivityType === Exclusivities.ALL_USERS)
259
- return true;
260
- if (!user)
261
- return true;
262
- // Verifica se o email do usuário é coorporativo
263
- if (!this.emailIsFromCollaborator(user.email) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
264
- throw new InvalidCouponError('Você não é colaborador.');
265
- // Verifica se o email do usuário é associado ao cupom de uso por usuario
266
- if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== user.email)
267
- throw new InvalidCouponError('Cupom não é válido para este usuário.');
268
- switch (coupon.exclusivityType) {
269
- case Exclusivities.ACTIVE_SUBSCRIBER:
270
- return user.isSubscriber ? true : false;
271
- case Exclusivities.INACTIVE_SUBSCRIBER:
272
- return user.isSubscriber ? false : true;
273
- case Exclusivities.NON_SUBSCRIBER:
274
- return user.isSubscriber ? false : true;
275
- }
276
- return true;
277
- }
278
- getCouponCategoriesId(coupon) {
279
- return __awaiter(this, void 0, void 0, function* () {
280
- let couponCategories = [];
281
- for (let index = 0; index < coupon.productsCategories.length; index++) {
282
- let c = yield this.categoryRepository.get({
283
- id: coupon.productsCategories[index],
284
- });
285
- couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
286
- }
287
- return couponCategories;
288
- });
289
- }
290
- }
291
- CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
292
- CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
293
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, decorators: [{
294
- type: Injectable,
295
- args: [{
296
- providedIn: 'root',
297
- }]
298
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
299
- type: Inject,
300
- args: ['CouponRepository']
301
- }] }, { type: i3.Shops, decorators: [{
302
- type: Inject,
303
- args: [DEFAULT_SHOP]
304
- }] }, { type: undefined, decorators: [{
305
- type: Inject,
306
- args: ['OrderRepository']
307
- }] }, { type: undefined, decorators: [{
308
- type: Inject,
309
- args: ['CategoryRepository']
60
+ class CouponService {
61
+ constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
62
+ this.couponRepository = couponRepository;
63
+ this.defaultShop = defaultShop;
64
+ this.orderRepository = orderRepository;
65
+ this.categoryRepository = categoryRepository;
66
+ this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
67
+ }
68
+ checkCoupon(nickname, checkoutType, checkout, plan) {
69
+ return from(this.couponRepository
70
+ .find({
71
+ filters: {
72
+ nickname: { operator: Where.EQUALS, value: nickname },
73
+ active: { operator: Where.EQUALS, value: true },
74
+ },
75
+ })
76
+ .then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
77
+ }
78
+ couponValidation(coupon, checkoutType) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ if (!coupon)
81
+ throw 'Cupom inválido.';
82
+ if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) > new Date())
83
+ throw 'Cupom inválido.';
84
+ if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
85
+ throw 'Cupom expirado.';
86
+ const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
87
+ if (!isInShop)
88
+ throw 'Cupom inválido para loja.';
89
+ const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
90
+ if (!isCheckoutType)
91
+ throw 'Cupom inválido. Erro de checkout.';
92
+ return coupon;
93
+ });
94
+ }
95
+ couponRulesValidation(coupon, checkoutType, checkout, plan) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
98
+ if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
99
+ throw 'Cupom inválido para sua assinatura.';
100
+ return coupon;
101
+ }
102
+ const orders = yield this.getOrdersWithCoupon(coupon);
103
+ const ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
104
+ if (coupon.useLimitPerUser && ordersWithUser > 0)
105
+ throw 'Limite de uso por usuário atingido.';
106
+ if (!coupon.unlimited && coupon.useLimit && orders.length >= coupon.useLimit)
107
+ throw 'Limite de uso atingido.';
108
+ const validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
109
+ if (!validUser)
110
+ throw 'Usuário não elegível.';
111
+ const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
112
+ if (!hasProductCategories)
113
+ throw 'Seu carrinho não possui produtos elegíveis para desconto.';
114
+ const hasMinSubTotal = yield this.hasMinSubTotal(coupon, checkout);
115
+ if (!hasMinSubTotal)
116
+ throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido`;
117
+ return coupon;
118
+ });
119
+ }
120
+ calcDiscountSubscription(coupon, checkout) {
121
+ let discount = 0;
122
+ if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
123
+ discount = coupon.discount.subscription.value;
124
+ else
125
+ discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
126
+ return of(discount);
127
+ }
128
+ calcDiscountShopping(coupon, checkout) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ let discount = 0;
131
+ if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
132
+ discount = yield this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
133
+ }
134
+ else {
135
+ discount = yield this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
136
+ }
137
+ return discount;
138
+ });
139
+ }
140
+ calcDiscountByType(type, value, categories, checkout) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ let discount = 0;
143
+ let lineItensDiscount = yield this.getLineItensEligebleForDiscount(categories, checkout);
144
+ const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
145
+ if (type == CouponTypes.ABSOLUTE) {
146
+ discount = value > subTotal ? subTotal : value;
147
+ }
148
+ else {
149
+ discount = subTotal * (value / 100);
150
+ }
151
+ return discount;
152
+ });
153
+ }
154
+ hasMinSubTotal(coupon, checkout) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ if (!coupon.minSubTotalValue)
157
+ return true;
158
+ let lineItensDiscount = yield this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
159
+ const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
160
+ if (coupon.minSubTotalValue <= subTotal)
161
+ return true;
162
+ return false;
163
+ });
164
+ }
165
+ hasProductCategories(coupon, checkout) {
166
+ var _a;
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ if (!coupon.productsCategories || !coupon.productsCategories.length) {
169
+ return true;
170
+ }
171
+ const couponCategories = yield this.getCouponCategoriesId(coupon.productsCategories);
172
+ const hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
173
+ var _a;
174
+ if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
175
+ return true;
176
+ return i.categories.some((c) => couponCategories.some((cat) => cat.id == c || cat.firestoreId == c));
177
+ });
178
+ return hasCategories.length ? true : false;
179
+ });
180
+ }
181
+ coupomUserValidation(coupon, user) {
182
+ if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
183
+ return true;
184
+ let userTypes = [];
185
+ if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) && this.emailIsFromCollaborator(user.email))
186
+ userTypes.push(Exclusivities.COLLABORATORS);
187
+ if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) && coupon.userExclusiveEmail.includes(user.email))
188
+ userTypes.push(Exclusivities.SPECIFIC_USER);
189
+ if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
190
+ user.isSubscriber &&
191
+ user.subscriptionPlan != '')
192
+ userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
193
+ if (user.isSubscriber &&
194
+ user.subscriptionPlan == '' &&
195
+ coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
196
+ userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
197
+ if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
198
+ userTypes.push(Exclusivities.NON_SUBSCRIBER);
199
+ return coupon.exclusivityType.some((r) => userTypes.includes(r));
200
+ }
201
+ getCouponCategoriesId(productsCategories) {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ let couponCategories = [];
204
+ for (let index = 0; index < productsCategories.length; index++) {
205
+ let c = yield this.categoryRepository.get({
206
+ id: productsCategories[index],
207
+ });
208
+ couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
209
+ }
210
+ return couponCategories;
211
+ });
212
+ }
213
+ getLineItensEligebleForDiscount(productsCategories, checkout) {
214
+ var _a;
215
+ return __awaiter(this, void 0, void 0, function* () {
216
+ let lineItensDiscount = [];
217
+ const couponCategories = yield this.getCouponCategoriesId(productsCategories);
218
+ if (productsCategories && productsCategories.length) {
219
+ lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
220
+ var _a;
221
+ if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
222
+ return i.categories.some((c) => couponCategories.some((cat) => cat.id == c || cat.firestoreId == c));
223
+ }
224
+ return true;
225
+ });
226
+ }
227
+ else {
228
+ lineItensDiscount = checkout.lineItems;
229
+ }
230
+ return lineItensDiscount;
231
+ });
232
+ }
233
+ calcCheckoutSubtotal(lineItens, user, shop) {
234
+ return ((lineItens === null || lineItens === void 0 ? void 0 : lineItens.reduce((acc, curr) => {
235
+ var _a, _b;
236
+ return (user === null || user === void 0 ? void 0 : user.isSubscriber) && ((_a = curr.price[shop]) === null || _a === void 0 ? void 0 : _a.subscriberPrice)
237
+ ? acc + ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice) * curr.quantity
238
+ : acc + curr.pricePaid * curr.quantity;
239
+ }, 0)) || 0);
240
+ }
241
+ getOrdersWithCoupon(coupon) {
242
+ return __awaiter(this, void 0, void 0, function* () {
243
+ return yield this.orderRepository
244
+ .find({
245
+ filters: {
246
+ coupon: { id: coupon.id },
247
+ payment: { status: 'paid' },
248
+ },
249
+ })
250
+ .then((result) => result.data);
251
+ });
252
+ }
253
+ countOrdersWithUser(orders, email) {
254
+ return orders.filter((o) => o.user.email == email).length;
255
+ }
256
+ }
257
+ CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
258
+ CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
259
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, decorators: [{
260
+ type: Injectable,
261
+ args: [{
262
+ providedIn: 'root',
263
+ }]
264
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
265
+ type: Inject,
266
+ args: ['CouponRepository']
267
+ }] }, { type: i3.Shops, decorators: [{
268
+ type: Inject,
269
+ args: [DEFAULT_SHOP]
270
+ }] }, { type: undefined, decorators: [{
271
+ type: Inject,
272
+ args: ['OrderRepository']
273
+ }] }, { type: undefined, decorators: [{
274
+ type: Inject,
275
+ args: ['CategoryRepository']
310
276
  }] }]; } });
311
277
 
312
- class CheckoutService {
313
- constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
314
- this.couponService = couponService;
315
- this.checkoutRepository = checkoutRepository;
316
- this.orderRepository = orderRepository;
317
- this.userRepository = userRepository;
318
- this.defaultShop = defaultShop;
319
- }
320
- getCheckout(checkoutData) {
321
- const checkoutId = cookie.get('checkoutId');
322
- if (!isNil(checkoutId))
323
- return from(this.checkoutRepository.get({ id: checkoutId }));
324
- return from(this.createCheckout(checkoutData));
325
- }
326
- getUserByCheckout(checkoutId) {
327
- return from(this.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => { var _a; return ((_a = checkout === null || checkout === void 0 ? void 0 : checkout.user) === null || _a === void 0 ? void 0 : _a.id) ? of(checkout.user) : from(this.userRepository.get({ id: checkout.user.id })); }), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
328
- }
329
- updateCheckoutLineItems(checkout) {
330
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
331
- }
332
- updateCheckoutUser(checkout) {
333
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
334
- }
335
- clearCheckoutFromSession() {
336
- cookie.remove('checkoutId');
337
- return of();
338
- }
339
- calcDiscount(coupon) {
340
- return this.getCheckout().pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.couponService.calcDiscountShopping(coupon, checkout); })));
341
- }
342
- checkCoupon(nickname, checkoutType) {
343
- return this.getCheckout().pipe(concatMap((checkout) => {
344
- var _a;
345
- return this.couponService
346
- .checkCoupon(nickname, (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.email, CheckoutTypes.ECOMMERCE, checkout.user.subscriptionPlan, checkout, false)
347
- .pipe();
348
- }));
349
- }
350
- createCheckout(checkoutData) {
351
- return __awaiter(this, void 0, void 0, function* () {
352
- const checkout = yield this.checkoutRepository.create(Object.assign(Object.assign({ createdAt: new Date() }, Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()), { shop: (checkoutData === null || checkoutData === void 0 ? void 0 : checkoutData.shop) || this.defaultShop }));
353
- cookie.set('checkoutId', checkout.id);
354
- return checkout;
355
- });
356
- }
357
- }
358
- CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'OrderRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
359
- CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService });
360
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, decorators: [{
361
- type: Injectable
362
- }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
363
- type: Inject,
364
- args: ['CheckoutRepository']
365
- }] }, { type: undefined, decorators: [{
366
- type: Inject,
367
- args: ['OrderRepository']
368
- }] }, { type: undefined, decorators: [{
369
- type: Inject,
370
- args: ['UserRepository']
371
- }] }, { type: i3.Shops, decorators: [{
372
- type: Inject,
373
- args: [DEFAULT_SHOP]
278
+ class CheckoutService {
279
+ constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
280
+ this.couponService = couponService;
281
+ this.checkoutRepository = checkoutRepository;
282
+ this.orderRepository = orderRepository;
283
+ this.userRepository = userRepository;
284
+ this.defaultShop = defaultShop;
285
+ }
286
+ getCheckout(checkoutData) {
287
+ const checkoutId = cookie.get('checkoutId');
288
+ if (!isNil(checkoutId))
289
+ return from(this.checkoutRepository.get({ id: checkoutId }));
290
+ return from(this.createCheckout(checkoutData));
291
+ }
292
+ getUserByCheckout(checkoutId) {
293
+ return from(this.checkoutRepository.get({ id: checkoutId })).pipe(concatMap((checkout) => { var _a; return ((_a = checkout === null || checkout === void 0 ? void 0 : checkout.user) === null || _a === void 0 ? void 0 : _a.id) ? of(checkout.user) : from(this.userRepository.get({ id: checkout.user.id })); }), concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))));
294
+ }
295
+ updateCheckoutLineItems(checkout) {
296
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
297
+ }
298
+ updateCheckoutUser(checkout) {
299
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
300
+ }
301
+ clearCheckoutFromSession() {
302
+ cookie.remove('checkoutId');
303
+ return of();
304
+ }
305
+ calcDiscount(coupon) {
306
+ return this.getCheckout().pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.couponService.calcDiscountShopping(coupon, checkout); })));
307
+ }
308
+ checkCoupon(nickname, checkoutType) {
309
+ return this.getCheckout().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, CheckoutTypes.ECOMMERCE, checkout, null).pipe()));
310
+ }
311
+ createCheckout(checkoutData) {
312
+ return __awaiter(this, void 0, void 0, function* () {
313
+ const checkout = yield this.checkoutRepository.create(Object.assign(Object.assign({ createdAt: new Date() }, Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()), { shop: (checkoutData === null || checkoutData === void 0 ? void 0 : checkoutData.shop) || this.defaultShop }));
314
+ cookie.set('checkoutId', checkout.id);
315
+ return checkout;
316
+ });
317
+ }
318
+ }
319
+ CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, deps: [{ token: CouponService }, { token: 'CheckoutRepository' }, { token: 'OrderRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
320
+ CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService });
321
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, decorators: [{
322
+ type: Injectable
323
+ }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
324
+ type: Inject,
325
+ args: ['CheckoutRepository']
326
+ }] }, { type: undefined, decorators: [{
327
+ type: Inject,
328
+ args: ['OrderRepository']
329
+ }] }, { type: undefined, decorators: [{
330
+ type: Inject,
331
+ args: ['UserRepository']
332
+ }] }, { type: i3.Shops, decorators: [{
333
+ type: Inject,
334
+ args: [DEFAULT_SHOP]
374
335
  }] }]; } });
375
336
 
376
- class CartService {
377
- constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
378
- this.authService = authService;
379
- this.checkoutService = checkoutService;
380
- this.defaultShop = defaultShop;
381
- this.productRepository = productRepository;
382
- this.categoryRepository = categoryRepository;
383
- this.variantRepository = variantRepository;
384
- this.buy2WinRepository = buy2WinRepository;
385
- this.cartSubject = new Subject();
386
- this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
387
- var _a;
388
- const items = [];
389
- const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
390
- if (index > -1) {
391
- checkoutLoaded.lineItems[index].quantity += quantity;
392
- checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
393
- }
394
- else
395
- checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
396
- return this.checkoutService
397
- .updateCheckoutLineItems(checkoutLoaded)
398
- .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
399
- }));
400
- this.generateCartObject = (items) => items
401
- ? items.reduce((cart, item) => {
402
- var _a;
403
- return (Object.assign(Object.assign({}, cart), { [item.id]: LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.id] || item)), { quantity: (((_a = cart[item.id]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })) }));
404
- }, {})
405
- : [];
406
- this.buildLineItem = ({ checkout, item, quantity, }) => __awaiter(this, void 0, void 0, function* () {
407
- var _a, _b, _c, _d, _e, _f, _g;
408
- const product = yield this.getProductData(item.id);
409
- item.quantity = (item === null || item === void 0 ? void 0 : item.quantity) || ((_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id)) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
410
- if (this.checkMaxStock(item, quantity || 0))
411
- throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
412
- const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
413
- const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
414
- const isGift = item.isGift || null;
415
- const pricePaid = this.getProductPrice({
416
- product: item,
417
- shop: checkout.shop || this.defaultShop,
418
- isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
419
- });
420
- RoundProductPricesHelper.roundProductPrices(item);
421
- return {
422
- checkout,
423
- lineItem: LineItem.toInstance({
424
- id,
425
- name: name !== null && name !== void 0 ? name : product.name,
426
- EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
427
- brand: product.brand,
428
- slug: slug !== null && slug !== void 0 ? slug : product.slug,
429
- sku: sku !== null && sku !== void 0 ? sku : product.sku,
430
- stock,
431
- price: this.roundPrice(price),
432
- image,
433
- weight: weight !== null && weight !== void 0 ? weight : product.weight,
434
- quantity: (item.quantity || 0) + (quantity || 0),
435
- pricePaid,
436
- categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
437
- isGift: isGift !== null && isGift !== void 0 ? isGift : null,
438
- costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
439
- type,
440
- }),
441
- };
442
- });
443
- this.getProductPrice = ({ product, isSubscriber, }) => {
444
- const info = product.price;
445
- if (product.isGift)
446
- return 0;
447
- return isSubscriber && info.subscriberPrice > 0
448
- ? Number(info.subscriberPrice.toFixed(2))
449
- : Number(info.price.toFixed(2));
450
- };
451
- this.checkMaxStock = (item, quantity) => {
452
- var _a;
453
- const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
454
- const currentItemAmount = item.quantity || 0;
455
- return currentItemAmount + quantity > maxStock;
456
- };
457
- }
458
- addItem(item, quantity = 1) {
459
- return from(this.checkoutService.getCheckout()).pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.buildLineItem({ checkout, item, quantity: quantity || 1 }); })), mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
460
- }
461
- decreaseItem(item) {
462
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
463
- var _a;
464
- const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id);
465
- if (!isNil(checkoutItem))
466
- checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
467
- return checkout;
468
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
469
- }
470
- getCart(checkout) {
471
- this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
472
- return this.cartSubject;
473
- }
474
- /**
475
- * @deprecated The method should not be used
476
- */
477
- getVariantPriceDiscount(item) {
478
- return this.authService.getUser().pipe(concatMap((user) => iif(() => user.isSubscriber && !!item.price.subscriberPrice, of(item.price.subscriberPrice), of(item.price.price))), catchError(() => of(item.price.price)));
479
- }
480
- removeItem(item) {
481
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
482
- const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
483
- if (index >= 0)
484
- checkout.lineItems.splice(index, 1);
485
- return checkout;
486
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
487
- }
488
- updateUserCart(user) {
489
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => __awaiter(this, void 0, void 0, function* () {
490
- var _a, _b;
491
- return this.checkoutService
492
- .updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length)
493
- ? yield Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map((item) => __awaiter(this, void 0, void 0, function* () { return (yield this.buildLineItem({ checkout, item })).lineItem; })))
494
- : [] })))
495
- .toPromise();
496
- })), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
497
- }
498
- clearCart() {
499
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
500
- this.checkoutService.clearCheckoutFromSession();
501
- return checkout;
502
- }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
503
- }
504
- buildCartFromCheckout(checkoutData) {
505
- return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
506
- }
507
- roundPrice(productPrice) {
508
- const { price, fullPrice, subscriberPrice } = productPrice;
509
- return Object.assign(Object.assign(Object.assign({}, productPrice), { price: Number(price.toFixed(2)), fullPrice: Number(fullPrice.toFixed(2)) }), (subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }));
510
- }
511
- getProductData(productId) {
512
- return __awaiter(this, void 0, void 0, function* () {
513
- let product;
514
- let variant;
515
- try {
516
- product = yield this.productRepository.get({ id: productId });
517
- }
518
- catch (error) {
519
- if (!(error instanceof NotFoundError))
520
- throw error;
521
- const { data: variants } = yield this.variantRepository.find({ filters: { id: productId } });
522
- variant = variants.shift();
523
- if (!variant)
524
- throw error;
525
- product = yield this.productRepository.get({ id: variant.productId });
526
- }
527
- return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
528
- });
529
- }
530
- getGifts() {
531
- return this.checkoutService.getCheckout().pipe(mergeMap((checkout) => __awaiter(this, void 0, void 0, function* () {
532
- const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
533
- if (!notGiftItems.length)
534
- return Object.assign(Object.assign({}, checkout), { lineItems: [] });
535
- const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
536
- const campaigns = yield this.buy2WinRepository
537
- .find({
538
- filters: {
539
- active: { operator: Where.EQUALS, value: true },
540
- shop: { operator: Where.EQUALS, value: this.defaultShop },
541
- },
542
- })
543
- .then((data) => data.data);
544
- if (!campaigns.length)
545
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
546
- const elegibleCampaigns = [];
547
- for (const campaign of campaigns) {
548
- const today = new Date();
549
- if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
550
- continue;
551
- if (campaign.activeCategory) {
552
- const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
553
- const categoriesCampaingFullTree = [];
554
- for (const id of categoriesCampaing) {
555
- const children = yield this.categoryRepository.getChildren(parseInt(id));
556
- categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
557
- }
558
- const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
559
- const filterProductsCategories = checkout.lineItems.filter((l) => {
560
- var _a;
561
- if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
562
- return true;
563
- return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
564
- });
565
- if (filterProductsCategories.length) {
566
- const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
567
- if (cartTotalCategories >= campaign.cartValueMin)
568
- elegibleCampaigns.push(campaign);
569
- }
570
- }
571
- else {
572
- if (campaign.cartValue && campaign.cartValue > 0) {
573
- if (campaign.cartValue <= cartTotal)
574
- elegibleCampaigns.push(campaign);
575
- }
576
- }
577
- }
578
- if (!elegibleCampaigns.length)
579
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
580
- const campaingnProducts = [];
581
- for (const campaign of elegibleCampaigns) {
582
- let elegibleProducts = [];
583
- for (const product of campaign.products) {
584
- const { data: productData } = yield this.productRepository.find({ filters: { sku: product } });
585
- if (!productData.length)
586
- continue;
587
- const gift = productData.shift();
588
- if (gift.stock.quantity < 1)
589
- continue;
590
- elegibleProducts.push(gift);
591
- }
592
- campaingnProducts.push(elegibleProducts);
593
- }
594
- if (!campaingnProducts.length)
595
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
596
- const gifts = this.giftToLineItems([].concat(...campaingnProducts));
597
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
598
- })), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
599
- }
600
- giftToLineItems(items) {
601
- return items.map((item) => {
602
- var _a;
603
- const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
604
- const image = ((_a = item === null || item === void 0 ? void 0 : item.miniatures) === null || _a === void 0 ? void 0 : _a.length) ? item.miniatures[0] : item.images[0];
605
- return LineItem.toInstance({
606
- brand,
607
- categories,
608
- id: id.toString(),
609
- name,
610
- price,
611
- sku,
612
- slug,
613
- stock,
614
- weight,
615
- EAN,
616
- image,
617
- pricePaid: 0,
618
- quantity: 1,
619
- isGift: true,
620
- });
621
- });
622
- }
623
- }
624
- CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
625
- CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
626
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
627
- type: Injectable
628
- }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
629
- type: Inject,
630
- args: [DEFAULT_SHOP]
631
- }] }, { type: undefined, decorators: [{
632
- type: Inject,
633
- args: ['ProductRepository']
634
- }] }, { type: undefined, decorators: [{
635
- type: Inject,
636
- args: ['CategoryRepository']
637
- }] }, { type: undefined, decorators: [{
638
- type: Inject,
639
- args: ['VariantRepository']
640
- }] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
641
- type: Inject,
642
- args: ['Buy2WinRepository']
337
+ class CartService {
338
+ constructor(authService, checkoutService, defaultShop, productRepository, variantRepository, buy2WinRepository) {
339
+ this.authService = authService;
340
+ this.checkoutService = checkoutService;
341
+ this.defaultShop = defaultShop;
342
+ this.productRepository = productRepository;
343
+ this.variantRepository = variantRepository;
344
+ this.buy2WinRepository = buy2WinRepository;
345
+ this.cartSubject = new Subject();
346
+ this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
347
+ var _a;
348
+ const items = [];
349
+ const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
350
+ if (index > -1) {
351
+ checkoutLoaded.lineItems[index].quantity += quantity;
352
+ checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
353
+ }
354
+ else
355
+ checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
356
+ return this.checkoutService
357
+ .updateCheckoutLineItems(checkoutLoaded)
358
+ .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
359
+ }));
360
+ this.generateCartObject = (items) => items
361
+ ? items.reduce((cart, item) => {
362
+ var _a;
363
+ return (Object.assign(Object.assign({}, cart), { [item.id]: LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.id] || item)), { quantity: (((_a = cart[item.id]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })) }));
364
+ }, {})
365
+ : [];
366
+ this.buildLineItem = ({ checkout, item, quantity, }) => __awaiter(this, void 0, void 0, function* () {
367
+ var _a, _b, _c, _d, _e, _f, _g;
368
+ const product = yield this.getProductData(item.id);
369
+ item.quantity = (item === null || item === void 0 ? void 0 : item.quantity) || ((_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id)) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
370
+ if (this.checkMaxStock(item, quantity || 0))
371
+ throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
372
+ const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
373
+ const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
374
+ const isGift = item.isGift || null;
375
+ const pricePaid = this.getProductPrice({
376
+ product: item,
377
+ shop: checkout.shop || this.defaultShop,
378
+ isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
379
+ });
380
+ RoundProductPricesHelper.roundProductPrices(item);
381
+ return {
382
+ checkout,
383
+ lineItem: LineItem.toInstance({
384
+ id,
385
+ name: name !== null && name !== void 0 ? name : product.name,
386
+ EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
387
+ brand: product.brand,
388
+ slug: slug !== null && slug !== void 0 ? slug : product.slug,
389
+ sku: sku !== null && sku !== void 0 ? sku : product.sku,
390
+ stock,
391
+ price: this.roundPrice(price),
392
+ image,
393
+ weight: weight !== null && weight !== void 0 ? weight : product.weight,
394
+ quantity: (item.quantity || 0) + (quantity || 0),
395
+ pricePaid,
396
+ categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
397
+ isGift: isGift !== null && isGift !== void 0 ? isGift : null,
398
+ costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
399
+ type,
400
+ }),
401
+ };
402
+ });
403
+ this.getProductPrice = ({ product, isSubscriber, }) => {
404
+ const info = product.price;
405
+ if (product.isGift)
406
+ return 0;
407
+ return isSubscriber && info.subscriberPrice > 0
408
+ ? Number(info.subscriberPrice.toFixed(2))
409
+ : Number(info.price.toFixed(2));
410
+ };
411
+ this.checkMaxStock = (item, quantity) => {
412
+ var _a;
413
+ const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
414
+ const currentItemAmount = item.quantity || 0;
415
+ return currentItemAmount + quantity > maxStock;
416
+ };
417
+ }
418
+ addItem(item, quantity = 1) {
419
+ return from(this.checkoutService.getCheckout()).pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.buildLineItem({ checkout, item, quantity: quantity || 1 }); })), mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
420
+ }
421
+ decreaseItem(item) {
422
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
423
+ var _a;
424
+ const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id);
425
+ if (!isNil(checkoutItem))
426
+ checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
427
+ return checkout;
428
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
429
+ }
430
+ getCart(checkout) {
431
+ this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
432
+ return this.cartSubject;
433
+ }
434
+ /**
435
+ * @deprecated The method should not be used
436
+ */
437
+ getVariantPriceDiscount(item) {
438
+ return this.authService.getUser().pipe(concatMap((user) => iif(() => user.isSubscriber && !!item.price.subscriberPrice, of(item.price.subscriberPrice), of(item.price.price))), catchError(() => of(item.price.price)));
439
+ }
440
+ removeItem(item) {
441
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
442
+ const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
443
+ if (index >= 0)
444
+ checkout.lineItems.splice(index, 1);
445
+ return checkout;
446
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
447
+ }
448
+ updateUserCart(user) {
449
+ return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => __awaiter(this, void 0, void 0, function* () {
450
+ var _a, _b;
451
+ return this.checkoutService
452
+ .updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length)
453
+ ? yield Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map((item) => __awaiter(this, void 0, void 0, function* () { return (yield this.buildLineItem({ checkout, item })).lineItem; })))
454
+ : [] })))
455
+ .toPromise();
456
+ })), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
457
+ }
458
+ clearCart() {
459
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
460
+ this.checkoutService.clearCheckoutFromSession();
461
+ return checkout;
462
+ }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
463
+ }
464
+ buildCartFromCheckout(checkoutData) {
465
+ return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
466
+ }
467
+ roundPrice(productPrice) {
468
+ const { price, fullPrice, subscriberPrice } = productPrice;
469
+ return Object.assign(Object.assign(Object.assign({}, productPrice), { price: Number(price.toFixed(2)), fullPrice: Number(fullPrice.toFixed(2)) }), (subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }));
470
+ }
471
+ getProductData(productId) {
472
+ return __awaiter(this, void 0, void 0, function* () {
473
+ let product;
474
+ let variant;
475
+ try {
476
+ product = yield this.productRepository.get({ id: productId });
477
+ }
478
+ catch (error) {
479
+ if (!(error instanceof NotFoundError))
480
+ throw error;
481
+ variant = yield this.variantRepository.get({ id: productId });
482
+ product = yield this.productRepository.get({ id: variant.productId });
483
+ }
484
+ return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
485
+ });
486
+ }
487
+ getGifts() {
488
+ return this.checkoutService.getCheckout().pipe(mergeMap((checkout) => __awaiter(this, void 0, void 0, function* () {
489
+ const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
490
+ if (!notGiftItems.length)
491
+ return Object.assign(Object.assign({}, checkout), { lineItems: [] });
492
+ const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
493
+ const campaigns = yield this.buy2WinRepository
494
+ .find({
495
+ filters: {
496
+ active: { operator: Where.EQUALS, value: true },
497
+ shop: { operator: Where.EQUALS, value: this.defaultShop },
498
+ },
499
+ })
500
+ .then((data) => data.data);
501
+ if (!campaigns.length)
502
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
503
+ const elegibleCampaigns = [];
504
+ for (const campaign of campaigns) {
505
+ const today = new Date();
506
+ if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
507
+ continue;
508
+ if (campaign.activeCategory) {
509
+ const categoriesCampaing = campaign.categories.map((c) => c.id);
510
+ const filterProductsCategories = checkout.lineItems.filter((l) => {
511
+ var _a;
512
+ if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
513
+ return true;
514
+ return l.categories.some((c) => categoriesCampaing.some((cat) => cat == c));
515
+ });
516
+ if (filterProductsCategories.length) {
517
+ const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
518
+ if (cartTotalCategories >= campaign.cartValueMin)
519
+ elegibleCampaigns.push(campaign);
520
+ }
521
+ }
522
+ else {
523
+ if (campaign.cartValue && campaign.cartValue > 0) {
524
+ if (campaign.cartValue <= cartTotal)
525
+ elegibleCampaigns.push(campaign);
526
+ }
527
+ }
528
+ }
529
+ if (!elegibleCampaigns.length)
530
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
531
+ const campaingnProducts = [];
532
+ for (const campaign of elegibleCampaigns) {
533
+ let elegibleProducts = [];
534
+ for (const product of campaign.products) {
535
+ const { data: productData } = yield this.productRepository.find({ filters: { sku: product } });
536
+ if (!productData.length)
537
+ continue;
538
+ const gift = productData.shift();
539
+ if (gift.stock.quantity < 1)
540
+ continue;
541
+ elegibleProducts.push(gift);
542
+ }
543
+ campaingnProducts.push(elegibleProducts);
544
+ }
545
+ if (!campaingnProducts.length)
546
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
547
+ const gifts = this.giftToLineItems([].concat(...campaingnProducts));
548
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
549
+ })), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
550
+ }
551
+ giftToLineItems(items) {
552
+ return items.map((item) => {
553
+ var _a;
554
+ const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
555
+ const image = ((_a = item === null || item === void 0 ? void 0 : item.miniatures) === null || _a === void 0 ? void 0 : _a.length) ? item.miniatures[0] : item.images[0];
556
+ return LineItem.toInstance({
557
+ brand,
558
+ categories,
559
+ id: id.toString(),
560
+ name,
561
+ price,
562
+ sku,
563
+ slug,
564
+ stock,
565
+ weight,
566
+ EAN,
567
+ image,
568
+ pricePaid: 0,
569
+ quantity: 1,
570
+ isGift: true,
571
+ });
572
+ });
573
+ }
574
+ }
575
+ CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
576
+ CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
577
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
578
+ type: Injectable
579
+ }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
580
+ type: Inject,
581
+ args: [DEFAULT_SHOP]
582
+ }] }, { type: undefined, decorators: [{
583
+ type: Inject,
584
+ args: ['ProductRepository']
585
+ }] }, { type: undefined, decorators: [{
586
+ type: Inject,
587
+ args: ['VariantRepository']
588
+ }] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
589
+ type: Inject,
590
+ args: ['Buy2WinRepository']
643
591
  }] }]; } });
644
592
 
645
- class CheckoutSubscriptionService {
646
- constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
647
- this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
648
- this.subscriptionRepository = subscriptionRepository;
649
- this.couponService = couponService;
650
- }
651
- getCheckoutSubscription(checkoutData) {
652
- const checkoutId = cookie.get('checkoutSubscriptionId');
653
- if (!isNil(checkoutId))
654
- return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
655
- return from(this.createCheckoutSubscription(checkoutData));
656
- }
657
- createCheckoutSubscription(checkoutData) {
658
- return __awaiter(this, void 0, void 0, function* () {
659
- const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
660
- cookie.set('checkoutSubscriptionId', checkout.id);
661
- return checkout;
662
- });
663
- }
664
- clearCheckoutSubscriptionFromSession() {
665
- cookie.remove('checkoutSubscriptionId');
666
- return of();
667
- }
668
- checkCoupon(nickname, userEmail) {
669
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
670
- .checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, checkout, true)
671
- .pipe()));
672
- }
673
- calcDiscountSubscription(coupon) {
674
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
675
- }
676
- }
677
- CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'SubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
678
- CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService });
679
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
680
- type: Injectable
681
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
682
- type: Inject,
683
- args: ['CheckoutSubscriptionRepository']
684
- }] }, { type: undefined, decorators: [{
685
- type: Inject,
686
- args: ['SubscriptionRepository']
593
+ class CheckoutSubscriptionService {
594
+ constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
595
+ this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
596
+ this.subscriptionRepository = subscriptionRepository;
597
+ this.couponService = couponService;
598
+ }
599
+ getCheckoutSubscription(checkoutData) {
600
+ const checkoutId = cookie.get('checkoutSubscriptionId');
601
+ if (!isNil(checkoutId))
602
+ return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
603
+ return from(this.createCheckoutSubscription(checkoutData));
604
+ }
605
+ createCheckoutSubscription(checkoutData) {
606
+ return __awaiter(this, void 0, void 0, function* () {
607
+ const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
608
+ cookie.set('checkoutSubscriptionId', checkout.id);
609
+ return checkout;
610
+ });
611
+ }
612
+ clearCheckoutSubscriptionFromSession() {
613
+ cookie.remove('checkoutSubscriptionId');
614
+ return of();
615
+ }
616
+ checkCoupon(nickname, userEmail) {
617
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
618
+ .checkCoupon(nickname, CheckoutTypes.SUBSCRIPTION, checkout, checkout.subscriptionPlan.name)
619
+ .pipe()));
620
+ }
621
+ calcDiscountSubscription(coupon) {
622
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
623
+ }
624
+ }
625
+ CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'SubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
626
+ CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService });
627
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
628
+ type: Injectable
629
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
630
+ type: Inject,
631
+ args: ['CheckoutSubscriptionRepository']
632
+ }] }, { type: undefined, decorators: [{
633
+ type: Inject,
634
+ args: ['SubscriptionRepository']
687
635
  }] }, { type: CouponService }]; } });
688
636
 
689
- class HomeShopService {
690
- constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
691
- this.categoryRepository = categoryRepository;
692
- this.homeRepository = homeRepository;
693
- this.productRepository = productRepository;
694
- this.defaultShop = defaultShop;
695
- this.buildCategoryGroupWithRequiredData = (group) => {
696
- var _a, _b;
697
- return ({
698
- category: Category.toInstance(pick(((_a = group === null || group === void 0 ? void 0 : group.category) === null || _a === void 0 ? void 0 : _a.toPlain()) || {}, ['id', 'name', 'slug', 'conditions'])),
699
- products: ((_b = group === null || group === void 0 ? void 0 : group.products) === null || _b === void 0 ? void 0 : _b.map((product) => Product.toInstance(pick((product === null || product === void 0 ? void 0 : product.toPlain()) || {}, [
700
- 'id',
701
- 'price',
702
- 'reviews',
703
- 'hasVariants',
704
- 'slug',
705
- 'sku',
706
- 'stock',
707
- 'costPrice',
708
- 'images',
709
- 'miniatures',
710
- 'name',
711
- 'weight',
712
- 'rate',
713
- 'type',
714
- ])))) || [],
715
- });
716
- };
717
- }
718
- get homeId() {
719
- if (this.defaultShop === Shops.GLAMSHOP)
720
- return 'glamshop';
721
- if (this.defaultShop === Shops.MENSMARKET)
722
- return 'mens_market';
723
- return null;
724
- }
725
- getHomeData() {
726
- return this.getHomeConfiguration().pipe(map((home) => { var _a; return (((_a = home === null || home === void 0 ? void 0 : home.data) === null || _a === void 0 ? void 0 : _a.expiresAt) > new Date() ? home : null); }), concatMap((home) => home
727
- ? of(home)
728
- : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
729
- discoverProducts,
730
- featuredProducts,
731
- verticalProducts,
732
- })), concatMap((data) => this.saveHomeData(data)))));
733
- }
734
- getBanners(type) {
735
- return this.getHomeConfiguration().pipe(map((home) => {
736
- if (type === 'brand')
737
- return home.brandsCarousel;
738
- if (type === 'buyToWin')
739
- return [home.buyToWinBanner];
740
- if (type === 'block')
741
- return home.blockBanners;
742
- if (type === 'blog')
743
- return [home.blogBanner];
744
- }));
745
- }
746
- getMinValueForFreeShipping() {
747
- return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
748
- }
749
- getDiscoverProducts() {
750
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
751
- }
752
- getFeaturedProducts() {
753
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
754
- }
755
- getVerticalProducts() {
756
- return this.getHomeConfiguration().pipe(concatMap((home) => forkJoin(home.verticalCarousels.filter(Boolean).map((id) => from(this.categoryRepository.get({ id })).pipe(concatMap((category) => from(this.productRepository.find({
757
- filters: { categories: { operator: Where.IN, value: [category.id] } },
758
- limits: { limit: 12 },
759
- })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
760
- }
761
- getHomeConfiguration() {
762
- return of(this.homeConfiguration).pipe(concatMap((home) => home
763
- ? of(home)
764
- : !this.homeId
765
- ? throwError(new RequiredArgumentError(['homeId']))
766
- : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
767
- }
768
- saveHomeData(homeData) {
769
- const data = {
770
- createdAt: new Date(),
771
- expiresAt: add(new Date(), { hours: 1 }),
772
- data: homeData,
773
- };
774
- return from(this.homeRepository.update({
775
- id: this.homeId,
776
- data,
777
- })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
778
- }
779
- }
780
- HomeShopService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, deps: [{ token: 'CategoryRepository' }, { token: 'HomeRepository' }, { token: 'ProductRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
781
- HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService });
782
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, decorators: [{
783
- type: Injectable
784
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
785
- type: Inject,
786
- args: ['CategoryRepository']
787
- }] }, { type: undefined, decorators: [{
788
- type: Inject,
789
- args: ['HomeRepository']
790
- }] }, { type: undefined, decorators: [{
791
- type: Inject,
792
- args: ['ProductRepository']
793
- }] }, { type: i3.Shops, decorators: [{
794
- type: Inject,
795
- args: [DEFAULT_SHOP]
637
+ class HomeShopService {
638
+ constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
639
+ this.categoryRepository = categoryRepository;
640
+ this.homeRepository = homeRepository;
641
+ this.productRepository = productRepository;
642
+ this.defaultShop = defaultShop;
643
+ this.buildCategoryGroupWithRequiredData = (group) => {
644
+ var _a, _b;
645
+ return ({
646
+ category: Category.toInstance(pick(((_a = group === null || group === void 0 ? void 0 : group.category) === null || _a === void 0 ? void 0 : _a.toPlain()) || {}, ['id', 'name', 'slug', 'conditions'])),
647
+ products: ((_b = group === null || group === void 0 ? void 0 : group.products) === null || _b === void 0 ? void 0 : _b.map((product) => Product.toInstance(pick((product === null || product === void 0 ? void 0 : product.toPlain()) || {}, [
648
+ 'id',
649
+ 'price',
650
+ 'reviews',
651
+ 'hasVariants',
652
+ 'slug',
653
+ 'sku',
654
+ 'stock',
655
+ 'costPrice',
656
+ 'images',
657
+ 'miniatures',
658
+ 'name',
659
+ 'weight',
660
+ 'rate',
661
+ 'type',
662
+ ])))) || [],
663
+ });
664
+ };
665
+ }
666
+ get homeId() {
667
+ if (this.defaultShop === Shops.GLAMSHOP)
668
+ return 'glamshop';
669
+ if (this.defaultShop === Shops.MENSMARKET)
670
+ return 'mens_market';
671
+ return null;
672
+ }
673
+ getHomeData() {
674
+ return this.getHomeConfiguration().pipe(map((home) => { var _a; return (((_a = home === null || home === void 0 ? void 0 : home.data) === null || _a === void 0 ? void 0 : _a.expiresAt) > new Date() ? home : null); }), concatMap((home) => home
675
+ ? of(home)
676
+ : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
677
+ discoverProducts,
678
+ featuredProducts,
679
+ verticalProducts,
680
+ })), concatMap((data) => this.saveHomeData(data)))));
681
+ }
682
+ getBanners(type) {
683
+ return this.getHomeConfiguration().pipe(map((home) => {
684
+ if (type === 'brand')
685
+ return home.brandsCarousel;
686
+ if (type === 'buyToWin')
687
+ return [home.buyToWinBanner];
688
+ if (type === 'block')
689
+ return home.blockBanners;
690
+ if (type === 'blog')
691
+ return [home.blogBanner];
692
+ }));
693
+ }
694
+ getMinValueForFreeShipping() {
695
+ return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
696
+ }
697
+ getDiscoverProducts() {
698
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
699
+ }
700
+ getFeaturedProducts() {
701
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
702
+ }
703
+ getVerticalProducts() {
704
+ return this.getHomeConfiguration().pipe(concatMap((home) => forkJoin(home.verticalCarousels.filter(Boolean).map((id) => from(this.categoryRepository.get({ id })).pipe(concatMap((category) => from(this.productRepository.find({
705
+ filters: { categories: { operator: Where.IN, value: [category.id] } },
706
+ limits: { limit: 12 },
707
+ })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
708
+ }
709
+ getHomeConfiguration() {
710
+ return of(this.homeConfiguration).pipe(concatMap((home) => home
711
+ ? of(home)
712
+ : !this.homeId
713
+ ? throwError(new RequiredArgumentError(['homeId']))
714
+ : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
715
+ }
716
+ saveHomeData(homeData) {
717
+ const data = {
718
+ createdAt: new Date(),
719
+ expiresAt: add(new Date(), { hours: 1 }),
720
+ data: homeData,
721
+ };
722
+ return from(this.homeRepository.update({
723
+ id: this.homeId,
724
+ data,
725
+ })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
726
+ }
727
+ }
728
+ HomeShopService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, deps: [{ token: 'CategoryRepository' }, { token: 'HomeRepository' }, { token: 'ProductRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
729
+ HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService });
730
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, decorators: [{
731
+ type: Injectable
732
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
733
+ type: Inject,
734
+ args: ['CategoryRepository']
735
+ }] }, { type: undefined, decorators: [{
736
+ type: Inject,
737
+ args: ['HomeRepository']
738
+ }] }, { type: undefined, decorators: [{
739
+ type: Inject,
740
+ args: ['ProductRepository']
741
+ }] }, { type: i3.Shops, decorators: [{
742
+ type: Inject,
743
+ args: [DEFAULT_SHOP]
796
744
  }] }]; } });
797
745
 
798
- class OrderService {
799
- constructor(angularFirestore, orderRepository) {
800
- this.angularFirestore = angularFirestore;
801
- this.orderRepository = orderRepository;
802
- this.orderSubject = new Subject();
803
- }
804
- getOrder(id) {
805
- this.angularFirestore
806
- .doc(`${this.orderRepository.collectionName}/${id}`)
807
- .valueChanges()
808
- .pipe(map((doc) => Order.toInstance(doc)))
809
- .subscribe((doc) => this.orderSubject.next(doc));
810
- return this.orderSubject;
811
- }
812
- }
813
- OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, deps: [{ token: i1$1.AngularFirestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
814
- OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
815
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
816
- type: Injectable
817
- }], ctorParameters: function () { return [{ type: i1$1.AngularFirestore }, { type: i3.OrderFirestoreRepository, decorators: [{
818
- type: Inject,
819
- args: ['OrderRepository']
746
+ class OrderService {
747
+ constructor(angularFirestore, orderRepository) {
748
+ this.angularFirestore = angularFirestore;
749
+ this.orderRepository = orderRepository;
750
+ this.orderSubject = new Subject();
751
+ }
752
+ getOrder(id) {
753
+ this.angularFirestore
754
+ .doc(`${this.orderRepository.collectionName}/${id}`)
755
+ .valueChanges()
756
+ .pipe(map((doc) => Order.toInstance(doc)))
757
+ .subscribe((doc) => this.orderSubject.next(doc));
758
+ return this.orderSubject;
759
+ }
760
+ }
761
+ OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, deps: [{ token: i1$1.AngularFirestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
762
+ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
763
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
764
+ type: Injectable
765
+ }], ctorParameters: function () { return [{ type: i1$1.AngularFirestore }, { type: i3.OrderFirestoreRepository, decorators: [{
766
+ type: Inject,
767
+ args: ['OrderRepository']
820
768
  }] }]; } });
821
769
 
822
- class ShippingService {
823
- constructor(http, apiUrl, homeService) {
824
- this.http = http;
825
- this.apiUrl = apiUrl;
826
- this.homeService = homeService;
827
- }
828
- getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
829
- return combineLatest([
830
- this.homeService.getHomeData(),
831
- this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
832
- ]).pipe(map(([datas, shippingMethodsResponse]) => {
833
- let shippingMethods = shippingMethodsResponse.result;
834
- if (!shippingMethods.length)
835
- return [];
836
- shippingMethods = shippingMethods.map((s) => {
837
- if (s.ShippingCompanyName == 'Same Day EG')
838
- s.ShippingCompanyName = 'Same Day';
839
- else
840
- return s;
841
- });
842
- const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
843
- if (this.isHolidays(datasSameDayNotAvaliable)) {
844
- shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
845
- }
846
- if (totalPrice >= 200) {
847
- shippingMethods = shippingMethods.map((s) => {
848
- if (s.serviceName !== 'Same Day')
849
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
850
- else
851
- return s;
852
- });
853
- }
854
- if (shop == Shops.GLAMSHOP)
855
- return shippingMethods;
856
- if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
857
- shippingMethods = shippingMethods.map((s) => {
858
- if (s.serviceName == 'Same Day')
859
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
860
- else
861
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
862
- });
863
- }
864
- if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
865
- shippingMethods = shippingMethods.map((s) => {
866
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
867
- });
868
- }
869
- return shippingMethods;
870
- }));
871
- }
872
- isFreeShippingBySubscription(shop, subscriptionPlan) {
873
- if (!subscriptionPlan)
874
- return false;
875
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT') {
876
- return true;
877
- }
878
- return false;
879
- }
880
- isHalfShippingBySubscription(shop, subscriptionPlan) {
881
- if (!subscriptionPlan)
882
- return false;
883
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
884
- return true;
885
- }
886
- return false;
887
- }
888
- isHolidays(datas) {
889
- const today = new Date();
890
- for (const key in datas) {
891
- let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
892
- let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
893
- if (start > end)
894
- end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
895
- if (today >= start && today <= end)
896
- return true;
897
- }
898
- return false;
899
- }
900
- }
901
- ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, deps: [{ token: i1$2.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
902
- ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService });
903
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, decorators: [{
904
- type: Injectable
905
- }], ctorParameters: function () { return [{ type: i1$2.HttpClient }, { type: undefined, decorators: [{
906
- type: Inject,
907
- args: [BACKEND_URL]
770
+ class ShippingService {
771
+ constructor(http, apiUrl, homeService) {
772
+ this.http = http;
773
+ this.apiUrl = apiUrl;
774
+ this.homeService = homeService;
775
+ }
776
+ getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
777
+ return combineLatest([
778
+ this.homeService.getHomeData(),
779
+ this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
780
+ ]).pipe(map(([datas, shippingMethodsResponse]) => {
781
+ let shippingMethods = shippingMethodsResponse.result;
782
+ if (!shippingMethods.length)
783
+ return [];
784
+ shippingMethods = shippingMethods.map((s) => {
785
+ if (s.ShippingCompanyName == 'Same Day EG')
786
+ s.ShippingCompanyName = 'Same Day';
787
+ else
788
+ return s;
789
+ });
790
+ const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
791
+ if (this.isHolidays(datasSameDayNotAvaliable)) {
792
+ shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
793
+ }
794
+ if (totalPrice >= 200) {
795
+ shippingMethods = shippingMethods.map((s) => {
796
+ if (s.serviceName !== 'Same Day')
797
+ return Object.assign(Object.assign({}, s), { totalPrice: 0 });
798
+ else
799
+ return s;
800
+ });
801
+ }
802
+ if (shop == Shops.GLAMSHOP)
803
+ return shippingMethods;
804
+ if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
805
+ shippingMethods = shippingMethods.map((s) => {
806
+ if (s.serviceName == 'Same Day')
807
+ return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
808
+ else
809
+ return Object.assign(Object.assign({}, s), { totalPrice: 0 });
810
+ });
811
+ }
812
+ if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
813
+ shippingMethods = shippingMethods.map((s) => {
814
+ return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
815
+ });
816
+ }
817
+ return shippingMethods;
818
+ }));
819
+ }
820
+ isFreeShippingBySubscription(shop, subscriptionPlan) {
821
+ if (!subscriptionPlan)
822
+ return false;
823
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT') {
824
+ return true;
825
+ }
826
+ return false;
827
+ }
828
+ isHalfShippingBySubscription(shop, subscriptionPlan) {
829
+ if (!subscriptionPlan)
830
+ return false;
831
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
832
+ return true;
833
+ }
834
+ return false;
835
+ }
836
+ isHolidays(datas) {
837
+ const today = new Date();
838
+ for (const key in datas) {
839
+ let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
840
+ let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
841
+ if (start > end)
842
+ end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
843
+ if (today >= start && today <= end)
844
+ return true;
845
+ }
846
+ return false;
847
+ }
848
+ }
849
+ ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, deps: [{ token: i1$2.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
850
+ ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService });
851
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, decorators: [{
852
+ type: Injectable
853
+ }], ctorParameters: function () { return [{ type: i1$2.HttpClient }, { type: undefined, decorators: [{
854
+ type: Inject,
855
+ args: [BACKEND_URL]
908
856
  }] }, { type: HomeShopService }]; } });
909
857
 
910
- class AngularFirebaseAuthModule {
911
- static initializeApp(options, nameOrConfig) {
912
- return {
913
- ngModule: AngularFirebaseAuthModule,
914
- providers: [
915
- { provide: FIREBASE_OPTIONS, useValue: options },
916
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
917
- ],
918
- };
919
- }
920
- }
921
- AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
922
- AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
923
- AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
924
- {
925
- provide: 'Authentication',
926
- useFactory: (authenticationService, userRepository) => {
927
- return new Authentication(authenticationService, userRepository);
928
- },
929
- deps: ['AuthenticationService', 'UserRepository'],
930
- },
931
- {
932
- provide: 'AuthenticationService',
933
- useFactory: (angularFireAuth) => {
934
- return new AuthenticationFirebaseAuthService(angularFireAuth);
935
- },
936
- deps: [AngularFireAuth],
937
- },
938
- {
939
- provide: 'Register',
940
- useFactory: (registerService, userRepository) => {
941
- return new Register(registerService, userRepository);
942
- },
943
- deps: ['RegisterService', 'UserRepository'],
944
- },
945
- {
946
- provide: 'RegisterService',
947
- useFactory: (angularFireAuth) => {
948
- return new RegisterFirebaseAuthService(angularFireAuth);
949
- },
950
- deps: [AngularFireAuth],
951
- },
952
- {
953
- provide: 'SignOut',
954
- useFactory: (authenticationService) => {
955
- return new SignOut(authenticationService);
956
- },
957
- deps: ['AuthenticationService'],
958
- },
959
- {
960
- provide: 'RecoveryPassword',
961
- useFactory: (authenticationService) => {
962
- return new RecoveryPassword(authenticationService);
963
- },
964
- deps: ['AuthenticationService'],
965
- },
966
- ], imports: [[AngularFireModule]] });
967
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
968
- type: NgModule,
969
- args: [{
970
- imports: [AngularFireModule],
971
- providers: [
972
- {
973
- provide: 'Authentication',
974
- useFactory: (authenticationService, userRepository) => {
975
- return new Authentication(authenticationService, userRepository);
976
- },
977
- deps: ['AuthenticationService', 'UserRepository'],
978
- },
979
- {
980
- provide: 'AuthenticationService',
981
- useFactory: (angularFireAuth) => {
982
- return new AuthenticationFirebaseAuthService(angularFireAuth);
983
- },
984
- deps: [AngularFireAuth],
985
- },
986
- {
987
- provide: 'Register',
988
- useFactory: (registerService, userRepository) => {
989
- return new Register(registerService, userRepository);
990
- },
991
- deps: ['RegisterService', 'UserRepository'],
992
- },
993
- {
994
- provide: 'RegisterService',
995
- useFactory: (angularFireAuth) => {
996
- return new RegisterFirebaseAuthService(angularFireAuth);
997
- },
998
- deps: [AngularFireAuth],
999
- },
1000
- {
1001
- provide: 'SignOut',
1002
- useFactory: (authenticationService) => {
1003
- return new SignOut(authenticationService);
1004
- },
1005
- deps: ['AuthenticationService'],
1006
- },
1007
- {
1008
- provide: 'RecoveryPassword',
1009
- useFactory: (authenticationService) => {
1010
- return new RecoveryPassword(authenticationService);
1011
- },
1012
- deps: ['AuthenticationService'],
1013
- },
1014
- ],
1015
- }]
858
+ class AngularFirebaseAuthModule {
859
+ static initializeApp(options, nameOrConfig) {
860
+ return {
861
+ ngModule: AngularFirebaseAuthModule,
862
+ providers: [
863
+ { provide: FIREBASE_OPTIONS, useValue: options },
864
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
865
+ ],
866
+ };
867
+ }
868
+ }
869
+ AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
870
+ AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
871
+ AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
872
+ {
873
+ provide: 'Authentication',
874
+ useFactory: (authenticationService, userRepository) => {
875
+ return new Authentication(authenticationService, userRepository);
876
+ },
877
+ deps: ['AuthenticationService', 'UserRepository'],
878
+ },
879
+ {
880
+ provide: 'AuthenticationService',
881
+ useFactory: (angularFireAuth) => {
882
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
883
+ },
884
+ deps: [AngularFireAuth],
885
+ },
886
+ {
887
+ provide: 'Register',
888
+ useFactory: (registerService, userRepository) => {
889
+ return new Register(registerService, userRepository);
890
+ },
891
+ deps: ['RegisterService', 'UserRepository'],
892
+ },
893
+ {
894
+ provide: 'RegisterService',
895
+ useFactory: (angularFireAuth) => {
896
+ return new RegisterFirebaseAuthService(angularFireAuth);
897
+ },
898
+ deps: [AngularFireAuth],
899
+ },
900
+ {
901
+ provide: 'SignOut',
902
+ useFactory: (authenticationService) => {
903
+ return new SignOut(authenticationService);
904
+ },
905
+ deps: ['AuthenticationService'],
906
+ },
907
+ {
908
+ provide: 'RecoveryPassword',
909
+ useFactory: (authenticationService) => {
910
+ return new RecoveryPassword(authenticationService);
911
+ },
912
+ deps: ['AuthenticationService'],
913
+ },
914
+ ], imports: [[AngularFireModule]] });
915
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
916
+ type: NgModule,
917
+ args: [{
918
+ imports: [AngularFireModule],
919
+ providers: [
920
+ {
921
+ provide: 'Authentication',
922
+ useFactory: (authenticationService, userRepository) => {
923
+ return new Authentication(authenticationService, userRepository);
924
+ },
925
+ deps: ['AuthenticationService', 'UserRepository'],
926
+ },
927
+ {
928
+ provide: 'AuthenticationService',
929
+ useFactory: (angularFireAuth) => {
930
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
931
+ },
932
+ deps: [AngularFireAuth],
933
+ },
934
+ {
935
+ provide: 'Register',
936
+ useFactory: (registerService, userRepository) => {
937
+ return new Register(registerService, userRepository);
938
+ },
939
+ deps: ['RegisterService', 'UserRepository'],
940
+ },
941
+ {
942
+ provide: 'RegisterService',
943
+ useFactory: (angularFireAuth) => {
944
+ return new RegisterFirebaseAuthService(angularFireAuth);
945
+ },
946
+ deps: [AngularFireAuth],
947
+ },
948
+ {
949
+ provide: 'SignOut',
950
+ useFactory: (authenticationService) => {
951
+ return new SignOut(authenticationService);
952
+ },
953
+ deps: ['AuthenticationService'],
954
+ },
955
+ {
956
+ provide: 'RecoveryPassword',
957
+ useFactory: (authenticationService) => {
958
+ return new RecoveryPassword(authenticationService);
959
+ },
960
+ deps: ['AuthenticationService'],
961
+ },
962
+ ],
963
+ }]
1016
964
  }] });
1017
965
 
1018
- class AngularElasticSeachModule {
1019
- static initializeApp(options) {
1020
- return {
1021
- ngModule: AngularElasticSeachModule,
1022
- providers: [{ provide: ES_CONFIG, useValue: options }],
1023
- };
1024
- }
1025
- }
1026
- AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1027
- AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule });
1028
- AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, providers: [
1029
- {
1030
- provide: ProductsIndex,
1031
- useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
1032
- deps: [ES_CONFIG],
1033
- },
1034
- ] });
1035
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
1036
- type: NgModule,
1037
- args: [{
1038
- providers: [
1039
- {
1040
- provide: ProductsIndex,
1041
- useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
1042
- deps: [ES_CONFIG],
1043
- },
1044
- ],
1045
- }]
966
+ class AngularElasticSeachModule {
967
+ static initializeApp(options) {
968
+ return {
969
+ ngModule: AngularElasticSeachModule,
970
+ providers: [{ provide: ES_CONFIG, useValue: options }],
971
+ };
972
+ }
973
+ }
974
+ AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
975
+ AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule });
976
+ AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, providers: [
977
+ {
978
+ provide: ProductsIndex,
979
+ useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
980
+ deps: [ES_CONFIG],
981
+ },
982
+ ] });
983
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
984
+ type: NgModule,
985
+ args: [{
986
+ providers: [
987
+ {
988
+ provide: ProductsIndex,
989
+ useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
990
+ deps: [ES_CONFIG],
991
+ },
992
+ ],
993
+ }]
1046
994
  }] });
1047
995
 
1048
- class AngularFirestoreModule {
1049
- static initializeApp(options, nameOrConfig) {
1050
- return {
1051
- ngModule: AngularFirestoreModule,
1052
- providers: [
1053
- { provide: FIREBASE_OPTIONS, useValue: options.firebase },
1054
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
1055
- { provide: ES_CONFIG, useValue: options.elasticSearch },
1056
- ],
1057
- };
1058
- }
1059
- }
1060
- AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1061
- AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule, AngularElasticSeachModule] });
1062
- AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
1063
- {
1064
- provide: 'BeautyProfileRepository',
1065
- useFactory: (firestore, userRepository) => {
1066
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1067
- },
1068
- deps: [AngularFirestore, 'UserRepository'],
1069
- },
1070
- {
1071
- provide: 'Buy2WinRepository',
1072
- useFactory: (firestore) => {
1073
- return new Buy2WinFirestoreRepository(firestore.firestore);
1074
- },
1075
- deps: [AngularFirestore],
1076
- },
1077
- {
1078
- provide: CategoryFirestoreRepository,
1079
- useFactory: (firestore) => {
1080
- return new CategoryFirestoreRepository(firestore.firestore);
1081
- },
1082
- deps: [AngularFirestore],
1083
- },
1084
- {
1085
- provide: 'CheckoutRepository',
1086
- useFactory: (firestore) => {
1087
- return new CheckoutFirestoreRepository(firestore.firestore);
1088
- },
1089
- deps: [AngularFirestore],
1090
- },
1091
- {
1092
- provide: 'CheckoutSubscriptionRepository',
1093
- useFactory: (firestore) => {
1094
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1095
- },
1096
- deps: [AngularFirestore],
1097
- },
1098
- {
1099
- provide: 'CouponRepository',
1100
- useFactory: (firestore) => {
1101
- return new CouponFirestoreRepository(firestore.firestore);
1102
- },
1103
- deps: [AngularFirestore],
1104
- },
1105
- {
1106
- provide: 'CampaignHashtagRepository',
1107
- useFactory: (firestore) => {
1108
- return new CampaignHashtagFirestoreRepository(firestore.firestore);
1109
- },
1110
- deps: [AngularFirestore],
1111
- },
1112
- {
1113
- provide: 'CampaignDashboardRepository',
1114
- useFactory: (firestore) => {
1115
- return new CampaignDashboardFirestoreRepository(firestore.firestore);
1116
- },
1117
- deps: [AngularFirestore],
1118
- },
1119
- {
1120
- provide: 'EditionRepository',
1121
- useFactory: (firestore, subscriptionRepository) => {
1122
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1123
- },
1124
- deps: [AngularFirestore, 'SubscriptionRepository'],
1125
- },
1126
- {
1127
- provide: 'HomeRepository',
1128
- useFactory: (firestore) => {
1129
- return new HomeFirestoreRepository(firestore.firestore);
1130
- },
1131
- deps: [AngularFirestore],
1132
- },
1133
- {
1134
- provide: 'LeadRepository',
1135
- useFactory: (firestore) => {
1136
- return new LeadFirestoreRepository(firestore.firestore);
1137
- },
1138
- deps: [AngularFirestore],
1139
- },
1140
- {
1141
- provide: 'LegacyOrderRepository',
1142
- useFactory: (firestore) => {
1143
- return new LegacyOrderFirestoreRepository(firestore.firestore);
1144
- },
1145
- deps: [AngularFirestore],
1146
- },
1147
- {
1148
- provide: 'ShopMenuRepository',
1149
- useFactory: (firestore) => {
1150
- return new ShopMenuFirestoreRepository(firestore.firestore);
1151
- },
1152
- deps: [AngularFirestore],
1153
- },
1154
- {
1155
- provide: 'OrderRepository',
1156
- useFactory: (firestore) => {
1157
- return new OrderFirestoreRepository(firestore.firestore);
1158
- },
1159
- deps: [AngularFirestore],
1160
- },
1161
- {
1162
- provide: 'PaymentRepository',
1163
- useFactory: (firestore) => {
1164
- return new PaymentFirestoreRepository(firestore.firestore);
1165
- },
1166
- deps: [AngularFirestore],
1167
- },
1168
- {
1169
- provide: ProductFirestoreRepository,
1170
- useFactory: (firestore) => {
1171
- return new ProductFirestoreRepository(firestore.firestore);
1172
- },
1173
- deps: [AngularFirestore],
1174
- },
1175
- {
1176
- provide: 'ShopSettingsRepository',
1177
- useFactory: (firestore) => {
1178
- return new ShopSettingsFirestoreRepository(firestore.firestore);
1179
- },
1180
- deps: [AngularFirestore],
1181
- },
1182
- {
1183
- provide: 'SubscriptionPaymentRepository',
1184
- useFactory: (firestore, subscriptionRepository) => {
1185
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1186
- },
1187
- deps: [AngularFirestore, 'SubscriptionRepository'],
1188
- },
1189
- {
1190
- provide: 'SubscriptionPlanRepository',
1191
- useFactory: (firestore) => {
1192
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1193
- },
1194
- deps: [AngularFirestore],
1195
- },
1196
- {
1197
- provide: 'SubscriptionProductRepository',
1198
- useFactory: (firestore) => {
1199
- return new SubscriptionProductFirestoreRepository(firestore.firestore);
1200
- },
1201
- deps: [AngularFirestore],
1202
- },
1203
- {
1204
- provide: 'SubscriptionRepository',
1205
- useFactory: (firestore) => {
1206
- return new SubscriptionFirestoreRepository(firestore.firestore);
1207
- },
1208
- deps: [AngularFirestore],
1209
- },
1210
- {
1211
- provide: 'UserRepository',
1212
- useFactory: (firestore) => {
1213
- return new UserFirestoreRepository(firestore.firestore);
1214
- },
1215
- deps: [AngularFirestore],
1216
- },
1217
- {
1218
- provide: 'UserAddressRepository',
1219
- useFactory: (firestore, userRepository) => {
1220
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1221
- },
1222
- deps: [AngularFirestore, 'UserRepository'],
1223
- },
1224
- {
1225
- provide: 'UserPaymentMethodRepository',
1226
- useFactory: (firestore, userRepository) => {
1227
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1228
- },
1229
- deps: [AngularFirestore, 'UserRepository'],
1230
- },
1231
- {
1232
- provide: ProductVariantFirestoreRepository,
1233
- useFactory: (firestore, productRepository) => {
1234
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1235
- },
1236
- deps: [AngularFirestore, ProductFirestoreRepository],
1237
- },
1238
- {
1239
- provide: APP_INITIALIZER,
1240
- useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
1241
- deps: [AngularFirestore],
1242
- multi: true,
1243
- },
1244
- ], imports: [[AngularFireModule, AngularElasticSeachModule]] });
1245
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
1246
- type: NgModule,
1247
- args: [{
1248
- imports: [AngularFireModule, AngularElasticSeachModule],
1249
- providers: [
1250
- {
1251
- provide: 'BeautyProfileRepository',
1252
- useFactory: (firestore, userRepository) => {
1253
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1254
- },
1255
- deps: [AngularFirestore, 'UserRepository'],
1256
- },
1257
- {
1258
- provide: 'Buy2WinRepository',
1259
- useFactory: (firestore) => {
1260
- return new Buy2WinFirestoreRepository(firestore.firestore);
1261
- },
1262
- deps: [AngularFirestore],
1263
- },
1264
- {
1265
- provide: CategoryFirestoreRepository,
1266
- useFactory: (firestore) => {
1267
- return new CategoryFirestoreRepository(firestore.firestore);
1268
- },
1269
- deps: [AngularFirestore],
1270
- },
1271
- {
1272
- provide: 'CheckoutRepository',
1273
- useFactory: (firestore) => {
1274
- return new CheckoutFirestoreRepository(firestore.firestore);
1275
- },
1276
- deps: [AngularFirestore],
1277
- },
1278
- {
1279
- provide: 'CheckoutSubscriptionRepository',
1280
- useFactory: (firestore) => {
1281
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1282
- },
1283
- deps: [AngularFirestore],
1284
- },
1285
- {
1286
- provide: 'CouponRepository',
1287
- useFactory: (firestore) => {
1288
- return new CouponFirestoreRepository(firestore.firestore);
1289
- },
1290
- deps: [AngularFirestore],
1291
- },
1292
- {
1293
- provide: 'CampaignHashtagRepository',
1294
- useFactory: (firestore) => {
1295
- return new CampaignHashtagFirestoreRepository(firestore.firestore);
1296
- },
1297
- deps: [AngularFirestore],
1298
- },
1299
- {
1300
- provide: 'CampaignDashboardRepository',
1301
- useFactory: (firestore) => {
1302
- return new CampaignDashboardFirestoreRepository(firestore.firestore);
1303
- },
1304
- deps: [AngularFirestore],
1305
- },
1306
- {
1307
- provide: 'EditionRepository',
1308
- useFactory: (firestore, subscriptionRepository) => {
1309
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1310
- },
1311
- deps: [AngularFirestore, 'SubscriptionRepository'],
1312
- },
1313
- {
1314
- provide: 'HomeRepository',
1315
- useFactory: (firestore) => {
1316
- return new HomeFirestoreRepository(firestore.firestore);
1317
- },
1318
- deps: [AngularFirestore],
1319
- },
1320
- {
1321
- provide: 'LeadRepository',
1322
- useFactory: (firestore) => {
1323
- return new LeadFirestoreRepository(firestore.firestore);
1324
- },
1325
- deps: [AngularFirestore],
1326
- },
1327
- {
1328
- provide: 'LegacyOrderRepository',
1329
- useFactory: (firestore) => {
1330
- return new LegacyOrderFirestoreRepository(firestore.firestore);
1331
- },
1332
- deps: [AngularFirestore],
1333
- },
1334
- {
1335
- provide: 'ShopMenuRepository',
1336
- useFactory: (firestore) => {
1337
- return new ShopMenuFirestoreRepository(firestore.firestore);
1338
- },
1339
- deps: [AngularFirestore],
1340
- },
1341
- {
1342
- provide: 'OrderRepository',
1343
- useFactory: (firestore) => {
1344
- return new OrderFirestoreRepository(firestore.firestore);
1345
- },
1346
- deps: [AngularFirestore],
1347
- },
1348
- {
1349
- provide: 'PaymentRepository',
1350
- useFactory: (firestore) => {
1351
- return new PaymentFirestoreRepository(firestore.firestore);
1352
- },
1353
- deps: [AngularFirestore],
1354
- },
1355
- {
1356
- provide: ProductFirestoreRepository,
1357
- useFactory: (firestore) => {
1358
- return new ProductFirestoreRepository(firestore.firestore);
1359
- },
1360
- deps: [AngularFirestore],
1361
- },
1362
- {
1363
- provide: 'ShopSettingsRepository',
1364
- useFactory: (firestore) => {
1365
- return new ShopSettingsFirestoreRepository(firestore.firestore);
1366
- },
1367
- deps: [AngularFirestore],
1368
- },
1369
- {
1370
- provide: 'SubscriptionPaymentRepository',
1371
- useFactory: (firestore, subscriptionRepository) => {
1372
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1373
- },
1374
- deps: [AngularFirestore, 'SubscriptionRepository'],
1375
- },
1376
- {
1377
- provide: 'SubscriptionPlanRepository',
1378
- useFactory: (firestore) => {
1379
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1380
- },
1381
- deps: [AngularFirestore],
1382
- },
1383
- {
1384
- provide: 'SubscriptionProductRepository',
1385
- useFactory: (firestore) => {
1386
- return new SubscriptionProductFirestoreRepository(firestore.firestore);
1387
- },
1388
- deps: [AngularFirestore],
1389
- },
1390
- {
1391
- provide: 'SubscriptionRepository',
1392
- useFactory: (firestore) => {
1393
- return new SubscriptionFirestoreRepository(firestore.firestore);
1394
- },
1395
- deps: [AngularFirestore],
1396
- },
1397
- {
1398
- provide: 'UserRepository',
1399
- useFactory: (firestore) => {
1400
- return new UserFirestoreRepository(firestore.firestore);
1401
- },
1402
- deps: [AngularFirestore],
1403
- },
1404
- {
1405
- provide: 'UserAddressRepository',
1406
- useFactory: (firestore, userRepository) => {
1407
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1408
- },
1409
- deps: [AngularFirestore, 'UserRepository'],
1410
- },
1411
- {
1412
- provide: 'UserPaymentMethodRepository',
1413
- useFactory: (firestore, userRepository) => {
1414
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1415
- },
1416
- deps: [AngularFirestore, 'UserRepository'],
1417
- },
1418
- {
1419
- provide: ProductVariantFirestoreRepository,
1420
- useFactory: (firestore, productRepository) => {
1421
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1422
- },
1423
- deps: [AngularFirestore, ProductFirestoreRepository],
1424
- },
1425
- {
1426
- provide: APP_INITIALIZER,
1427
- useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
1428
- deps: [AngularFirestore],
1429
- multi: true,
1430
- },
1431
- ],
1432
- }]
996
+ class AngularFirestoreModule {
997
+ static initializeApp(options, nameOrConfig) {
998
+ return {
999
+ ngModule: AngularFirestoreModule,
1000
+ providers: [
1001
+ { provide: FIREBASE_OPTIONS, useValue: options.firebase },
1002
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
1003
+ { provide: ES_CONFIG, useValue: options.elasticSearch },
1004
+ ],
1005
+ };
1006
+ }
1007
+ }
1008
+ AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1009
+ AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule, AngularElasticSeachModule] });
1010
+ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
1011
+ {
1012
+ provide: 'BeautyProfileRepository',
1013
+ useFactory: (firestore, userRepository) => {
1014
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1015
+ },
1016
+ deps: [AngularFirestore, 'UserRepository'],
1017
+ },
1018
+ {
1019
+ provide: 'Buy2WinRepository',
1020
+ useFactory: (firestore) => {
1021
+ return new Buy2WinFirestoreRepository(firestore.firestore);
1022
+ },
1023
+ deps: [AngularFirestore],
1024
+ },
1025
+ {
1026
+ provide: CategoryFirestoreRepository,
1027
+ useFactory: (firestore) => {
1028
+ return new CategoryFirestoreRepository(firestore.firestore);
1029
+ },
1030
+ deps: [AngularFirestore],
1031
+ },
1032
+ {
1033
+ provide: 'CheckoutRepository',
1034
+ useFactory: (firestore) => {
1035
+ return new CheckoutFirestoreRepository(firestore.firestore);
1036
+ },
1037
+ deps: [AngularFirestore],
1038
+ },
1039
+ {
1040
+ provide: 'CheckoutSubscriptionRepository',
1041
+ useFactory: (firestore) => {
1042
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1043
+ },
1044
+ deps: [AngularFirestore],
1045
+ },
1046
+ {
1047
+ provide: 'CouponRepository',
1048
+ useFactory: (firestore) => {
1049
+ return new CouponFirestoreRepository(firestore.firestore);
1050
+ },
1051
+ deps: [AngularFirestore],
1052
+ },
1053
+ {
1054
+ provide: 'CampaignHashtagRepository',
1055
+ useFactory: (firestore) => {
1056
+ return new CampaignHashtagFirestoreRepository(firestore.firestore);
1057
+ },
1058
+ deps: [AngularFirestore],
1059
+ },
1060
+ {
1061
+ provide: 'CampaignDashboardRepository',
1062
+ useFactory: (firestore) => {
1063
+ return new CampaignDashboardFirestoreRepository(firestore.firestore);
1064
+ },
1065
+ deps: [AngularFirestore],
1066
+ },
1067
+ {
1068
+ provide: 'EditionRepository',
1069
+ useFactory: (firestore, subscriptionRepository) => {
1070
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1071
+ },
1072
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1073
+ },
1074
+ {
1075
+ provide: 'HomeRepository',
1076
+ useFactory: (firestore) => {
1077
+ return new HomeFirestoreRepository(firestore.firestore);
1078
+ },
1079
+ deps: [AngularFirestore],
1080
+ },
1081
+ {
1082
+ provide: 'LeadRepository',
1083
+ useFactory: (firestore) => {
1084
+ return new LeadFirestoreRepository(firestore.firestore);
1085
+ },
1086
+ deps: [AngularFirestore],
1087
+ },
1088
+ {
1089
+ provide: 'LegacyOrderRepository',
1090
+ useFactory: (firestore) => {
1091
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
1092
+ },
1093
+ deps: [AngularFirestore],
1094
+ },
1095
+ {
1096
+ provide: 'ShopMenuRepository',
1097
+ useFactory: (firestore) => {
1098
+ return new ShopMenuFirestoreRepository(firestore.firestore);
1099
+ },
1100
+ deps: [AngularFirestore],
1101
+ },
1102
+ {
1103
+ provide: 'OrderRepository',
1104
+ useFactory: (firestore) => {
1105
+ return new OrderFirestoreRepository(firestore.firestore);
1106
+ },
1107
+ deps: [AngularFirestore],
1108
+ },
1109
+ {
1110
+ provide: 'PaymentRepository',
1111
+ useFactory: (firestore) => {
1112
+ return new PaymentFirestoreRepository(firestore.firestore);
1113
+ },
1114
+ deps: [AngularFirestore],
1115
+ },
1116
+ {
1117
+ provide: ProductFirestoreRepository,
1118
+ useFactory: (firestore) => {
1119
+ return new ProductFirestoreRepository(firestore.firestore);
1120
+ },
1121
+ deps: [AngularFirestore],
1122
+ },
1123
+ {
1124
+ provide: 'ShopSettingsRepository',
1125
+ useFactory: (firestore) => {
1126
+ return new ShopSettingsFirestoreRepository(firestore.firestore);
1127
+ },
1128
+ deps: [AngularFirestore],
1129
+ },
1130
+ {
1131
+ provide: 'SubscriptionPaymentRepository',
1132
+ useFactory: (firestore, subscriptionRepository) => {
1133
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1134
+ },
1135
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1136
+ },
1137
+ {
1138
+ provide: 'SubscriptionPlanRepository',
1139
+ useFactory: (firestore) => {
1140
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1141
+ },
1142
+ deps: [AngularFirestore],
1143
+ },
1144
+ {
1145
+ provide: 'SubscriptionProductRepository',
1146
+ useFactory: (firestore) => {
1147
+ return new SubscriptionProductFirestoreRepository(firestore.firestore);
1148
+ },
1149
+ deps: [AngularFirestore],
1150
+ },
1151
+ {
1152
+ provide: 'SubscriptionRepository',
1153
+ useFactory: (firestore) => {
1154
+ return new SubscriptionFirestoreRepository(firestore.firestore);
1155
+ },
1156
+ deps: [AngularFirestore],
1157
+ },
1158
+ {
1159
+ provide: 'UserRepository',
1160
+ useFactory: (firestore) => {
1161
+ return new UserFirestoreRepository(firestore.firestore);
1162
+ },
1163
+ deps: [AngularFirestore],
1164
+ },
1165
+ {
1166
+ provide: 'UserAddressRepository',
1167
+ useFactory: (firestore, userRepository) => {
1168
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1169
+ },
1170
+ deps: [AngularFirestore, 'UserRepository'],
1171
+ },
1172
+ {
1173
+ provide: 'UserPaymentMethodRepository',
1174
+ useFactory: (firestore, userRepository) => {
1175
+ return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1176
+ },
1177
+ deps: [AngularFirestore, 'UserRepository'],
1178
+ },
1179
+ {
1180
+ provide: ProductVariantFirestoreRepository,
1181
+ useFactory: (firestore, productRepository) => {
1182
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1183
+ },
1184
+ deps: [AngularFirestore, ProductFirestoreRepository],
1185
+ },
1186
+ {
1187
+ provide: APP_INITIALIZER,
1188
+ useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
1189
+ deps: [AngularFirestore],
1190
+ multi: true,
1191
+ },
1192
+ ], imports: [[AngularFireModule, AngularElasticSeachModule]] });
1193
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
1194
+ type: NgModule,
1195
+ args: [{
1196
+ imports: [AngularFireModule, AngularElasticSeachModule],
1197
+ providers: [
1198
+ {
1199
+ provide: 'BeautyProfileRepository',
1200
+ useFactory: (firestore, userRepository) => {
1201
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1202
+ },
1203
+ deps: [AngularFirestore, 'UserRepository'],
1204
+ },
1205
+ {
1206
+ provide: 'Buy2WinRepository',
1207
+ useFactory: (firestore) => {
1208
+ return new Buy2WinFirestoreRepository(firestore.firestore);
1209
+ },
1210
+ deps: [AngularFirestore],
1211
+ },
1212
+ {
1213
+ provide: CategoryFirestoreRepository,
1214
+ useFactory: (firestore) => {
1215
+ return new CategoryFirestoreRepository(firestore.firestore);
1216
+ },
1217
+ deps: [AngularFirestore],
1218
+ },
1219
+ {
1220
+ provide: 'CheckoutRepository',
1221
+ useFactory: (firestore) => {
1222
+ return new CheckoutFirestoreRepository(firestore.firestore);
1223
+ },
1224
+ deps: [AngularFirestore],
1225
+ },
1226
+ {
1227
+ provide: 'CheckoutSubscriptionRepository',
1228
+ useFactory: (firestore) => {
1229
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1230
+ },
1231
+ deps: [AngularFirestore],
1232
+ },
1233
+ {
1234
+ provide: 'CouponRepository',
1235
+ useFactory: (firestore) => {
1236
+ return new CouponFirestoreRepository(firestore.firestore);
1237
+ },
1238
+ deps: [AngularFirestore],
1239
+ },
1240
+ {
1241
+ provide: 'CampaignHashtagRepository',
1242
+ useFactory: (firestore) => {
1243
+ return new CampaignHashtagFirestoreRepository(firestore.firestore);
1244
+ },
1245
+ deps: [AngularFirestore],
1246
+ },
1247
+ {
1248
+ provide: 'CampaignDashboardRepository',
1249
+ useFactory: (firestore) => {
1250
+ return new CampaignDashboardFirestoreRepository(firestore.firestore);
1251
+ },
1252
+ deps: [AngularFirestore],
1253
+ },
1254
+ {
1255
+ provide: 'EditionRepository',
1256
+ useFactory: (firestore, subscriptionRepository) => {
1257
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1258
+ },
1259
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1260
+ },
1261
+ {
1262
+ provide: 'HomeRepository',
1263
+ useFactory: (firestore) => {
1264
+ return new HomeFirestoreRepository(firestore.firestore);
1265
+ },
1266
+ deps: [AngularFirestore],
1267
+ },
1268
+ {
1269
+ provide: 'LeadRepository',
1270
+ useFactory: (firestore) => {
1271
+ return new LeadFirestoreRepository(firestore.firestore);
1272
+ },
1273
+ deps: [AngularFirestore],
1274
+ },
1275
+ {
1276
+ provide: 'LegacyOrderRepository',
1277
+ useFactory: (firestore) => {
1278
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
1279
+ },
1280
+ deps: [AngularFirestore],
1281
+ },
1282
+ {
1283
+ provide: 'ShopMenuRepository',
1284
+ useFactory: (firestore) => {
1285
+ return new ShopMenuFirestoreRepository(firestore.firestore);
1286
+ },
1287
+ deps: [AngularFirestore],
1288
+ },
1289
+ {
1290
+ provide: 'OrderRepository',
1291
+ useFactory: (firestore) => {
1292
+ return new OrderFirestoreRepository(firestore.firestore);
1293
+ },
1294
+ deps: [AngularFirestore],
1295
+ },
1296
+ {
1297
+ provide: 'PaymentRepository',
1298
+ useFactory: (firestore) => {
1299
+ return new PaymentFirestoreRepository(firestore.firestore);
1300
+ },
1301
+ deps: [AngularFirestore],
1302
+ },
1303
+ {
1304
+ provide: ProductFirestoreRepository,
1305
+ useFactory: (firestore) => {
1306
+ return new ProductFirestoreRepository(firestore.firestore);
1307
+ },
1308
+ deps: [AngularFirestore],
1309
+ },
1310
+ {
1311
+ provide: 'ShopSettingsRepository',
1312
+ useFactory: (firestore) => {
1313
+ return new ShopSettingsFirestoreRepository(firestore.firestore);
1314
+ },
1315
+ deps: [AngularFirestore],
1316
+ },
1317
+ {
1318
+ provide: 'SubscriptionPaymentRepository',
1319
+ useFactory: (firestore, subscriptionRepository) => {
1320
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1321
+ },
1322
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1323
+ },
1324
+ {
1325
+ provide: 'SubscriptionPlanRepository',
1326
+ useFactory: (firestore) => {
1327
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1328
+ },
1329
+ deps: [AngularFirestore],
1330
+ },
1331
+ {
1332
+ provide: 'SubscriptionProductRepository',
1333
+ useFactory: (firestore) => {
1334
+ return new SubscriptionProductFirestoreRepository(firestore.firestore);
1335
+ },
1336
+ deps: [AngularFirestore],
1337
+ },
1338
+ {
1339
+ provide: 'SubscriptionRepository',
1340
+ useFactory: (firestore) => {
1341
+ return new SubscriptionFirestoreRepository(firestore.firestore);
1342
+ },
1343
+ deps: [AngularFirestore],
1344
+ },
1345
+ {
1346
+ provide: 'UserRepository',
1347
+ useFactory: (firestore) => {
1348
+ return new UserFirestoreRepository(firestore.firestore);
1349
+ },
1350
+ deps: [AngularFirestore],
1351
+ },
1352
+ {
1353
+ provide: 'UserAddressRepository',
1354
+ useFactory: (firestore, userRepository) => {
1355
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1356
+ },
1357
+ deps: [AngularFirestore, 'UserRepository'],
1358
+ },
1359
+ {
1360
+ provide: 'UserPaymentMethodRepository',
1361
+ useFactory: (firestore, userRepository) => {
1362
+ return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1363
+ },
1364
+ deps: [AngularFirestore, 'UserRepository'],
1365
+ },
1366
+ {
1367
+ provide: ProductVariantFirestoreRepository,
1368
+ useFactory: (firestore, productRepository) => {
1369
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1370
+ },
1371
+ deps: [AngularFirestore, ProductFirestoreRepository],
1372
+ },
1373
+ {
1374
+ provide: APP_INITIALIZER,
1375
+ useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
1376
+ deps: [AngularFirestore],
1377
+ multi: true,
1378
+ },
1379
+ ],
1380
+ }]
1433
1381
  }] });
1434
1382
 
1435
- class AngularHasuraGraphQLModule {
1436
- static initializeApp(options) {
1437
- return {
1438
- ngModule: AngularHasuraGraphQLModule,
1439
- providers: [{ provide: HASURA_OPTIONS, useValue: options }],
1440
- };
1441
- }
1442
- }
1443
- AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1444
- AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule });
1445
- AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
1446
- {
1447
- provide: 'CategoryRepository',
1448
- useExisting: CategoryHasuraGraphQLRepository,
1449
- },
1450
- {
1451
- provide: CategoryHasuraGraphQLRepository,
1452
- useFactory: (options, productRepository, categoryFilterRepository) => {
1453
- return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
1454
- },
1455
- deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1456
- },
1457
- {
1458
- provide: 'ProductRepository',
1459
- useExisting: ProductHasuraGraphQLRepository,
1460
- },
1461
- {
1462
- provide: ProductHasuraGraphQLRepository,
1463
- useFactory: (options) => {
1464
- return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1465
- },
1466
- deps: [HASURA_OPTIONS],
1467
- },
1468
- {
1469
- provide: 'VariantRepository',
1470
- useExisting: VariantHasuraGraphQLRepository,
1471
- },
1472
- {
1473
- provide: VariantHasuraGraphQLRepository,
1474
- useFactory: (options) => {
1475
- return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1476
- },
1477
- deps: [HASURA_OPTIONS],
1478
- },
1479
- {
1480
- provide: 'CategoryFilterRepository',
1481
- useExisting: CategoryFilterHasuraGraphQLRepository,
1482
- },
1483
- {
1484
- provide: CategoryFilterHasuraGraphQLRepository,
1485
- useFactory: (options) => {
1486
- return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
1487
- },
1488
- deps: [HASURA_OPTIONS],
1489
- },
1490
- {
1491
- provide: 'FilterOptionRepository',
1492
- useExisting: FilterOptionHasuraGraphQLRepository,
1493
- },
1494
- {
1495
- provide: FilterOptionHasuraGraphQLRepository,
1496
- useFactory: (options) => {
1497
- return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
1498
- },
1499
- deps: [HASURA_OPTIONS],
1500
- },
1501
- {
1502
- provide: 'FilterRepository',
1503
- useExisting: FilterHasuraGraphQLRepository,
1504
- },
1505
- {
1506
- provide: FilterHasuraGraphQLRepository,
1507
- useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
1508
- return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
1509
- },
1510
- deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1511
- },
1512
- ] });
1513
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
1514
- type: NgModule,
1515
- args: [{
1516
- providers: [
1517
- {
1518
- provide: 'CategoryRepository',
1519
- useExisting: CategoryHasuraGraphQLRepository,
1520
- },
1521
- {
1522
- provide: CategoryHasuraGraphQLRepository,
1523
- useFactory: (options, productRepository, categoryFilterRepository) => {
1524
- return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
1525
- },
1526
- deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1527
- },
1528
- {
1529
- provide: 'ProductRepository',
1530
- useExisting: ProductHasuraGraphQLRepository,
1531
- },
1532
- {
1533
- provide: ProductHasuraGraphQLRepository,
1534
- useFactory: (options) => {
1535
- return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1536
- },
1537
- deps: [HASURA_OPTIONS],
1538
- },
1539
- {
1540
- provide: 'VariantRepository',
1541
- useExisting: VariantHasuraGraphQLRepository,
1542
- },
1543
- {
1544
- provide: VariantHasuraGraphQLRepository,
1545
- useFactory: (options) => {
1546
- return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1547
- },
1548
- deps: [HASURA_OPTIONS],
1549
- },
1550
- {
1551
- provide: 'CategoryFilterRepository',
1552
- useExisting: CategoryFilterHasuraGraphQLRepository,
1553
- },
1554
- {
1555
- provide: CategoryFilterHasuraGraphQLRepository,
1556
- useFactory: (options) => {
1557
- return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
1558
- },
1559
- deps: [HASURA_OPTIONS],
1560
- },
1561
- {
1562
- provide: 'FilterOptionRepository',
1563
- useExisting: FilterOptionHasuraGraphQLRepository,
1564
- },
1565
- {
1566
- provide: FilterOptionHasuraGraphQLRepository,
1567
- useFactory: (options) => {
1568
- return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
1569
- },
1570
- deps: [HASURA_OPTIONS],
1571
- },
1572
- {
1573
- provide: 'FilterRepository',
1574
- useExisting: FilterHasuraGraphQLRepository,
1575
- },
1576
- {
1577
- provide: FilterHasuraGraphQLRepository,
1578
- useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
1579
- return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
1580
- },
1581
- deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1582
- },
1583
- ],
1584
- }]
1383
+ class AngularHasuraGraphQLModule {
1384
+ static initializeApp(options) {
1385
+ return {
1386
+ ngModule: AngularHasuraGraphQLModule,
1387
+ providers: [{ provide: HASURA_OPTIONS, useValue: options }],
1388
+ };
1389
+ }
1390
+ }
1391
+ AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1392
+ AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule });
1393
+ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
1394
+ {
1395
+ provide: 'CategoryRepository',
1396
+ useExisting: CategoryHasuraGraphQLRepository,
1397
+ },
1398
+ {
1399
+ provide: CategoryHasuraGraphQLRepository,
1400
+ useFactory: (options, productRepository, categoryFilterRepository) => {
1401
+ return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
1402
+ },
1403
+ deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1404
+ },
1405
+ {
1406
+ provide: 'ProductRepository',
1407
+ useExisting: ProductHasuraGraphQLRepository,
1408
+ },
1409
+ {
1410
+ provide: ProductHasuraGraphQLRepository,
1411
+ useFactory: (options) => {
1412
+ return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1413
+ },
1414
+ deps: [HASURA_OPTIONS],
1415
+ },
1416
+ {
1417
+ provide: 'VariantRepository',
1418
+ useExisting: VariantHasuraGraphQLRepository,
1419
+ },
1420
+ {
1421
+ provide: VariantHasuraGraphQLRepository,
1422
+ useFactory: (options) => {
1423
+ return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1424
+ },
1425
+ deps: [HASURA_OPTIONS],
1426
+ },
1427
+ {
1428
+ provide: 'CategoryFilterRepository',
1429
+ useExisting: CategoryFilterHasuraGraphQLRepository,
1430
+ },
1431
+ {
1432
+ provide: CategoryFilterHasuraGraphQLRepository,
1433
+ useFactory: (options) => {
1434
+ return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
1435
+ },
1436
+ deps: [HASURA_OPTIONS],
1437
+ },
1438
+ {
1439
+ provide: 'FilterOptionRepository',
1440
+ useExisting: FilterOptionHasuraGraphQLRepository,
1441
+ },
1442
+ {
1443
+ provide: FilterOptionHasuraGraphQLRepository,
1444
+ useFactory: (options) => {
1445
+ return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
1446
+ },
1447
+ deps: [HASURA_OPTIONS],
1448
+ },
1449
+ {
1450
+ provide: 'FilterRepository',
1451
+ useExisting: FilterHasuraGraphQLRepository,
1452
+ },
1453
+ {
1454
+ provide: FilterHasuraGraphQLRepository,
1455
+ useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
1456
+ return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
1457
+ },
1458
+ deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1459
+ },
1460
+ ] });
1461
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
1462
+ type: NgModule,
1463
+ args: [{
1464
+ providers: [
1465
+ {
1466
+ provide: 'CategoryRepository',
1467
+ useExisting: CategoryHasuraGraphQLRepository,
1468
+ },
1469
+ {
1470
+ provide: CategoryHasuraGraphQLRepository,
1471
+ useFactory: (options, productRepository, categoryFilterRepository) => {
1472
+ return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
1473
+ },
1474
+ deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1475
+ },
1476
+ {
1477
+ provide: 'ProductRepository',
1478
+ useExisting: ProductHasuraGraphQLRepository,
1479
+ },
1480
+ {
1481
+ provide: ProductHasuraGraphQLRepository,
1482
+ useFactory: (options) => {
1483
+ return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1484
+ },
1485
+ deps: [HASURA_OPTIONS],
1486
+ },
1487
+ {
1488
+ provide: 'VariantRepository',
1489
+ useExisting: VariantHasuraGraphQLRepository,
1490
+ },
1491
+ {
1492
+ provide: VariantHasuraGraphQLRepository,
1493
+ useFactory: (options) => {
1494
+ return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1495
+ },
1496
+ deps: [HASURA_OPTIONS],
1497
+ },
1498
+ {
1499
+ provide: 'CategoryFilterRepository',
1500
+ useExisting: CategoryFilterHasuraGraphQLRepository,
1501
+ },
1502
+ {
1503
+ provide: CategoryFilterHasuraGraphQLRepository,
1504
+ useFactory: (options) => {
1505
+ return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
1506
+ },
1507
+ deps: [HASURA_OPTIONS],
1508
+ },
1509
+ {
1510
+ provide: 'FilterOptionRepository',
1511
+ useExisting: FilterOptionHasuraGraphQLRepository,
1512
+ },
1513
+ {
1514
+ provide: FilterOptionHasuraGraphQLRepository,
1515
+ useFactory: (options) => {
1516
+ return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
1517
+ },
1518
+ deps: [HASURA_OPTIONS],
1519
+ },
1520
+ {
1521
+ provide: 'FilterRepository',
1522
+ useExisting: FilterHasuraGraphQLRepository,
1523
+ },
1524
+ {
1525
+ provide: FilterHasuraGraphQLRepository,
1526
+ useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
1527
+ return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
1528
+ },
1529
+ deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1530
+ },
1531
+ ],
1532
+ }]
1585
1533
  }] });
1586
1534
 
1587
- class AngularConnectModule {
1588
- static initializeApp(defaultShop, options, nameOrConfig) {
1589
- return {
1590
- ngModule: AngularConnectModule,
1591
- providers: [
1592
- ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
1593
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
1594
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
1595
- ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
1596
- ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
1597
- ...(isNil(options === null || options === void 0 ? void 0 : options.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
1598
- ],
1599
- };
1600
- }
1601
- }
1602
- AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1603
- AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
1604
- AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [
1605
- AuthService,
1606
- CartService,
1607
- CheckoutService,
1608
- CheckoutSubscriptionService,
1609
- CouponService,
1610
- HomeShopService,
1611
- OrderService,
1612
- ShippingService,
1613
- ], imports: [[AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
1614
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
1615
- type: NgModule,
1616
- args: [{
1617
- imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule],
1618
- providers: [
1619
- AuthService,
1620
- CartService,
1621
- CheckoutService,
1622
- CheckoutSubscriptionService,
1623
- CouponService,
1624
- HomeShopService,
1625
- OrderService,
1626
- ShippingService,
1627
- ],
1628
- }]
1535
+ class AngularConnectModule {
1536
+ static initializeApp(defaultShop, options, nameOrConfig) {
1537
+ return {
1538
+ ngModule: AngularConnectModule,
1539
+ providers: [
1540
+ ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
1541
+ ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
1542
+ ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
1543
+ ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
1544
+ ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
1545
+ ...(isNil(options === null || options === void 0 ? void 0 : options.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
1546
+ ],
1547
+ };
1548
+ }
1549
+ }
1550
+ AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1551
+ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
1552
+ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [
1553
+ AuthService,
1554
+ CartService,
1555
+ CheckoutService,
1556
+ CheckoutSubscriptionService,
1557
+ CouponService,
1558
+ HomeShopService,
1559
+ OrderService,
1560
+ ShippingService,
1561
+ ], imports: [[AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
1562
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
1563
+ type: NgModule,
1564
+ args: [{
1565
+ imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule],
1566
+ providers: [
1567
+ AuthService,
1568
+ CartService,
1569
+ CheckoutService,
1570
+ CheckoutSubscriptionService,
1571
+ CouponService,
1572
+ HomeShopService,
1573
+ OrderService,
1574
+ ShippingService,
1575
+ ],
1576
+ }]
1629
1577
  }] });
1630
1578
 
1631
- /**
1632
- * Generated bundle index. Do not edit.
1579
+ /**
1580
+ * Generated bundle index. Do not edit.
1633
1581
  */
1634
1582
 
1635
1583
  export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ShippingService };