@infrab4a/connect-angular 0.12.4 → 0.12.5

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 (47) hide show
  1. package/bundles/infrab4a-connect-angular.umd.js +1250 -1243
  2. package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
  3. package/esm2015/infrab4a-connect-angular.js +4 -4
  4. package/esm2015/lib/angular-connect.module.js +29 -29
  5. package/esm2015/lib/angular-firebase-auth.module.js +113 -113
  6. package/esm2015/lib/angular-firestore.module.js +336 -336
  7. package/esm2015/lib/consts/default-shop.const.js +1 -1
  8. package/esm2015/lib/consts/index.js +1 -1
  9. package/esm2015/lib/index.js +4 -4
  10. package/esm2015/lib/services/auth.service.js +41 -41
  11. package/esm2015/lib/services/cart.service.js +165 -165
  12. package/esm2015/lib/services/checkout-subscription.service.js +66 -95
  13. package/esm2015/lib/services/checkout.service.js +79 -79
  14. package/esm2015/lib/services/coupon.service.js +70 -51
  15. package/esm2015/lib/services/errors/group-invalid-coupon.error.js +7 -0
  16. package/esm2015/lib/services/errors/index.js +3 -2
  17. package/esm2015/lib/services/errors/invalid-coupon.error.js +6 -6
  18. package/esm2015/lib/services/index.js +6 -6
  19. package/esm2015/lib/services/order.service.js +31 -31
  20. package/esm2015/lib/services/types/index.js +2 -2
  21. package/esm2015/lib/services/types/required-checkout-data.type.js +1 -1
  22. package/esm2015/lib/services/types/required-checkout-subscription-data.type.js +1 -1
  23. package/esm2015/public-api.js +1 -1
  24. package/fesm2015/infrab4a-connect-angular.js +864 -867
  25. package/fesm2015/infrab4a-connect-angular.js.map +1 -1
  26. package/infrab4a-connect-angular.d.ts +5 -5
  27. package/lib/angular-connect.module.d.ts +12 -12
  28. package/lib/angular-firebase-auth.module.d.ts +10 -10
  29. package/lib/angular-firestore.module.d.ts +10 -10
  30. package/lib/consts/default-shop.const.d.ts +1 -1
  31. package/lib/consts/index.d.ts +1 -1
  32. package/lib/index.d.ts +4 -4
  33. package/lib/services/auth.service.d.ts +19 -19
  34. package/lib/services/cart.service.d.ts +41 -41
  35. package/lib/services/checkout-subscription.service.d.ts +17 -19
  36. package/lib/services/checkout.service.d.ts +22 -22
  37. package/lib/services/coupon.service.d.ts +14 -13
  38. package/lib/services/errors/group-invalid-coupon.error.d.ts +5 -0
  39. package/lib/services/errors/index.d.ts +2 -1
  40. package/lib/services/errors/invalid-coupon.error.d.ts +4 -4
  41. package/lib/services/index.d.ts +6 -6
  42. package/lib/services/order.service.d.ts +13 -13
  43. package/lib/services/types/index.d.ts +2 -2
  44. package/lib/services/types/required-checkout-data.type.d.ts +2 -2
  45. package/lib/services/types/required-checkout-subscription-data.type.d.ts +2 -2
  46. package/package.json +2 -2
  47. package/public-api.d.ts +1 -1
@@ -4,899 +4,896 @@ import * as i1 from '@angular/fire/auth';
4
4
  import { AngularFireAuth } from '@angular/fire/auth';
5
5
  import { of, combineLatest, from, throwError, Subject, iif, forkJoin } from 'rxjs';
6
6
  import { catchError, map, mergeMap, concatMap, tap } from 'rxjs/operators';
7
- import * as i1$1 from '@infrab4a/connect';
8
- import { Where, NotFoundError, FinancialCoupon, CheckoutTypes, Exclusivities, isNil, Checkout, pick, LineItem, CouponTypes, CouponSubtypes, CheckoutSubscription, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository } from '@infrab4a/connect';
7
+ import * as i2 from '@infrab4a/connect';
8
+ import { FinancialCoupon, Where, NotFoundError, Exclusivities, isNil, Checkout, CheckoutTypes, pick, LineItem, CouponTypes, CouponSubtypes, CheckoutSubscription, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository } from '@infrab4a/connect';
9
9
  import { __awaiter } from 'tslib';
10
10
  import cookie from 'js-cookie';
11
- import * as i1$2 from '@angular/fire/firestore';
11
+ import * as i1$1 from '@angular/fire/firestore';
12
12
  import { AngularFirestore } from '@angular/fire/firestore';
13
13
  import { FIREBASE_OPTIONS, FIREBASE_APP_NAME, AngularFireModule } from '@angular/fire';
14
14
 
15
- class AuthService {
16
- constructor(angularFireAuth, userRepository) {
17
- this.angularFireAuth = angularFireAuth;
18
- this.userRepository = userRepository;
19
- }
20
- getAuthstate() {
21
- const observables = [
22
- this.angularFireAuth.authState.pipe(catchError(() => of(null))),
23
- this.getUser().pipe(catchError(() => of(null))),
24
- ];
25
- return combineLatest(observables).pipe(map(([fireUser, user]) => {
26
- return {
27
- user,
28
- isAnonymous: fireUser === null || fireUser === void 0 ? void 0 : fireUser.isAnonymous,
29
- };
30
- }));
31
- }
32
- getUser() {
33
- return this.getFireUser().pipe(map((user) => user === null || user === void 0 ? void 0 : user.uid), mergeMap((id) => (id ? this.userRepository.get({ id }) : of(null))));
34
- }
35
- getTokenId() {
36
- return this.angularFireAuth.idToken;
37
- }
38
- getFireUser() {
39
- return this.angularFireAuth.user.pipe(catchError(() => of(null)));
40
- }
41
- }
42
- 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 });
43
- AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService });
44
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, decorators: [{
45
- type: Injectable
46
- }], ctorParameters: function () { return [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
47
- type: Inject,
48
- args: ['UserRepository']
15
+ class AuthService {
16
+ constructor(angularFireAuth, userRepository) {
17
+ this.angularFireAuth = angularFireAuth;
18
+ this.userRepository = userRepository;
19
+ }
20
+ getAuthstate() {
21
+ const observables = [
22
+ this.angularFireAuth.authState.pipe(catchError(() => of(null))),
23
+ this.getUser().pipe(catchError(() => of(null))),
24
+ ];
25
+ return combineLatest(observables).pipe(map(([fireUser, user]) => {
26
+ return {
27
+ user,
28
+ isAnonymous: fireUser === null || fireUser === void 0 ? void 0 : fireUser.isAnonymous,
29
+ };
30
+ }));
31
+ }
32
+ getUser() {
33
+ return this.getFireUser().pipe(map((user) => user === null || user === void 0 ? void 0 : user.uid), mergeMap((id) => (id ? this.userRepository.get({ id }) : of(null))));
34
+ }
35
+ getTokenId() {
36
+ return this.angularFireAuth.idToken;
37
+ }
38
+ getFireUser() {
39
+ return this.angularFireAuth.user.pipe(catchError(() => of(null)));
40
+ }
41
+ }
42
+ 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 });
43
+ AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService });
44
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, decorators: [{
45
+ type: Injectable
46
+ }], ctorParameters: function () { return [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
47
+ type: Inject,
48
+ args: ['UserRepository']
49
49
  }] }]; } });
50
50
 
51
51
  const DEFAULT_SHOP = 'DEFAULT_SHOP';
52
52
 
53
- class InvalidCouponError extends Error {
54
- constructor(message) {
55
- super(message);
56
- this.message = message;
57
- }
53
+ class InvalidCouponError extends Error {
54
+ constructor(message) {
55
+ super(message);
56
+ this.message = message;
57
+ }
58
58
  }
59
59
 
60
- class CouponService {
61
- constructor(couponRepository, defaultShop) {
62
- this.couponRepository = couponRepository;
63
- this.defaultShop = defaultShop;
64
- this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
65
- }
66
- checkCoupon(nickname, userEmail) {
67
- return from(this.couponRepository.find([
68
- {
69
- nickname: { operator: Where.EQUALS, value: nickname },
70
- shopAvailability: { operator: Where.EQUALS, value: this.defaultShop },
71
- },
72
- ])).pipe(concatMap((coupons) => coupons.count < 1 ? throwError(() => new NotFoundError('Coupon not found')) : of(coupons.data[0])), concatMap((coupon) => FinancialCoupon.isFinancialCoupon(coupon) && this.isValidCoupon(coupon, userEmail)
73
- ? of(coupon)
74
- : throwError(() => new InvalidCouponError('Coupon is not valid'))));
75
- }
76
- isValidCoupon(coupon, userEmail) {
77
- if (coupon.checkoutType !== CheckoutTypes.ECOMMERCE)
78
- throw new InvalidCouponError('Coupon is not ecommerce valid');
79
- if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
80
- throw new InvalidCouponError('User is not a collaborator');
81
- if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.recipient !== userEmail)
82
- throw new InvalidCouponError('Coupon is not valid for user');
83
- if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
84
- throw new InvalidCouponError('Coupon is expired');
85
- return true;
86
- }
87
- }
88
- CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
89
- CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
90
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, decorators: [{
91
- type: Injectable,
92
- args: [{
93
- providedIn: 'root',
94
- }]
95
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
96
- type: Inject,
97
- args: ['CouponRepository']
98
- }] }, { type: i1$1.Shops, decorators: [{
99
- type: Inject,
100
- args: [DEFAULT_SHOP]
101
- }] }]; } });
60
+ class GroupInvalidCouponError extends Error {
61
+ constructor(errors) {
62
+ super('Many coupon errors throw');
63
+ this.errors = errors;
64
+ }
65
+ }
102
66
 
103
- class CheckoutService {
104
- constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
105
- this.couponService = couponService;
106
- this.checkoutRepository = checkoutRepository;
107
- this.orderRepository = orderRepository;
108
- this.userRepository = userRepository;
109
- this.defaultShop = defaultShop;
110
- }
111
- getCheckout(checkoutData) {
112
- const checkoutId = cookie.get('checkoutId');
113
- if (!isNil(checkoutId))
114
- return from(this.checkoutRepository.get({ id: checkoutId }));
115
- return from(this.createCheckout(checkoutData));
116
- }
117
- getUserByCheckout(checkoutId) {
118
- 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'))));
119
- }
120
- updateCheckoutLineItems(checkout) {
121
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
122
- }
123
- updateCheckoutUser(checkout) {
124
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
125
- }
126
- clearCheckoutFromSession() {
127
- cookie.remove('checkoutId');
128
- return of();
129
- }
130
- checkCoupon(nickname) {
131
- return this.getCheckout().pipe(concatMap((checkout) => {
132
- var _a;
133
- return this.couponService.checkCoupon(nickname, (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.email).pipe(concatMap((coupon) => {
134
- var _a, _b;
135
- return !!((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.email)
136
- ? from(this.orderRepository.find([{ user: { email: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email }, coupon: { id: coupon.id } }])).pipe(concatMap((orders) => {
137
- if (orders.data.length >= (coupon.useLimit || Infinity))
138
- return throwError(() => new Error('Coupon is already applied'));
139
- return of(coupon);
140
- }))
141
- : of(coupon);
142
- }));
143
- }));
144
- }
145
- createCheckout(checkoutData) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- 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 }));
148
- cookie.set('checkoutId', checkout.id);
149
- return checkout;
150
- });
151
- }
152
- }
153
- 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 });
154
- CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService });
155
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, decorators: [{
156
- type: Injectable
157
- }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
158
- type: Inject,
159
- args: ['CheckoutRepository']
160
- }] }, { type: undefined, decorators: [{
161
- type: Inject,
162
- args: ['OrderRepository']
163
- }] }, { type: undefined, decorators: [{
164
- type: Inject,
165
- args: ['UserRepository']
166
- }] }, { type: i1$1.Shops, decorators: [{
167
- type: Inject,
168
- args: [DEFAULT_SHOP]
67
+ class CouponService {
68
+ constructor(couponRepository, defaultShop) {
69
+ this.couponRepository = couponRepository;
70
+ this.defaultShop = defaultShop;
71
+ this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
72
+ this.separateValidCoupons = (coupons, userEmail) => coupons
73
+ .map((coupon) => {
74
+ try {
75
+ if (!FinancialCoupon.isFinancialCoupon(coupon))
76
+ throw new InvalidCouponError('Coupon is not valid');
77
+ if (this.isValidCoupon(coupon, userEmail))
78
+ return coupon;
79
+ }
80
+ catch (error) {
81
+ return error;
82
+ }
83
+ })
84
+ .reduce((current, coupon) => (Object.assign(Object.assign({}, current), (FinancialCoupon.isFinancialCoupon(coupon)
85
+ ? { valids: [...current.valids, coupon] }
86
+ : { invalids: [...current.invalids, coupon] }))), {
87
+ valids: [],
88
+ invalids: [],
89
+ });
90
+ }
91
+ checkCoupon(nickname, userEmail, checkoutType) {
92
+ return from(this.couponRepository.find([
93
+ {
94
+ nickname: { operator: Where.EQUALS, value: nickname },
95
+ shopAvailability: { operator: Where.EQUALS, value: this.defaultShop },
96
+ checkoutType: { operator: Where.EQUALS, value: checkoutType },
97
+ },
98
+ ])).pipe(concatMap((coupons) => coupons.count < 1 ? throwError(() => new NotFoundError('Coupon not found')) : of(coupons.data)), map((coupons) => this.separateValidCoupons(coupons, userEmail)), map(({ valids, invalids }) => {
99
+ if (!valids.length)
100
+ throw new GroupInvalidCouponError(invalids);
101
+ return valids;
102
+ }));
103
+ }
104
+ isValidCoupon(coupon, userEmail) {
105
+ if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
106
+ throw new InvalidCouponError('User is not a collaborator');
107
+ if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.recipient !== userEmail)
108
+ throw new InvalidCouponError('Coupon is not valid for user');
109
+ if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
110
+ throw new InvalidCouponError('Coupon is expired');
111
+ return true;
112
+ }
113
+ }
114
+ CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
115
+ CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
116
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, decorators: [{
117
+ type: Injectable,
118
+ args: [{
119
+ providedIn: 'root',
120
+ }]
121
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
122
+ type: Inject,
123
+ args: ['CouponRepository']
124
+ }] }, { type: i2.Shops, decorators: [{
125
+ type: Inject,
126
+ args: [DEFAULT_SHOP]
169
127
  }] }]; } });
170
128
 
171
- class CartService {
172
- constructor(authService, checkoutService, defaultShop) {
173
- this.authService = authService;
174
- this.checkoutService = checkoutService;
175
- this.defaultShop = defaultShop;
176
- this.cartSubject = new Subject();
177
- this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
178
- var _a;
179
- const items = [];
180
- const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.sku).indexOf(lineItem.sku);
181
- if (index > -1) {
182
- checkoutLoaded.lineItems[index].quantity += quantity;
183
- checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
184
- }
185
- else
186
- checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
187
- return this.checkoutService
188
- .updateCheckoutLineItems(checkoutLoaded)
189
- .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
190
- }));
191
- this.generateCartObject = (items) => {
192
- const cart = {};
193
- items === null || items === void 0 ? void 0 : items.forEach((item) => {
194
- var _a;
195
- return (cart[item.sku] = LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.sku] || item)), { quantity: (((_a = cart[item.sku]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })));
196
- });
197
- return cart;
198
- };
199
- this.buildLineItem = ({ checkout, item, quantity, }) => {
200
- var _a, _b, _c, _d, _e;
201
- 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.sku === item.sku)) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
202
- if (this.checkMaxStock(item, quantity || 0))
203
- throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
204
- const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
205
- const { id, name, brand, slug, stock, price, weight, categories, sku } = item;
206
- const isGift = item.isGift || null;
207
- const pricePaid = this.getProductPrice({
208
- product: item,
209
- shop: checkout.shop || this.defaultShop,
210
- isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
211
- });
212
- return LineItem.toInstance({
213
- id,
214
- name,
215
- brand,
216
- slug,
217
- sku,
218
- stock,
219
- price,
220
- image,
221
- weight,
222
- quantity: (item.quantity || 0) + (quantity || 0),
223
- pricePaid,
224
- categories,
225
- isGift,
226
- costPrice: item === null || item === void 0 ? void 0 : item.costPrice,
227
- });
228
- };
229
- this.getProductPrice = ({ product, shop, isSubscriber, }) => {
230
- const info = product.getInfoByShop(shop);
231
- if (product.isGift)
232
- return 0;
233
- return isSubscriber && info.subscriberPrice > 0 ? info.subscriberPrice : info.price;
234
- };
235
- this.checkMaxStock = (item, quantity) => {
236
- var _a;
237
- const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
238
- const currentItemAmount = item.quantity || 0;
239
- return currentItemAmount + quantity > maxStock;
240
- };
241
- }
242
- addItem(item, quantity = 1) {
243
- return this.checkoutService.getCheckout().pipe(map((checkout) => ({
244
- checkout,
245
- lineItem: this.buildLineItem({ checkout, item, quantity: quantity || 1 }),
246
- })), concatMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
247
- }
248
- decreaseItem(item) {
249
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
250
- var _a;
251
- const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.sku === item.sku);
252
- if (!isNil(checkoutItem))
253
- checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
254
- return checkout;
255
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
256
- }
257
- getCart(checkout) {
258
- this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
259
- return this.cartSubject;
260
- }
261
- /**
262
- * @deprecated The method should not be used
263
- */
264
- getDiscount(coupon) {
265
- switch (coupon.type) {
266
- case CouponTypes.FINANCIAL:
267
- return this.getFinancialDiscount(coupon);
268
- case CouponTypes.PRODUCT:
269
- return (subTotalPrice) => subTotalPrice;
270
- case CouponTypes.GIFTCARD:
271
- return this.getFinancialDiscount(coupon);
272
- case CouponTypes.VOUCHER:
273
- return (subTotalPrice) => subTotalPrice;
274
- }
275
- }
276
- /**
277
- * @deprecated The method should not be used
278
- */
279
- getVariantPriceDiscount(item, shop) {
280
- return this.authService.getUser().pipe(concatMap((user) => iif(() => user.isSubscriber && !!item.getInfoByShop(shop).subscriberPrice, of(item.getInfoByShop(shop).subscriberPrice), of(item.getInfoByShop(shop).price))), catchError(() => of(item.getInfoByShop(shop).price)));
281
- }
282
- removeItem(item) {
283
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
284
- const index = checkout.lineItems.findIndex((lineItem) => lineItem.sku === item.sku);
285
- if (index >= 0)
286
- checkout.lineItems.splice(index, 1);
287
- return checkout;
288
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
289
- }
290
- updateUserCart(user) {
291
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => {
292
- var _a;
293
- return this.checkoutService.updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.map((item) => this.buildLineItem({ checkout, item }))) || [] })));
294
- }), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
295
- }
296
- clearCart() {
297
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
298
- this.checkoutService.clearCheckoutFromSession();
299
- return checkout;
300
- }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
301
- }
302
- buildCartFromCheckout(checkoutData) {
303
- return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
304
- }
305
- getFinancialDiscount(coupon) {
306
- return (subTotalPrice) => {
307
- if (FinancialCoupon.isFinancialCoupon(coupon))
308
- switch (coupon.subtype) {
309
- case CouponSubtypes.ABSOLUTE:
310
- return subTotalPrice - coupon.discount * 100;
311
- case CouponSubtypes.PERCENTAGE:
312
- return subTotalPrice * (1 - coupon.discount / 100);
313
- }
314
- };
315
- }
316
- }
317
- CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
318
- CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
319
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
320
- type: Injectable
321
- }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$1.Shops, decorators: [{
322
- type: Inject,
323
- args: [DEFAULT_SHOP]
129
+ class CheckoutService {
130
+ constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
131
+ this.couponService = couponService;
132
+ this.checkoutRepository = checkoutRepository;
133
+ this.orderRepository = orderRepository;
134
+ this.userRepository = userRepository;
135
+ this.defaultShop = defaultShop;
136
+ }
137
+ getCheckout(checkoutData) {
138
+ const checkoutId = cookie.get('checkoutId');
139
+ if (!isNil(checkoutId))
140
+ return from(this.checkoutRepository.get({ id: checkoutId }));
141
+ return from(this.createCheckout(checkoutData));
142
+ }
143
+ getUserByCheckout(checkoutId) {
144
+ 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'))));
145
+ }
146
+ updateCheckoutLineItems(checkout) {
147
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
148
+ }
149
+ updateCheckoutUser(checkout) {
150
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
151
+ }
152
+ clearCheckoutFromSession() {
153
+ cookie.remove('checkoutId');
154
+ return of();
155
+ }
156
+ checkCoupon(nickname) {
157
+ return this.getCheckout().pipe(concatMap((checkout) => {
158
+ var _a;
159
+ return this.couponService.checkCoupon(nickname, (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.email, CheckoutTypes.ECOMMERCE).pipe(concatMap((coupons) => of(coupons.shift())), concatMap((coupon) => {
160
+ var _a, _b;
161
+ return !!((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.email)
162
+ ? from(this.orderRepository.find([{ user: { email: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email }, coupon: { id: coupon.id } }])).pipe(concatMap((orders) => {
163
+ if (orders.data.length >= (coupon.useLimit || Infinity))
164
+ return throwError(() => new Error('Coupon is already applied'));
165
+ return of(coupon);
166
+ }))
167
+ : of(coupon);
168
+ }));
169
+ }));
170
+ }
171
+ createCheckout(checkoutData) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ 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 }));
174
+ cookie.set('checkoutId', checkout.id);
175
+ return checkout;
176
+ });
177
+ }
178
+ }
179
+ 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 });
180
+ CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService });
181
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, decorators: [{
182
+ type: Injectable
183
+ }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
184
+ type: Inject,
185
+ args: ['CheckoutRepository']
186
+ }] }, { type: undefined, decorators: [{
187
+ type: Inject,
188
+ args: ['OrderRepository']
189
+ }] }, { type: undefined, decorators: [{
190
+ type: Inject,
191
+ args: ['UserRepository']
192
+ }] }, { type: i2.Shops, decorators: [{
193
+ type: Inject,
194
+ args: [DEFAULT_SHOP]
324
195
  }] }]; } });
325
196
 
326
- class CheckoutSubscriptionService {
327
- constructor(checkoutSubscriptionRepository, couponRepository, subscriptionRepository, defaultShop) {
328
- this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
329
- this.couponRepository = couponRepository;
330
- this.subscriptionRepository = subscriptionRepository;
331
- this.defaultShop = defaultShop;
332
- this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
333
- }
334
- getCheckoutSubscription(checkoutData) {
335
- const checkoutId = cookie.get('checkoutSubscriptionId');
336
- if (!isNil(checkoutId))
337
- return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
338
- return from(this.createCheckoutSubscription(checkoutData));
339
- }
340
- createCheckoutSubscription(checkoutData) {
341
- return __awaiter(this, void 0, void 0, function* () {
342
- const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
343
- cookie.set('checkoutSubscriptionId', checkout.id);
344
- return checkout;
345
- });
346
- }
347
- clearCheckoutSubscriptionFromSession() {
348
- cookie.remove('checkoutSubscriptionId');
349
- return of();
350
- }
351
- checkCoupon(nickname, userEmail) {
352
- return forkJoin([
353
- this.couponRepository.find([
354
- {
355
- nickname: { operator: Where.EQUALS, value: nickname },
356
- shopAvailability: { operator: Where.EQUALS, value: this.defaultShop },
357
- },
358
- ]),
359
- this.subscriptionRepository.find([
360
- {
361
- coupon: {
362
- nickname: {
363
- operator: Where.EQUALS, value: nickname
364
- }
365
- }
366
- }
367
- ])
368
- ]).pipe(concatMap((results) => {
369
- const [coupons, subscriptions] = results;
370
- if (coupons.count < 1) {
371
- return throwError(() => new NotFoundError('Coupon not found'));
372
- }
373
- else if (coupons.data[0].useLimit && subscriptions.count >= coupons.data[0].useLimit) {
374
- return throwError(() => new NotFoundError('Coupon not found'));
375
- }
376
- return of(coupons.data[0]);
377
- }), concatMap((coupon) => FinancialCoupon.isFinancialCoupon(coupon) && this.isValidCoupon(coupon, userEmail)
378
- ? of(coupon)
379
- : throwError(() => new InvalidCouponError('Coupon is not valid'))));
380
- }
381
- isValidCoupon(coupon, userEmail) {
382
- if (+coupon.checkoutType !== CheckoutTypes.SUBSCRIPTION)
383
- throw new InvalidCouponError('Coupon is not subscription valid');
384
- if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
385
- throw new InvalidCouponError('User is not a collaborator');
386
- if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.recipient !== userEmail)
387
- throw new InvalidCouponError('Coupon is not valid for user');
388
- if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
389
- throw new InvalidCouponError('Coupon is expired');
390
- return true;
391
- }
392
- }
393
- CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: 'CouponRepository' }, { token: 'SubscriptionRepository' }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
394
- CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService });
395
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
396
- type: Injectable
397
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
398
- type: Inject,
399
- args: ['CheckoutSubscriptionRepository']
400
- }] }, { type: undefined, decorators: [{
401
- type: Inject,
402
- args: ['CouponRepository']
403
- }] }, { type: undefined, decorators: [{
404
- type: Inject,
405
- args: ['SubscriptionRepository']
406
- }] }, { type: i1$1.Shops, decorators: [{
407
- type: Inject,
408
- args: [DEFAULT_SHOP]
197
+ class CartService {
198
+ constructor(authService, checkoutService, defaultShop) {
199
+ this.authService = authService;
200
+ this.checkoutService = checkoutService;
201
+ this.defaultShop = defaultShop;
202
+ this.cartSubject = new Subject();
203
+ this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
204
+ var _a;
205
+ const items = [];
206
+ const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.sku).indexOf(lineItem.sku);
207
+ if (index > -1) {
208
+ checkoutLoaded.lineItems[index].quantity += quantity;
209
+ checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
210
+ }
211
+ else
212
+ checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
213
+ return this.checkoutService
214
+ .updateCheckoutLineItems(checkoutLoaded)
215
+ .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
216
+ }));
217
+ this.generateCartObject = (items) => {
218
+ const cart = {};
219
+ items === null || items === void 0 ? void 0 : items.forEach((item) => {
220
+ var _a;
221
+ return (cart[item.sku] = LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.sku] || item)), { quantity: (((_a = cart[item.sku]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })));
222
+ });
223
+ return cart;
224
+ };
225
+ this.buildLineItem = ({ checkout, item, quantity, }) => {
226
+ var _a, _b, _c, _d, _e;
227
+ 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.sku === item.sku)) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
228
+ if (this.checkMaxStock(item, quantity || 0))
229
+ throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
230
+ const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
231
+ const { id, name, brand, slug, stock, price, weight, categories, sku } = item;
232
+ const isGift = item.isGift || null;
233
+ const pricePaid = this.getProductPrice({
234
+ product: item,
235
+ shop: checkout.shop || this.defaultShop,
236
+ isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
237
+ });
238
+ return LineItem.toInstance({
239
+ id,
240
+ name,
241
+ brand,
242
+ slug,
243
+ sku,
244
+ stock,
245
+ price,
246
+ image,
247
+ weight,
248
+ quantity: (item.quantity || 0) + (quantity || 0),
249
+ pricePaid,
250
+ categories,
251
+ isGift,
252
+ costPrice: item === null || item === void 0 ? void 0 : item.costPrice,
253
+ });
254
+ };
255
+ this.getProductPrice = ({ product, shop, isSubscriber, }) => {
256
+ const info = product.getInfoByShop(shop);
257
+ if (product.isGift)
258
+ return 0;
259
+ return isSubscriber && info.subscriberPrice > 0 ? info.subscriberPrice : info.price;
260
+ };
261
+ this.checkMaxStock = (item, quantity) => {
262
+ var _a;
263
+ const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
264
+ const currentItemAmount = item.quantity || 0;
265
+ return currentItemAmount + quantity > maxStock;
266
+ };
267
+ }
268
+ addItem(item, quantity = 1) {
269
+ return this.checkoutService.getCheckout().pipe(map((checkout) => ({
270
+ checkout,
271
+ lineItem: this.buildLineItem({ checkout, item, quantity: quantity || 1 }),
272
+ })), concatMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
273
+ }
274
+ decreaseItem(item) {
275
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
276
+ var _a;
277
+ const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.sku === item.sku);
278
+ if (!isNil(checkoutItem))
279
+ checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
280
+ return checkout;
281
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
282
+ }
283
+ getCart(checkout) {
284
+ this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
285
+ return this.cartSubject;
286
+ }
287
+ /**
288
+ * @deprecated The method should not be used
289
+ */
290
+ getDiscount(coupon) {
291
+ switch (coupon.type) {
292
+ case CouponTypes.FINANCIAL:
293
+ return this.getFinancialDiscount(coupon);
294
+ case CouponTypes.PRODUCT:
295
+ return (subTotalPrice) => subTotalPrice;
296
+ case CouponTypes.GIFTCARD:
297
+ return this.getFinancialDiscount(coupon);
298
+ case CouponTypes.VOUCHER:
299
+ return (subTotalPrice) => subTotalPrice;
300
+ }
301
+ }
302
+ /**
303
+ * @deprecated The method should not be used
304
+ */
305
+ getVariantPriceDiscount(item, shop) {
306
+ return this.authService.getUser().pipe(concatMap((user) => iif(() => user.isSubscriber && !!item.getInfoByShop(shop).subscriberPrice, of(item.getInfoByShop(shop).subscriberPrice), of(item.getInfoByShop(shop).price))), catchError(() => of(item.getInfoByShop(shop).price)));
307
+ }
308
+ removeItem(item) {
309
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
310
+ const index = checkout.lineItems.findIndex((lineItem) => lineItem.sku === item.sku);
311
+ if (index >= 0)
312
+ checkout.lineItems.splice(index, 1);
313
+ return checkout;
314
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
315
+ }
316
+ updateUserCart(user) {
317
+ return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => {
318
+ var _a;
319
+ return this.checkoutService.updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.map((item) => this.buildLineItem({ checkout, item }))) || [] })));
320
+ }), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
321
+ }
322
+ clearCart() {
323
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
324
+ this.checkoutService.clearCheckoutFromSession();
325
+ return checkout;
326
+ }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
327
+ }
328
+ buildCartFromCheckout(checkoutData) {
329
+ return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
330
+ }
331
+ getFinancialDiscount(coupon) {
332
+ return (subTotalPrice) => {
333
+ if (FinancialCoupon.isFinancialCoupon(coupon))
334
+ switch (coupon.subtype) {
335
+ case CouponSubtypes.ABSOLUTE:
336
+ return subTotalPrice - coupon.discount * 100;
337
+ case CouponSubtypes.PERCENTAGE:
338
+ return subTotalPrice * (1 - coupon.discount / 100);
339
+ }
340
+ };
341
+ }
342
+ }
343
+ CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }], target: i0.ɵɵFactoryTarget.Injectable });
344
+ CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
345
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
346
+ type: Injectable
347
+ }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i2.Shops, decorators: [{
348
+ type: Inject,
349
+ args: [DEFAULT_SHOP]
409
350
  }] }]; } });
410
351
 
411
- class OrderService {
412
- constructor(angularFirestore, orderRepository) {
413
- this.angularFirestore = angularFirestore;
414
- this.orderRepository = orderRepository;
415
- this.orderSubject = new Subject();
416
- }
417
- getOrder(id) {
418
- this.angularFirestore
419
- .doc(`${this.orderRepository.collectionName}/${id}`)
420
- .valueChanges()
421
- .pipe(map((doc) => Order.toInstance(doc)))
422
- .subscribe((doc) => this.orderSubject.next(doc));
423
- return this.orderSubject;
424
- }
425
- }
426
- OrderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, deps: [{ token: i1$2.AngularFirestore }, { token: 'OrderRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
427
- OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
428
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
429
- type: Injectable
430
- }], ctorParameters: function () { return [{ type: i1$2.AngularFirestore }, { type: i1$1.OrderFirestoreRepository, decorators: [{
431
- type: Inject,
432
- args: ['OrderRepository']
352
+ class CheckoutSubscriptionService {
353
+ constructor(checkoutSubscriptionRepository, couponService) {
354
+ this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
355
+ this.couponService = couponService;
356
+ this.checkCouponsWithCheckout = (coupons, checkout) => forkJoin(coupons.map((coupon) => {
357
+ var _a;
358
+ return from(this.checkoutSubscriptionRepository.find([
359
+ { user: { email: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.email }, coupon: { id: coupon.id } },
360
+ ])).pipe(map((subscriptions) => ({ coupon, subscriptions })));
361
+ })).pipe(map((results) => results.map(({ coupon, subscriptions }) => {
362
+ if (subscriptions.data.length >= (coupon.useLimit || Infinity))
363
+ return new InvalidCouponError('Coupon is already applied');
364
+ return coupon;
365
+ })), map((validatedCoupons) => ({
366
+ valids: validatedCoupons.filter((coupon) => FinancialCoupon.isFinancialCoupon(coupon)),
367
+ invalids: validatedCoupons.filter((coupon) => coupon instanceof InvalidCouponError),
368
+ })), concatMap(({ valids, invalids }) => valids.length ? of(valids) : throwError(new GroupInvalidCouponError(invalids))));
369
+ }
370
+ getCheckoutSubscription(checkoutData) {
371
+ const checkoutId = cookie.get('checkoutSubscriptionId');
372
+ if (!isNil(checkoutId))
373
+ return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
374
+ return from(this.createCheckoutSubscription(checkoutData));
375
+ }
376
+ createCheckoutSubscription(checkoutData) {
377
+ return __awaiter(this, void 0, void 0, function* () {
378
+ const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
379
+ cookie.set('checkoutSubscriptionId', checkout.id);
380
+ return checkout;
381
+ });
382
+ }
383
+ clearCheckoutSubscriptionFromSession() {
384
+ cookie.remove('checkoutSubscriptionId');
385
+ return of();
386
+ }
387
+ checkCoupon(nickname, userEmail) {
388
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION).pipe(concatMap((coupons) => {
389
+ const couponsWithSamePlan = coupons.filter((coupon) => checkout.subscriptionPlan.name === coupon.plan);
390
+ const couponsWithNoPlan = coupons.filter((coupon) => !coupon.plan);
391
+ if (couponsWithSamePlan.length > 0)
392
+ return of(couponsWithSamePlan);
393
+ if (couponsWithNoPlan.length > 0)
394
+ return of(couponsWithNoPlan);
395
+ throw new Error(`Coupon subscription plan is invalid.`);
396
+ }), concatMap((coupons) => { var _a; return !!((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.email) ? this.checkCouponsWithCheckout(coupons, checkout) : of(coupons); }), map((validatedCoupons) => validatedCoupons.shift()))));
397
+ }
398
+ }
399
+ CheckoutSubscriptionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, deps: [{ token: 'CheckoutSubscriptionRepository' }, { token: CouponService }], target: i0.ɵɵFactoryTarget.Injectable });
400
+ CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService });
401
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
402
+ type: Injectable
403
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
404
+ type: Inject,
405
+ args: ['CheckoutSubscriptionRepository']
406
+ }] }, { type: CouponService }]; } });
407
+
408
+ class OrderService {
409
+ constructor(angularFirestore, orderRepository) {
410
+ this.angularFirestore = angularFirestore;
411
+ this.orderRepository = orderRepository;
412
+ this.orderSubject = new Subject();
413
+ }
414
+ getOrder(id) {
415
+ this.angularFirestore
416
+ .doc(`${this.orderRepository.collectionName}/${id}`)
417
+ .valueChanges()
418
+ .pipe(map((doc) => Order.toInstance(doc)))
419
+ .subscribe((doc) => this.orderSubject.next(doc));
420
+ return this.orderSubject;
421
+ }
422
+ }
423
+ 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 });
424
+ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
425
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
426
+ type: Injectable
427
+ }], ctorParameters: function () { return [{ type: i1$1.AngularFirestore }, { type: i2.OrderFirestoreRepository, decorators: [{
428
+ type: Inject,
429
+ args: ['OrderRepository']
433
430
  }] }]; } });
434
431
 
435
- class AngularFirebaseAuthModule {
436
- static initializeApp(options, nameOrConfig) {
437
- return {
438
- ngModule: AngularFirebaseAuthModule,
439
- providers: [
440
- { provide: FIREBASE_OPTIONS, useValue: options },
441
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
442
- ],
443
- };
444
- }
445
- }
446
- AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
447
- AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
448
- AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
449
- {
450
- provide: 'Authentication',
451
- useFactory: (authenticationService, userRepository) => {
452
- return new Authentication(authenticationService, userRepository);
453
- },
454
- deps: ['AuthenticationService', 'UserRepository'],
455
- },
456
- {
457
- provide: 'AuthenticationService',
458
- useFactory: (angularFireAuth) => {
459
- return new AuthenticationFirebaseAuthService(angularFireAuth);
460
- },
461
- deps: [AngularFireAuth],
462
- },
463
- {
464
- provide: 'Register',
465
- useFactory: (registerService, userRepository) => {
466
- return new Register(registerService, userRepository);
467
- },
468
- deps: ['RegisterService', 'UserRepository'],
469
- },
470
- {
471
- provide: 'RegisterService',
472
- useFactory: (angularFireAuth) => {
473
- return new RegisterFirebaseAuthService(angularFireAuth);
474
- },
475
- deps: [AngularFireAuth],
476
- },
477
- {
478
- provide: 'SignOut',
479
- useFactory: (authenticationService) => {
480
- return new SignOut(authenticationService);
481
- },
482
- deps: ['AuthenticationService'],
483
- },
484
- {
485
- provide: 'RecoveryPassword',
486
- useFactory: (authenticationService) => {
487
- return new RecoveryPassword(authenticationService);
488
- },
489
- deps: ['AuthenticationService'],
490
- },
491
- ], imports: [[AngularFireModule]] });
492
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
493
- type: NgModule,
494
- args: [{
495
- imports: [AngularFireModule],
496
- providers: [
497
- {
498
- provide: 'Authentication',
499
- useFactory: (authenticationService, userRepository) => {
500
- return new Authentication(authenticationService, userRepository);
501
- },
502
- deps: ['AuthenticationService', 'UserRepository'],
503
- },
504
- {
505
- provide: 'AuthenticationService',
506
- useFactory: (angularFireAuth) => {
507
- return new AuthenticationFirebaseAuthService(angularFireAuth);
508
- },
509
- deps: [AngularFireAuth],
510
- },
511
- {
512
- provide: 'Register',
513
- useFactory: (registerService, userRepository) => {
514
- return new Register(registerService, userRepository);
515
- },
516
- deps: ['RegisterService', 'UserRepository'],
517
- },
518
- {
519
- provide: 'RegisterService',
520
- useFactory: (angularFireAuth) => {
521
- return new RegisterFirebaseAuthService(angularFireAuth);
522
- },
523
- deps: [AngularFireAuth],
524
- },
525
- {
526
- provide: 'SignOut',
527
- useFactory: (authenticationService) => {
528
- return new SignOut(authenticationService);
529
- },
530
- deps: ['AuthenticationService'],
531
- },
532
- {
533
- provide: 'RecoveryPassword',
534
- useFactory: (authenticationService) => {
535
- return new RecoveryPassword(authenticationService);
536
- },
537
- deps: ['AuthenticationService'],
538
- },
539
- ],
540
- }]
432
+ class AngularFirebaseAuthModule {
433
+ static initializeApp(options, nameOrConfig) {
434
+ return {
435
+ ngModule: AngularFirebaseAuthModule,
436
+ providers: [
437
+ { provide: FIREBASE_OPTIONS, useValue: options },
438
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
439
+ ],
440
+ };
441
+ }
442
+ }
443
+ AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
444
+ AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
445
+ AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
446
+ {
447
+ provide: 'Authentication',
448
+ useFactory: (authenticationService, userRepository) => {
449
+ return new Authentication(authenticationService, userRepository);
450
+ },
451
+ deps: ['AuthenticationService', 'UserRepository'],
452
+ },
453
+ {
454
+ provide: 'AuthenticationService',
455
+ useFactory: (angularFireAuth) => {
456
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
457
+ },
458
+ deps: [AngularFireAuth],
459
+ },
460
+ {
461
+ provide: 'Register',
462
+ useFactory: (registerService, userRepository) => {
463
+ return new Register(registerService, userRepository);
464
+ },
465
+ deps: ['RegisterService', 'UserRepository'],
466
+ },
467
+ {
468
+ provide: 'RegisterService',
469
+ useFactory: (angularFireAuth) => {
470
+ return new RegisterFirebaseAuthService(angularFireAuth);
471
+ },
472
+ deps: [AngularFireAuth],
473
+ },
474
+ {
475
+ provide: 'SignOut',
476
+ useFactory: (authenticationService) => {
477
+ return new SignOut(authenticationService);
478
+ },
479
+ deps: ['AuthenticationService'],
480
+ },
481
+ {
482
+ provide: 'RecoveryPassword',
483
+ useFactory: (authenticationService) => {
484
+ return new RecoveryPassword(authenticationService);
485
+ },
486
+ deps: ['AuthenticationService'],
487
+ },
488
+ ], imports: [[AngularFireModule]] });
489
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
490
+ type: NgModule,
491
+ args: [{
492
+ imports: [AngularFireModule],
493
+ providers: [
494
+ {
495
+ provide: 'Authentication',
496
+ useFactory: (authenticationService, userRepository) => {
497
+ return new Authentication(authenticationService, userRepository);
498
+ },
499
+ deps: ['AuthenticationService', 'UserRepository'],
500
+ },
501
+ {
502
+ provide: 'AuthenticationService',
503
+ useFactory: (angularFireAuth) => {
504
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
505
+ },
506
+ deps: [AngularFireAuth],
507
+ },
508
+ {
509
+ provide: 'Register',
510
+ useFactory: (registerService, userRepository) => {
511
+ return new Register(registerService, userRepository);
512
+ },
513
+ deps: ['RegisterService', 'UserRepository'],
514
+ },
515
+ {
516
+ provide: 'RegisterService',
517
+ useFactory: (angularFireAuth) => {
518
+ return new RegisterFirebaseAuthService(angularFireAuth);
519
+ },
520
+ deps: [AngularFireAuth],
521
+ },
522
+ {
523
+ provide: 'SignOut',
524
+ useFactory: (authenticationService) => {
525
+ return new SignOut(authenticationService);
526
+ },
527
+ deps: ['AuthenticationService'],
528
+ },
529
+ {
530
+ provide: 'RecoveryPassword',
531
+ useFactory: (authenticationService) => {
532
+ return new RecoveryPassword(authenticationService);
533
+ },
534
+ deps: ['AuthenticationService'],
535
+ },
536
+ ],
537
+ }]
541
538
  }] });
542
539
 
543
- class AngularFirestoreModule {
544
- static initializeApp(options, nameOrConfig) {
545
- return {
546
- ngModule: AngularFirestoreModule,
547
- providers: [
548
- { provide: FIREBASE_OPTIONS, useValue: options },
549
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
550
- ],
551
- };
552
- }
553
- }
554
- AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
555
- AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule] });
556
- AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
557
- {
558
- provide: 'BeautyProfileRepository',
559
- useFactory: (firestore, userRepository) => {
560
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
561
- },
562
- deps: [AngularFirestore, 'UserRepository'],
563
- },
564
- {
565
- provide: 'Buy2WinRepository',
566
- useFactory: (firestore) => {
567
- return new Buy2WinFirestoreRepository(firestore.firestore);
568
- },
569
- deps: [AngularFirestore],
570
- },
571
- {
572
- provide: 'CategoryRepository',
573
- useFactory: (firestore) => {
574
- return new CategoryFirestoreRepository(firestore.firestore);
575
- },
576
- deps: [AngularFirestore],
577
- },
578
- {
579
- provide: 'CheckoutRepository',
580
- useFactory: (firestore) => {
581
- return new CheckoutFirestoreRepository(firestore.firestore);
582
- },
583
- deps: [AngularFirestore],
584
- },
585
- {
586
- provide: 'CheckoutSubscriptionRepository',
587
- useFactory: (firestore) => {
588
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
589
- },
590
- deps: [AngularFirestore],
591
- },
592
- {
593
- provide: 'CouponRepository',
594
- useFactory: (firestore) => {
595
- return new CouponFirestoreRepository(firestore.firestore);
596
- },
597
- deps: [AngularFirestore],
598
- },
599
- {
600
- provide: 'EditionRepository',
601
- useFactory: (firestore, subscriptionRepository) => {
602
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
603
- },
604
- deps: [AngularFirestore, 'SubscriptionRepository'],
605
- },
606
- {
607
- provide: 'HomeRepository',
608
- useFactory: (firestore) => {
609
- return new HomeFirestoreRepository(firestore.firestore);
610
- },
611
- deps: [AngularFirestore],
612
- },
613
- {
614
- provide: 'LeadRepository',
615
- useFactory: (firestore) => {
616
- return new LeadFirestoreRepository(firestore.firestore);
617
- },
618
- deps: [AngularFirestore],
619
- },
620
- {
621
- provide: 'LegacyOrderRepository',
622
- useFactory: (firestore) => {
623
- return new LegacyOrderFirestoreRepository(firestore.firestore);
624
- },
625
- deps: [AngularFirestore],
626
- },
627
- {
628
- provide: 'ShopMenuRepository',
629
- useFactory: (firestore) => {
630
- return new ShopMenuFirestoreRepository(firestore.firestore);
631
- },
632
- deps: [AngularFirestore],
633
- },
634
- {
635
- provide: 'OrderRepository',
636
- useFactory: (firestore) => {
637
- return new OrderFirestoreRepository(firestore.firestore);
638
- },
639
- deps: [AngularFirestore],
640
- },
641
- {
642
- provide: 'PaymentRepository',
643
- useFactory: (firestore) => {
644
- return new PaymentFirestoreRepository(firestore.firestore);
645
- },
646
- deps: [AngularFirestore],
647
- },
648
- {
649
- provide: 'ProductRepository',
650
- useFactory: (firestore) => {
651
- return new ProductFirestoreRepository(firestore.firestore);
652
- },
653
- deps: [AngularFirestore],
654
- },
655
- {
656
- provide: 'SubscriptionPaymentRepository',
657
- useFactory: (firestore, subscriptionRepository) => {
658
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
659
- },
660
- deps: [AngularFirestore, 'SubscriptionRepository'],
661
- },
662
- {
663
- provide: 'SubscriptionPlanRepository',
664
- useFactory: (firestore) => {
665
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
666
- },
667
- deps: [AngularFirestore],
668
- },
669
- {
670
- provide: 'SubscriptionProductRepository',
671
- useFactory: (firestore) => {
672
- return new SubscriptionProductFirestoreRepository(firestore.firestore);
673
- },
674
- deps: [AngularFirestore],
675
- },
676
- {
677
- provide: 'SubscriptionRepository',
678
- useFactory: (firestore) => {
679
- return new SubscriptionFirestoreRepository(firestore.firestore);
680
- },
681
- deps: [AngularFirestore],
682
- },
683
- {
684
- provide: 'UserRepository',
685
- useFactory: (firestore) => {
686
- return new UserFirestoreRepository(firestore.firestore);
687
- },
688
- deps: [AngularFirestore],
689
- },
690
- {
691
- provide: 'UserAddressRepository',
692
- useFactory: (firestore, userRepository) => {
693
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
694
- },
695
- deps: [AngularFirestore, 'UserRepository'],
696
- },
697
- {
698
- provide: 'UserPaymentMethodRepository',
699
- useFactory: (firestore, userRepository) => {
700
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
701
- },
702
- deps: [AngularFirestore, 'UserRepository'],
703
- },
704
- {
705
- provide: 'VariantRepository',
706
- useFactory: (firestore, productRepository) => {
707
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
708
- },
709
- deps: [AngularFirestore, 'ProductRepository'],
710
- },
711
- ], imports: [[AngularFireModule]] });
712
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
713
- type: NgModule,
714
- args: [{
715
- imports: [AngularFireModule],
716
- providers: [
717
- {
718
- provide: 'BeautyProfileRepository',
719
- useFactory: (firestore, userRepository) => {
720
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
721
- },
722
- deps: [AngularFirestore, 'UserRepository'],
723
- },
724
- {
725
- provide: 'Buy2WinRepository',
726
- useFactory: (firestore) => {
727
- return new Buy2WinFirestoreRepository(firestore.firestore);
728
- },
729
- deps: [AngularFirestore],
730
- },
731
- {
732
- provide: 'CategoryRepository',
733
- useFactory: (firestore) => {
734
- return new CategoryFirestoreRepository(firestore.firestore);
735
- },
736
- deps: [AngularFirestore],
737
- },
738
- {
739
- provide: 'CheckoutRepository',
740
- useFactory: (firestore) => {
741
- return new CheckoutFirestoreRepository(firestore.firestore);
742
- },
743
- deps: [AngularFirestore],
744
- },
745
- {
746
- provide: 'CheckoutSubscriptionRepository',
747
- useFactory: (firestore) => {
748
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
749
- },
750
- deps: [AngularFirestore],
751
- },
752
- {
753
- provide: 'CouponRepository',
754
- useFactory: (firestore) => {
755
- return new CouponFirestoreRepository(firestore.firestore);
756
- },
757
- deps: [AngularFirestore],
758
- },
759
- {
760
- provide: 'EditionRepository',
761
- useFactory: (firestore, subscriptionRepository) => {
762
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
763
- },
764
- deps: [AngularFirestore, 'SubscriptionRepository'],
765
- },
766
- {
767
- provide: 'HomeRepository',
768
- useFactory: (firestore) => {
769
- return new HomeFirestoreRepository(firestore.firestore);
770
- },
771
- deps: [AngularFirestore],
772
- },
773
- {
774
- provide: 'LeadRepository',
775
- useFactory: (firestore) => {
776
- return new LeadFirestoreRepository(firestore.firestore);
777
- },
778
- deps: [AngularFirestore],
779
- },
780
- {
781
- provide: 'LegacyOrderRepository',
782
- useFactory: (firestore) => {
783
- return new LegacyOrderFirestoreRepository(firestore.firestore);
784
- },
785
- deps: [AngularFirestore],
786
- },
787
- {
788
- provide: 'ShopMenuRepository',
789
- useFactory: (firestore) => {
790
- return new ShopMenuFirestoreRepository(firestore.firestore);
791
- },
792
- deps: [AngularFirestore],
793
- },
794
- {
795
- provide: 'OrderRepository',
796
- useFactory: (firestore) => {
797
- return new OrderFirestoreRepository(firestore.firestore);
798
- },
799
- deps: [AngularFirestore],
800
- },
801
- {
802
- provide: 'PaymentRepository',
803
- useFactory: (firestore) => {
804
- return new PaymentFirestoreRepository(firestore.firestore);
805
- },
806
- deps: [AngularFirestore],
807
- },
808
- {
809
- provide: 'ProductRepository',
810
- useFactory: (firestore) => {
811
- return new ProductFirestoreRepository(firestore.firestore);
812
- },
813
- deps: [AngularFirestore],
814
- },
815
- {
816
- provide: 'SubscriptionPaymentRepository',
817
- useFactory: (firestore, subscriptionRepository) => {
818
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
819
- },
820
- deps: [AngularFirestore, 'SubscriptionRepository'],
821
- },
822
- {
823
- provide: 'SubscriptionPlanRepository',
824
- useFactory: (firestore) => {
825
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
826
- },
827
- deps: [AngularFirestore],
828
- },
829
- {
830
- provide: 'SubscriptionProductRepository',
831
- useFactory: (firestore) => {
832
- return new SubscriptionProductFirestoreRepository(firestore.firestore);
833
- },
834
- deps: [AngularFirestore],
835
- },
836
- {
837
- provide: 'SubscriptionRepository',
838
- useFactory: (firestore) => {
839
- return new SubscriptionFirestoreRepository(firestore.firestore);
840
- },
841
- deps: [AngularFirestore],
842
- },
843
- {
844
- provide: 'UserRepository',
845
- useFactory: (firestore) => {
846
- return new UserFirestoreRepository(firestore.firestore);
847
- },
848
- deps: [AngularFirestore],
849
- },
850
- {
851
- provide: 'UserAddressRepository',
852
- useFactory: (firestore, userRepository) => {
853
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
854
- },
855
- deps: [AngularFirestore, 'UserRepository'],
856
- },
857
- {
858
- provide: 'UserPaymentMethodRepository',
859
- useFactory: (firestore, userRepository) => {
860
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
861
- },
862
- deps: [AngularFirestore, 'UserRepository'],
863
- },
864
- {
865
- provide: 'VariantRepository',
866
- useFactory: (firestore, productRepository) => {
867
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
868
- },
869
- deps: [AngularFirestore, 'ProductRepository'],
870
- },
871
- ],
872
- }]
540
+ class AngularFirestoreModule {
541
+ static initializeApp(options, nameOrConfig) {
542
+ return {
543
+ ngModule: AngularFirestoreModule,
544
+ providers: [
545
+ { provide: FIREBASE_OPTIONS, useValue: options },
546
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
547
+ ],
548
+ };
549
+ }
550
+ }
551
+ AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
552
+ AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule] });
553
+ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
554
+ {
555
+ provide: 'BeautyProfileRepository',
556
+ useFactory: (firestore, userRepository) => {
557
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
558
+ },
559
+ deps: [AngularFirestore, 'UserRepository'],
560
+ },
561
+ {
562
+ provide: 'Buy2WinRepository',
563
+ useFactory: (firestore) => {
564
+ return new Buy2WinFirestoreRepository(firestore.firestore);
565
+ },
566
+ deps: [AngularFirestore],
567
+ },
568
+ {
569
+ provide: 'CategoryRepository',
570
+ useFactory: (firestore) => {
571
+ return new CategoryFirestoreRepository(firestore.firestore);
572
+ },
573
+ deps: [AngularFirestore],
574
+ },
575
+ {
576
+ provide: 'CheckoutRepository',
577
+ useFactory: (firestore) => {
578
+ return new CheckoutFirestoreRepository(firestore.firestore);
579
+ },
580
+ deps: [AngularFirestore],
581
+ },
582
+ {
583
+ provide: 'CheckoutSubscriptionRepository',
584
+ useFactory: (firestore) => {
585
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
586
+ },
587
+ deps: [AngularFirestore],
588
+ },
589
+ {
590
+ provide: 'CouponRepository',
591
+ useFactory: (firestore) => {
592
+ return new CouponFirestoreRepository(firestore.firestore);
593
+ },
594
+ deps: [AngularFirestore],
595
+ },
596
+ {
597
+ provide: 'EditionRepository',
598
+ useFactory: (firestore, subscriptionRepository) => {
599
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
600
+ },
601
+ deps: [AngularFirestore, 'SubscriptionRepository'],
602
+ },
603
+ {
604
+ provide: 'HomeRepository',
605
+ useFactory: (firestore) => {
606
+ return new HomeFirestoreRepository(firestore.firestore);
607
+ },
608
+ deps: [AngularFirestore],
609
+ },
610
+ {
611
+ provide: 'LeadRepository',
612
+ useFactory: (firestore) => {
613
+ return new LeadFirestoreRepository(firestore.firestore);
614
+ },
615
+ deps: [AngularFirestore],
616
+ },
617
+ {
618
+ provide: 'LegacyOrderRepository',
619
+ useFactory: (firestore) => {
620
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
621
+ },
622
+ deps: [AngularFirestore],
623
+ },
624
+ {
625
+ provide: 'ShopMenuRepository',
626
+ useFactory: (firestore) => {
627
+ return new ShopMenuFirestoreRepository(firestore.firestore);
628
+ },
629
+ deps: [AngularFirestore],
630
+ },
631
+ {
632
+ provide: 'OrderRepository',
633
+ useFactory: (firestore) => {
634
+ return new OrderFirestoreRepository(firestore.firestore);
635
+ },
636
+ deps: [AngularFirestore],
637
+ },
638
+ {
639
+ provide: 'PaymentRepository',
640
+ useFactory: (firestore) => {
641
+ return new PaymentFirestoreRepository(firestore.firestore);
642
+ },
643
+ deps: [AngularFirestore],
644
+ },
645
+ {
646
+ provide: 'ProductRepository',
647
+ useFactory: (firestore) => {
648
+ return new ProductFirestoreRepository(firestore.firestore);
649
+ },
650
+ deps: [AngularFirestore],
651
+ },
652
+ {
653
+ provide: 'SubscriptionPaymentRepository',
654
+ useFactory: (firestore, subscriptionRepository) => {
655
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
656
+ },
657
+ deps: [AngularFirestore, 'SubscriptionRepository'],
658
+ },
659
+ {
660
+ provide: 'SubscriptionPlanRepository',
661
+ useFactory: (firestore) => {
662
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
663
+ },
664
+ deps: [AngularFirestore],
665
+ },
666
+ {
667
+ provide: 'SubscriptionProductRepository',
668
+ useFactory: (firestore) => {
669
+ return new SubscriptionProductFirestoreRepository(firestore.firestore);
670
+ },
671
+ deps: [AngularFirestore],
672
+ },
673
+ {
674
+ provide: 'SubscriptionRepository',
675
+ useFactory: (firestore) => {
676
+ return new SubscriptionFirestoreRepository(firestore.firestore);
677
+ },
678
+ deps: [AngularFirestore],
679
+ },
680
+ {
681
+ provide: 'UserRepository',
682
+ useFactory: (firestore) => {
683
+ return new UserFirestoreRepository(firestore.firestore);
684
+ },
685
+ deps: [AngularFirestore],
686
+ },
687
+ {
688
+ provide: 'UserAddressRepository',
689
+ useFactory: (firestore, userRepository) => {
690
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
691
+ },
692
+ deps: [AngularFirestore, 'UserRepository'],
693
+ },
694
+ {
695
+ provide: 'UserPaymentMethodRepository',
696
+ useFactory: (firestore, userRepository) => {
697
+ return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
698
+ },
699
+ deps: [AngularFirestore, 'UserRepository'],
700
+ },
701
+ {
702
+ provide: 'VariantRepository',
703
+ useFactory: (firestore, productRepository) => {
704
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
705
+ },
706
+ deps: [AngularFirestore, 'ProductRepository'],
707
+ },
708
+ ], imports: [[AngularFireModule]] });
709
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
710
+ type: NgModule,
711
+ args: [{
712
+ imports: [AngularFireModule],
713
+ providers: [
714
+ {
715
+ provide: 'BeautyProfileRepository',
716
+ useFactory: (firestore, userRepository) => {
717
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
718
+ },
719
+ deps: [AngularFirestore, 'UserRepository'],
720
+ },
721
+ {
722
+ provide: 'Buy2WinRepository',
723
+ useFactory: (firestore) => {
724
+ return new Buy2WinFirestoreRepository(firestore.firestore);
725
+ },
726
+ deps: [AngularFirestore],
727
+ },
728
+ {
729
+ provide: 'CategoryRepository',
730
+ useFactory: (firestore) => {
731
+ return new CategoryFirestoreRepository(firestore.firestore);
732
+ },
733
+ deps: [AngularFirestore],
734
+ },
735
+ {
736
+ provide: 'CheckoutRepository',
737
+ useFactory: (firestore) => {
738
+ return new CheckoutFirestoreRepository(firestore.firestore);
739
+ },
740
+ deps: [AngularFirestore],
741
+ },
742
+ {
743
+ provide: 'CheckoutSubscriptionRepository',
744
+ useFactory: (firestore) => {
745
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
746
+ },
747
+ deps: [AngularFirestore],
748
+ },
749
+ {
750
+ provide: 'CouponRepository',
751
+ useFactory: (firestore) => {
752
+ return new CouponFirestoreRepository(firestore.firestore);
753
+ },
754
+ deps: [AngularFirestore],
755
+ },
756
+ {
757
+ provide: 'EditionRepository',
758
+ useFactory: (firestore, subscriptionRepository) => {
759
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
760
+ },
761
+ deps: [AngularFirestore, 'SubscriptionRepository'],
762
+ },
763
+ {
764
+ provide: 'HomeRepository',
765
+ useFactory: (firestore) => {
766
+ return new HomeFirestoreRepository(firestore.firestore);
767
+ },
768
+ deps: [AngularFirestore],
769
+ },
770
+ {
771
+ provide: 'LeadRepository',
772
+ useFactory: (firestore) => {
773
+ return new LeadFirestoreRepository(firestore.firestore);
774
+ },
775
+ deps: [AngularFirestore],
776
+ },
777
+ {
778
+ provide: 'LegacyOrderRepository',
779
+ useFactory: (firestore) => {
780
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
781
+ },
782
+ deps: [AngularFirestore],
783
+ },
784
+ {
785
+ provide: 'ShopMenuRepository',
786
+ useFactory: (firestore) => {
787
+ return new ShopMenuFirestoreRepository(firestore.firestore);
788
+ },
789
+ deps: [AngularFirestore],
790
+ },
791
+ {
792
+ provide: 'OrderRepository',
793
+ useFactory: (firestore) => {
794
+ return new OrderFirestoreRepository(firestore.firestore);
795
+ },
796
+ deps: [AngularFirestore],
797
+ },
798
+ {
799
+ provide: 'PaymentRepository',
800
+ useFactory: (firestore) => {
801
+ return new PaymentFirestoreRepository(firestore.firestore);
802
+ },
803
+ deps: [AngularFirestore],
804
+ },
805
+ {
806
+ provide: 'ProductRepository',
807
+ useFactory: (firestore) => {
808
+ return new ProductFirestoreRepository(firestore.firestore);
809
+ },
810
+ deps: [AngularFirestore],
811
+ },
812
+ {
813
+ provide: 'SubscriptionPaymentRepository',
814
+ useFactory: (firestore, subscriptionRepository) => {
815
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
816
+ },
817
+ deps: [AngularFirestore, 'SubscriptionRepository'],
818
+ },
819
+ {
820
+ provide: 'SubscriptionPlanRepository',
821
+ useFactory: (firestore) => {
822
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
823
+ },
824
+ deps: [AngularFirestore],
825
+ },
826
+ {
827
+ provide: 'SubscriptionProductRepository',
828
+ useFactory: (firestore) => {
829
+ return new SubscriptionProductFirestoreRepository(firestore.firestore);
830
+ },
831
+ deps: [AngularFirestore],
832
+ },
833
+ {
834
+ provide: 'SubscriptionRepository',
835
+ useFactory: (firestore) => {
836
+ return new SubscriptionFirestoreRepository(firestore.firestore);
837
+ },
838
+ deps: [AngularFirestore],
839
+ },
840
+ {
841
+ provide: 'UserRepository',
842
+ useFactory: (firestore) => {
843
+ return new UserFirestoreRepository(firestore.firestore);
844
+ },
845
+ deps: [AngularFirestore],
846
+ },
847
+ {
848
+ provide: 'UserAddressRepository',
849
+ useFactory: (firestore, userRepository) => {
850
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
851
+ },
852
+ deps: [AngularFirestore, 'UserRepository'],
853
+ },
854
+ {
855
+ provide: 'UserPaymentMethodRepository',
856
+ useFactory: (firestore, userRepository) => {
857
+ return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
858
+ },
859
+ deps: [AngularFirestore, 'UserRepository'],
860
+ },
861
+ {
862
+ provide: 'VariantRepository',
863
+ useFactory: (firestore, productRepository) => {
864
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
865
+ },
866
+ deps: [AngularFirestore, 'ProductRepository'],
867
+ },
868
+ ],
869
+ }]
873
870
  }] });
874
871
 
875
- class AngularConnectModule {
876
- static initializeApp(defaultShop, options, nameOrConfig) {
877
- return {
878
- ngModule: AngularConnectModule,
879
- providers: [
880
- ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
881
- ...(isNil(options) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options }]),
882
- ...(isNil(options) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
883
- ],
884
- };
885
- }
886
- }
887
- AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
888
- AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule] });
889
- AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, OrderService], imports: [[AngularFireModule, AngularFirestoreModule]] });
890
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
891
- type: NgModule,
892
- args: [{
893
- imports: [AngularFireModule, AngularFirestoreModule],
894
- providers: [AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, OrderService],
895
- }]
872
+ class AngularConnectModule {
873
+ static initializeApp(defaultShop, options, nameOrConfig) {
874
+ return {
875
+ ngModule: AngularConnectModule,
876
+ providers: [
877
+ ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
878
+ ...(isNil(options) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options }]),
879
+ ...(isNil(options) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
880
+ ],
881
+ };
882
+ }
883
+ }
884
+ AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
885
+ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule] });
886
+ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, OrderService], imports: [[AngularFireModule, AngularFirestoreModule]] });
887
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
888
+ type: NgModule,
889
+ args: [{
890
+ imports: [AngularFireModule, AngularFirestoreModule],
891
+ providers: [AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, OrderService],
892
+ }]
896
893
  }] });
897
894
 
898
- /**
899
- * Generated bundle index. Do not edit.
895
+ /**
896
+ * Generated bundle index. Do not edit.
900
897
  */
901
898
 
902
899
  export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, OrderService };