@infrab4a/connect-angular 2.0.5-beta.0 → 2.0.6-beta.0

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 (55) hide show
  1. package/angular-connect.module.d.ts +18 -18
  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 +1705 -1676
  7. package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
  8. package/consts/default-shop.const.d.ts +1 -1
  9. package/consts/es-config.const.d.ts +1 -1
  10. package/consts/hasura-options.const.d.ts +1 -1
  11. package/consts/index.d.ts +3 -3
  12. package/esm2015/angular-connect.module.js +49 -49
  13. package/esm2015/angular-elastic-search.module.js +38 -38
  14. package/esm2015/angular-firebase-auth.module.js +113 -113
  15. package/esm2015/angular-firestore.module.js +340 -340
  16. package/esm2015/angular-hasura-graphql.module.js +90 -90
  17. package/esm2015/consts/default-shop.const.js +2 -2
  18. package/esm2015/consts/es-config.const.js +2 -2
  19. package/esm2015/consts/hasura-options.const.js +2 -2
  20. package/esm2015/consts/index.js +4 -4
  21. package/esm2015/index.js +6 -6
  22. package/esm2015/infrab4a-connect-angular.js +4 -4
  23. package/esm2015/services/auth.service.js +42 -42
  24. package/esm2015/services/cart.service.js +157 -147
  25. package/esm2015/services/checkout-subscription.service.js +51 -51
  26. package/esm2015/services/checkout.service.js +75 -75
  27. package/esm2015/services/coupon.service.js +261 -250
  28. package/esm2015/services/errors/group-invalid-coupon.error.js +8 -8
  29. package/esm2015/services/errors/index.js +3 -3
  30. package/esm2015/services/errors/invalid-coupon.error.js +8 -8
  31. package/esm2015/services/home-shop.service.js +112 -112
  32. package/esm2015/services/index.js +8 -8
  33. package/esm2015/services/order.service.js +32 -32
  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/fesm2015/infrab4a-connect-angular.js +1258 -1237
  38. package/fesm2015/infrab4a-connect-angular.js.map +1 -1
  39. package/index.d.ts +5 -5
  40. package/infrab4a-connect-angular.d.ts +5 -5
  41. package/package.json +1 -1
  42. package/services/auth.service.d.ts +19 -19
  43. package/services/cart.service.d.ts +36 -35
  44. package/services/checkout-subscription.service.d.ts +18 -18
  45. package/services/checkout.service.d.ts +23 -23
  46. package/services/coupon.service.d.ts +25 -24
  47. package/services/errors/group-invalid-coupon.error.d.ts +6 -6
  48. package/services/errors/index.d.ts +2 -2
  49. package/services/errors/invalid-coupon.error.d.ts +5 -5
  50. package/services/home-shop.service.d.ts +25 -25
  51. package/services/index.d.ts +7 -7
  52. package/services/order.service.d.ts +13 -13
  53. package/services/types/index.d.ts +2 -2
  54. package/services/types/required-checkout-data.type.d.ts +2 -2
  55. package/services/types/required-checkout-subscription-data.type.d.ts +2 -2
@@ -13,40 +13,40 @@ import * as i1$1 from '@angular/fire/firestore';
13
13
  import { AngularFirestore } from '@angular/fire/firestore';
14
14
  import { FIREBASE_OPTIONS, FIREBASE_APP_NAME, AngularFireModule } from '@angular/fire';
15
15
 
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 ? this.userRepository.get({ id }) : 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']
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 ? this.userRepository.get({ id }) : 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']
50
50
  }] }]; } });
51
51
 
52
52
  const DEFAULT_SHOP = 'DEFAULT_SHOP';
@@ -55,1235 +55,1256 @@ const ES_CONFIG = 'ES_CONFIG';
55
55
 
56
56
  const HASURA_OPTIONS = 'HASURA_OPTIONS';
57
57
 
58
- class InvalidCouponError extends CustomError {
59
- constructor(message) {
60
- super(message);
61
- this.message = message;
62
- }
58
+ class InvalidCouponError extends CustomError {
59
+ constructor(message) {
60
+ super(message);
61
+ this.message = message;
62
+ }
63
63
  }
64
64
 
65
- class GroupInvalidCouponError extends CustomError {
66
- constructor(errors) {
67
- super('Many coupon errors throw');
68
- this.errors = errors;
69
- }
65
+ class GroupInvalidCouponError extends CustomError {
66
+ constructor(errors) {
67
+ super('Many coupon errors throw');
68
+ this.errors = errors;
69
+ }
70
70
  }
71
71
 
72
- class CouponService {
73
- constructor(couponRepository, defaultShop, orderRepository, subscriptionRepository) {
74
- this.couponRepository = couponRepository;
75
- this.defaultShop = defaultShop;
76
- this.orderRepository = orderRepository;
77
- this.subscriptionRepository = subscriptionRepository;
78
- this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
79
- this.separateValidCoupons = (coupons, userEmail) => coupons
80
- .map((coupon) => {
81
- try {
82
- if (!(coupon instanceof Coupon))
83
- throw new InvalidCouponError('Cupom inválido.');
84
- if (this.isValidCoupon(coupon, userEmail))
85
- return coupon;
86
- }
87
- catch (error) {
88
- return error;
89
- }
90
- })
91
- .reduce((current, coupon) => (Object.assign(Object.assign({}, current), (coupon instanceof Coupon
92
- ? { valids: [...current.valids, coupon] }
93
- : { invalids: [...current.invalids, coupon] }))), {
94
- valids: [],
95
- invalids: [],
96
- });
97
- }
98
- checkCoupon(nickname, userEmail, checkoutType, plan, checkout, isSubscription) {
99
- return from(this.couponRepository.find({
100
- filters: {
101
- nickname: { operator: Where.EQUALS, value: nickname },
102
- active: { operator: Where.EQUALS, value: true },
103
- },
104
- })).pipe(concatMap((coupons) => this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription)), concatMap((coupon) => this.checkCouponUseAndLimit(coupon, userEmail)), map((coupon) => this.isValidCoupon(coupon, userEmail)), map((coupon) => coupon));
105
- }
106
- checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription) {
107
- // Caso não ache nenhum cupom, retorna erro
108
- if (coupons.count < 1) {
109
- return throwError('Cupom inválido.');
110
- }
111
- // Get Primeiro Cupom (o find do repository retorna um array)
112
- const coupon = coupons.data.shift();
113
- // Verifica se o cupom é aplicavel na loja
114
- const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
115
- // Cupon não aplicavel a loja retorna erro
116
- if (!isInShop)
117
- return throwError('Cupom inválido para loja.');
118
- // Verifica se o coupon é aplicado no checkout que está sendo realizado
119
- const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
120
- // Cupon não aplicavel ao checkout retorna erro
121
- if (!isCheckoutType)
122
- return throwError('Cupom inválido. Erro de checkout.');
123
- // Verifica se o cupom é ou pode ser aplicado para subscription
124
- if (checkoutType === CheckoutTypes.ALL || checkoutType === CheckoutTypes.SUBSCRIPTION) {
125
- // Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
126
- if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
127
- return throwError('Cupom inválido para sua assinatura.');
128
- }
129
- if (isSubscription)
130
- return of(coupon);
131
- // Verifica se possui o valor minimo de compra para utilização do cupom
132
- const hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
133
- // Se não tem valor mínimo atingido, retorna erro
134
- if (!hasMinSubTotal)
135
- return throwError('Valor mínimo não atingido');
136
- // Verifica se a compra possui produtos elegíveis para desconto
137
- const hasProductCategories = this.hasProductCategories(coupon, checkout);
138
- // Se não tem produtos elegíveis, retorna erro
139
- if (!hasProductCategories)
140
- return throwError('Seu carrinho não possui produtos elegíveis para desconto.');
141
- return of(coupon);
142
- }
143
- isValidCoupon(coupon, userEmail) {
144
- // Verifica a data de inicio de validade do cupom
145
- if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) > new Date())
146
- throw new InvalidCouponError('Cupom ainda não liberado.');
147
- // Verifica a data de validade do cupom
148
- if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
149
- throw new InvalidCouponError('Cupom expirado.');
150
- return coupon;
151
- }
152
- checkCouponUseAndLimit(coupon, userEmail) {
153
- return __awaiter(this, void 0, void 0, function* () {
154
- // Busca orders que possuem o cupom e que estão pagas
155
- const orders = yield this.orderRepository.find({
156
- filters: {
157
- coupon: { id: coupon.id },
158
- payment: { status: 'paid' },
159
- },
160
- });
161
- // orders que usuario ja fez com o cupom
162
- const ordersUserCoupon = orders.data.filter((o) => o.user.email == userEmail);
163
- // Verifica o limite de uso de cupom por usuario
164
- if (coupon.useLimitPerUser && ordersUserCoupon.length)
165
- throw new InvalidCouponError('Limite de uso por usuário atingido.');
166
- // Verifica o limite de uso geral por usuario
167
- if (coupon.useLimit && orders.data.length >= coupon.useLimit)
168
- throw new InvalidCouponError('Limite de uso atingido.');
169
- const validUser = yield this.userValidationAndSubscriptionStatus(coupon, userEmail);
170
- if (!validUser)
171
- throw new InvalidCouponError('Usuário não elegível.');
172
- return coupon;
173
- });
174
- }
175
- calcDiscountSubscription(coupon, checkout) {
176
- //
177
- let discount = 0;
178
- if (coupon.type === CouponTypes.ABSOLUTE)
179
- discount = coupon.discount;
180
- else if (coupon.type === CouponTypes.PERCENTAGE)
181
- discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount / 100);
182
- return of(discount);
183
- }
184
- calcDiscountShopping(coupon, checkout) {
185
- let discount = 0;
186
- switch (coupon.type) {
187
- case CouponTypes.ABSOLUTE: {
188
- discount = coupon.discount;
189
- break;
190
- }
191
- case CouponTypes.PERCENTAGE: {
192
- discount = this.calcShoppingPercentageDiscount(coupon, checkout);
193
- break;
194
- }
195
- }
196
- return of(discount);
197
- }
198
- calcShoppingPercentageDiscount(coupon, checkout) {
199
- var _a;
200
- let discount = 0;
201
- const shop = checkout.shop;
202
- let lineItensDiscount = [];
203
- if (coupon.productsCategories && coupon.productsCategories.length) {
204
- lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
205
- var _a;
206
- if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
207
- return i.categories.some((c) => coupon.productsCategories.includes(c));
208
- }
209
- return true;
210
- });
211
- }
212
- else {
213
- lineItensDiscount = checkout.lineItems;
214
- }
215
- const subTotal = lineItensDiscount.reduce((acc, curr) => {
216
- var _a, _b, _c;
217
- return ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber) && ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice)
218
- ? acc + ((_c = curr.price[shop]) === null || _c === void 0 ? void 0 : _c.subscriberPrice) * curr.quantity
219
- : acc + curr.pricePaid * curr.quantity;
220
- }, 0) || 0;
221
- discount = subTotal * (coupon.discount / 100);
222
- return discount;
223
- }
224
- hasMinSubTotal(coupon, checkout) {
225
- var _a;
226
- if (!coupon.minSubTotalValue)
227
- return true;
228
- const shop = checkout.shop;
229
- let subTotal = ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.reduce((acc, curr) => {
230
- var _a, _b, _c;
231
- return ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber) && ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice)
232
- ? acc + ((_c = curr.price[shop]) === null || _c === void 0 ? void 0 : _c.subscriberPrice) * curr.quantity
233
- : acc + curr.pricePaid * curr.quantity;
234
- }, 0)) || 0;
235
- if (coupon.minSubTotalValue <= subTotal)
236
- return true;
237
- return false;
238
- }
239
- hasProductCategories(coupon, checkout) {
240
- var _a;
241
- if (coupon.productsCategories && coupon.productsCategories.length) {
242
- const hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
243
- var _a;
244
- if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
245
- return i.categories.some((c) => coupon.productsCategories.includes(c) && !i.isGift);
246
- }
247
- return true;
248
- });
249
- return hasCategories.length ? true : false;
250
- }
251
- else {
252
- return true;
253
- }
254
- }
255
- userValidationAndSubscriptionStatus(coupon, userEmail) {
256
- return __awaiter(this, void 0, void 0, function* () {
257
- // Verifica se o email do usuário é coorporativo
258
- if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
259
- throw new InvalidCouponError('Você não é colaborador.');
260
- // Verifica se o email do usuário é associado ao cupom de uso por usuario
261
- if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== userEmail)
262
- throw new InvalidCouponError('Cupom não é válido para este usuário.');
263
- const couponRuleSubscription = coupon.exclusivityType === Exclusivities.ACTIVE_SUBSCRIBER ||
264
- coupon.exclusivityType === Exclusivities.INACTIVE_SUBSCRIBER ||
265
- coupon.exclusivityType === Exclusivities.NON_SUBSCRIBER;
266
- if (couponRuleSubscription && userEmail) {
267
- const sub = yield this.subscriptionRepository
268
- .find({
269
- filters: {
270
- user: {
271
- email: { operator: Where.EQUALS, value: userEmail },
272
- },
273
- },
274
- })
275
- .then((sub) => sub.data);
276
- const activeSubs = sub === null || sub === void 0 ? void 0 : sub.filter((s) => s.status === Status.ACTIVE);
277
- switch (coupon.exclusivityType) {
278
- case Exclusivities.ACTIVE_SUBSCRIBER:
279
- return activeSubs.length > 0;
280
- case Exclusivities.INACTIVE_SUBSCRIBER:
281
- return activeSubs.length === 0;
282
- case Exclusivities.NON_SUBSCRIBER:
283
- return sub.length === 0;
284
- default:
285
- return false;
286
- }
287
- }
288
- return true;
289
- });
290
- }
291
- }
292
- 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: 'SubscriptionRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
293
- CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
294
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, decorators: [{
295
- type: Injectable,
296
- args: [{
297
- providedIn: 'root',
298
- }]
299
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
300
- type: Inject,
301
- args: ['CouponRepository']
302
- }] }, { type: i2.Shops, decorators: [{
303
- type: Inject,
304
- args: [DEFAULT_SHOP]
305
- }] }, { type: undefined, decorators: [{
306
- type: Inject,
307
- args: ['OrderRepository']
308
- }] }, { type: undefined, decorators: [{
309
- type: Inject,
310
- args: ['SubscriptionRepository']
72
+ class CouponService {
73
+ constructor(couponRepository, defaultShop, orderRepository, subscriptionRepository, categoryRepository) {
74
+ this.couponRepository = couponRepository;
75
+ this.defaultShop = defaultShop;
76
+ this.orderRepository = orderRepository;
77
+ this.subscriptionRepository = subscriptionRepository;
78
+ this.categoryRepository = categoryRepository;
79
+ this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
80
+ this.separateValidCoupons = (coupons, userEmail) => coupons
81
+ .map((coupon) => {
82
+ try {
83
+ if (!(coupon instanceof Coupon))
84
+ throw new InvalidCouponError('Cupom inválido.');
85
+ if (this.isValidCoupon(coupon, userEmail))
86
+ return coupon;
87
+ }
88
+ catch (error) {
89
+ return error;
90
+ }
91
+ })
92
+ .reduce((current, coupon) => (Object.assign(Object.assign({}, current), (coupon instanceof Coupon
93
+ ? { valids: [...current.valids, coupon] }
94
+ : { invalids: [...current.invalids, coupon] }))), {
95
+ valids: [],
96
+ invalids: [],
97
+ });
98
+ }
99
+ checkCoupon(nickname, userEmail, checkoutType, plan, checkout, isSubscription) {
100
+ return from(this.couponRepository.find({
101
+ filters: {
102
+ nickname: { operator: Where.EQUALS, value: nickname },
103
+ active: { operator: Where.EQUALS, value: true },
104
+ },
105
+ })).pipe(concatMap((coupons) => this.checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription)), concatMap((coupon) => this.checkCouponUseAndLimit(coupon, userEmail)), map((coupon) => this.isValidCoupon(coupon, userEmail)), map((coupon) => coupon));
106
+ }
107
+ checkCouponRules(coupons, checkoutType, plan, checkout, isSubscription) {
108
+ // Caso não ache nenhum cupom, retorna erro
109
+ if (coupons.count < 1) {
110
+ return throwError('Cupom inválido.');
111
+ }
112
+ // Get Primeiro Cupom (o find do repository retorna um array)
113
+ const coupon = coupons.data.shift();
114
+ // Verifica se o cupom é aplicavel na loja
115
+ const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
116
+ // Cupon não aplicavel a loja retorna erro
117
+ if (!isInShop)
118
+ return throwError('Cupom inválido para loja.');
119
+ // Verifica se o coupon é aplicado no checkout que está sendo realizado
120
+ const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
121
+ // Cupon não aplicavel ao checkout retorna erro
122
+ if (!isCheckoutType)
123
+ return throwError('Cupom inválido. Erro de checkout.');
124
+ // Verifica se o cupom é ou pode ser aplicado para subscription
125
+ if (checkoutType === CheckoutTypes.ALL || checkoutType === CheckoutTypes.SUBSCRIPTION) {
126
+ // Se o cupom tiver um plano associado, verifica se é o mesmo plano do checkout da assinatura
127
+ if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
128
+ return throwError('Cupom inválido para sua assinatura.');
129
+ }
130
+ if (isSubscription)
131
+ return of(coupon);
132
+ // Verifica se possui o valor minimo de compra para utilização do cupom
133
+ const hasMinSubTotal = this.hasMinSubTotal(coupon, checkout);
134
+ // Se não tem valor mínimo atingido, retorna erro
135
+ if (!hasMinSubTotal)
136
+ return throwError('Valor mínimo não atingido');
137
+ // Verifica se a compra possui produtos elegíveis para desconto
138
+ const hasProductCategories = this.hasProductCategories(coupon, checkout);
139
+ // Se não tem produtos elegíveis, retorna erro
140
+ if (!hasProductCategories)
141
+ return throwError('Seu carrinho não possui produtos elegíveis para desconto.');
142
+ return of(coupon);
143
+ }
144
+ isValidCoupon(coupon, userEmail) {
145
+ // Verifica a data de inicio de validade do cupom
146
+ if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) > new Date())
147
+ throw new InvalidCouponError('Cupom ainda não liberado.');
148
+ // Verifica a data de validade do cupom
149
+ if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
150
+ throw new InvalidCouponError('Cupom expirado.');
151
+ return coupon;
152
+ }
153
+ checkCouponUseAndLimit(coupon, userEmail) {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ // Busca orders que possuem o cupom e que estão pagas
156
+ const orders = yield this.orderRepository.find({
157
+ filters: {
158
+ coupon: { id: coupon.id },
159
+ payment: { status: 'paid' },
160
+ },
161
+ });
162
+ // orders que usuario ja fez com o cupom
163
+ const ordersUserCoupon = orders.data.filter((o) => o.user.email == userEmail);
164
+ // Verifica o limite de uso de cupom por usuario
165
+ if (coupon.useLimitPerUser && ordersUserCoupon.length)
166
+ throw new InvalidCouponError('Limite de uso por usuário atingido.');
167
+ // Verifica o limite de uso geral por usuario
168
+ if (coupon.useLimit && orders.data.length >= coupon.useLimit)
169
+ throw new InvalidCouponError('Limite de uso atingido.');
170
+ const validUser = yield this.userValidationAndSubscriptionStatus(coupon, userEmail);
171
+ if (!validUser)
172
+ throw new InvalidCouponError('Usuário não elegível.');
173
+ return coupon;
174
+ });
175
+ }
176
+ calcDiscountSubscription(coupon, checkout) {
177
+ //
178
+ let discount = 0;
179
+ if (coupon.type === CouponTypes.ABSOLUTE)
180
+ discount = coupon.discount;
181
+ else if (coupon.type === CouponTypes.PERCENTAGE)
182
+ discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount / 100);
183
+ return of(discount);
184
+ }
185
+ calcDiscountShopping(coupon, checkout) {
186
+ let discount = 0;
187
+ switch (coupon.type) {
188
+ case CouponTypes.ABSOLUTE: {
189
+ discount = coupon.discount;
190
+ break;
191
+ }
192
+ case CouponTypes.PERCENTAGE: {
193
+ discount = this.calcShoppingPercentageDiscount(coupon, checkout);
194
+ break;
195
+ }
196
+ }
197
+ return of(discount);
198
+ }
199
+ calcShoppingPercentageDiscount(coupon, checkout) {
200
+ var _a;
201
+ let discount = 0;
202
+ const shop = checkout.shop;
203
+ let lineItensDiscount = [];
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) => coupon.productsCategories.includes(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
+ hasMinSubTotal(coupon, checkout) {
226
+ var _a;
227
+ if (!coupon.minSubTotalValue)
228
+ return true;
229
+ const shop = checkout.shop;
230
+ let subTotal = ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.reduce((acc, curr) => {
231
+ var _a, _b, _c;
232
+ return ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber) && ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice)
233
+ ? acc + ((_c = curr.price[shop]) === null || _c === void 0 ? void 0 : _c.subscriberPrice) * curr.quantity
234
+ : acc + curr.pricePaid * curr.quantity;
235
+ }, 0)) || 0;
236
+ if (coupon.minSubTotalValue <= subTotal)
237
+ return true;
238
+ return false;
239
+ }
240
+ hasProductCategories(coupon, checkout) {
241
+ var _a;
242
+ if (coupon.productsCategories && coupon.productsCategories.length) {
243
+ const hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((i) => {
244
+ var _a;
245
+ if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
246
+ // buscar categoria por id
247
+ // filtrar por id ou firestore id
248
+ return i.categories.some((c) => __awaiter(this, void 0, void 0, function* () {
249
+ const categoria = yield this.categoryRepository.get({ id: c });
250
+ console.log(categoria);
251
+ console.log(coupon.productsCategories.includes(categoria.id), coupon.productsCategories.includes(categoria.firestoreId));
252
+ return (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift;
253
+ }));
254
+ }
255
+ return true;
256
+ });
257
+ return hasCategories.length ? true : false;
258
+ }
259
+ else {
260
+ return true;
261
+ }
262
+ }
263
+ userValidationAndSubscriptionStatus(coupon, userEmail) {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ // Verifica se o email do usuário é coorporativo
266
+ if (!this.emailIsFromCollaborator(userEmail) && coupon.exclusivityType === Exclusivities.COLLABORATORS)
267
+ throw new InvalidCouponError('Você não é colaborador.');
268
+ // Verifica se o email do usuário é associado ao cupom de uso por usuario
269
+ if (coupon.exclusivityType === Exclusivities.SPECIFIC_USER && coupon.userExclusiveEmail !== userEmail)
270
+ throw new InvalidCouponError('Cupom não é válido para este usuário.');
271
+ const couponRuleSubscription = coupon.exclusivityType === Exclusivities.ACTIVE_SUBSCRIBER ||
272
+ coupon.exclusivityType === Exclusivities.INACTIVE_SUBSCRIBER ||
273
+ coupon.exclusivityType === Exclusivities.NON_SUBSCRIBER;
274
+ if (couponRuleSubscription && userEmail) {
275
+ const sub = yield this.subscriptionRepository
276
+ .find({
277
+ filters: {
278
+ user: {
279
+ email: { operator: Where.EQUALS, value: userEmail },
280
+ },
281
+ },
282
+ })
283
+ .then((sub) => sub.data);
284
+ const activeSubs = sub === null || sub === void 0 ? void 0 : sub.filter((s) => s.status === Status.ACTIVE);
285
+ switch (coupon.exclusivityType) {
286
+ case Exclusivities.ACTIVE_SUBSCRIBER:
287
+ return activeSubs.length > 0;
288
+ case Exclusivities.INACTIVE_SUBSCRIBER:
289
+ return activeSubs.length === 0;
290
+ case Exclusivities.NON_SUBSCRIBER:
291
+ return sub.length === 0;
292
+ default:
293
+ return false;
294
+ }
295
+ }
296
+ return true;
297
+ });
298
+ }
299
+ }
300
+ 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: 'SubscriptionRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
301
+ CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, providedIn: 'root' });
302
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CouponService, decorators: [{
303
+ type: Injectable,
304
+ args: [{
305
+ providedIn: 'root',
306
+ }]
307
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
308
+ type: Inject,
309
+ args: ['CouponRepository']
310
+ }] }, { type: i2.Shops, decorators: [{
311
+ type: Inject,
312
+ args: [DEFAULT_SHOP]
313
+ }] }, { type: undefined, decorators: [{
314
+ type: Inject,
315
+ args: ['OrderRepository']
316
+ }] }, { type: undefined, decorators: [{
317
+ type: Inject,
318
+ args: ['SubscriptionRepository']
319
+ }] }, { type: undefined, decorators: [{
320
+ type: Inject,
321
+ args: ['CategoryRepository']
311
322
  }] }]; } });
312
323
 
313
- class CheckoutService {
314
- constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
315
- this.couponService = couponService;
316
- this.checkoutRepository = checkoutRepository;
317
- this.orderRepository = orderRepository;
318
- this.userRepository = userRepository;
319
- this.defaultShop = defaultShop;
320
- }
321
- getCheckout(checkoutData) {
322
- const checkoutId = cookie.get('checkoutId');
323
- if (!isNil(checkoutId))
324
- return from(this.checkoutRepository.get({ id: checkoutId }));
325
- return from(this.createCheckout(checkoutData));
326
- }
327
- getUserByCheckout(checkoutId) {
328
- 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'))));
329
- }
330
- updateCheckoutLineItems(checkout) {
331
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
332
- }
333
- updateCheckoutUser(checkout) {
334
- return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
335
- }
336
- clearCheckoutFromSession() {
337
- cookie.remove('checkoutId');
338
- return of();
339
- }
340
- calcDiscount(coupon) {
341
- return this.getCheckout().pipe(concatMap((checkout) => this.couponService.calcDiscountShopping(coupon, checkout).pipe()));
342
- }
343
- checkCoupon(nickname, checkoutType) {
344
- return this.getCheckout().pipe(concatMap((checkout) => {
345
- var _a;
346
- return this.couponService
347
- .checkCoupon(nickname, (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.email, CheckoutTypes.ECOMMERCE, checkout.user.subscriptionPlan, checkout, false)
348
- .pipe();
349
- }));
350
- }
351
- createCheckout(checkoutData) {
352
- return __awaiter(this, void 0, void 0, function* () {
353
- 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 }));
354
- cookie.set('checkoutId', checkout.id);
355
- return checkout;
356
- });
357
- }
358
- }
359
- 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 });
360
- CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService });
361
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, decorators: [{
362
- type: Injectable
363
- }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
364
- type: Inject,
365
- args: ['CheckoutRepository']
366
- }] }, { type: undefined, decorators: [{
367
- type: Inject,
368
- args: ['OrderRepository']
369
- }] }, { type: undefined, decorators: [{
370
- type: Inject,
371
- args: ['UserRepository']
372
- }] }, { type: i2.Shops, decorators: [{
373
- type: Inject,
374
- args: [DEFAULT_SHOP]
324
+ class CheckoutService {
325
+ constructor(couponService, checkoutRepository, orderRepository, userRepository, defaultShop) {
326
+ this.couponService = couponService;
327
+ this.checkoutRepository = checkoutRepository;
328
+ this.orderRepository = orderRepository;
329
+ this.userRepository = userRepository;
330
+ this.defaultShop = defaultShop;
331
+ }
332
+ getCheckout(checkoutData) {
333
+ const checkoutId = cookie.get('checkoutId');
334
+ if (!isNil(checkoutId))
335
+ return from(this.checkoutRepository.get({ id: checkoutId }));
336
+ return from(this.createCheckout(checkoutData));
337
+ }
338
+ getUserByCheckout(checkoutId) {
339
+ 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'))));
340
+ }
341
+ updateCheckoutLineItems(checkout) {
342
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
343
+ }
344
+ updateCheckoutUser(checkout) {
345
+ return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
346
+ }
347
+ clearCheckoutFromSession() {
348
+ cookie.remove('checkoutId');
349
+ return of();
350
+ }
351
+ calcDiscount(coupon) {
352
+ return this.getCheckout().pipe(concatMap((checkout) => this.couponService.calcDiscountShopping(coupon, checkout).pipe()));
353
+ }
354
+ checkCoupon(nickname, checkoutType) {
355
+ return this.getCheckout().pipe(concatMap((checkout) => {
356
+ var _a;
357
+ return this.couponService
358
+ .checkCoupon(nickname, (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.email, CheckoutTypes.ECOMMERCE, checkout.user.subscriptionPlan, checkout, false)
359
+ .pipe();
360
+ }));
361
+ }
362
+ createCheckout(checkoutData) {
363
+ return __awaiter(this, void 0, void 0, function* () {
364
+ 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 }));
365
+ cookie.set('checkoutId', checkout.id);
366
+ return checkout;
367
+ });
368
+ }
369
+ }
370
+ 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 });
371
+ CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService });
372
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutService, decorators: [{
373
+ type: Injectable
374
+ }], ctorParameters: function () { return [{ type: CouponService }, { type: undefined, decorators: [{
375
+ type: Inject,
376
+ args: ['CheckoutRepository']
377
+ }] }, { type: undefined, decorators: [{
378
+ type: Inject,
379
+ args: ['OrderRepository']
380
+ }] }, { type: undefined, decorators: [{
381
+ type: Inject,
382
+ args: ['UserRepository']
383
+ }] }, { type: i2.Shops, decorators: [{
384
+ type: Inject,
385
+ args: [DEFAULT_SHOP]
375
386
  }] }]; } });
376
387
 
377
- class CartService {
378
- constructor(authService, checkoutService, defaultShop, productRepository) {
379
- this.authService = authService;
380
- this.checkoutService = checkoutService;
381
- this.defaultShop = defaultShop;
382
- this.productRepository = productRepository;
383
- this.cartSubject = new Subject();
384
- this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
385
- var _a;
386
- const items = [];
387
- const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.sku).indexOf(lineItem.sku);
388
- if (index > -1) {
389
- checkoutLoaded.lineItems[index].quantity += quantity;
390
- checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
391
- }
392
- else
393
- checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
394
- return this.checkoutService
395
- .updateCheckoutLineItems(checkoutLoaded)
396
- .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
397
- }));
398
- this.generateCartObject = (items) => {
399
- const cart = {};
400
- items === null || items === void 0 ? void 0 : items.forEach((item) => {
401
- var _a;
402
- 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) })));
403
- });
404
- return cart;
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.productRepository.get({ id: 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.sku === item.sku)) === 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, brand, slug, stock, price, weight, categories, sku } = 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
- return {
421
- checkout,
422
- lineItem: LineItem.toInstance({
423
- id,
424
- name: name !== null && name !== void 0 ? name : product.name,
425
- EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
426
- brand: product.brand,
427
- slug: slug !== null && slug !== void 0 ? slug : product.slug,
428
- sku: sku !== null && sku !== void 0 ? sku : product.sku,
429
- stock,
430
- price,
431
- image,
432
- weight: weight !== null && weight !== void 0 ? weight : product.weight,
433
- quantity: (item.quantity || 0) + (quantity || 0),
434
- pricePaid,
435
- categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
436
- isGift: isGift !== null && isGift !== void 0 ? isGift : null,
437
- costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
438
- }),
439
- };
440
- });
441
- this.getProductPrice = ({ product, isSubscriber, }) => {
442
- const info = product.price;
443
- if (product.isGift)
444
- return 0;
445
- return isSubscriber && info.subscriberPrice > 0 ? info.subscriberPrice : info.price;
446
- };
447
- this.checkMaxStock = (item, quantity) => {
448
- var _a;
449
- const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
450
- const currentItemAmount = item.quantity || 0;
451
- return currentItemAmount + quantity > maxStock;
452
- };
453
- }
454
- addItem(item, quantity = 1) {
455
- 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)));
456
- }
457
- decreaseItem(item) {
458
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
459
- var _a;
460
- const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.sku === item.sku);
461
- if (!isNil(checkoutItem))
462
- checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
463
- return checkout;
464
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
465
- }
466
- getCart(checkout) {
467
- this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
468
- return this.cartSubject;
469
- }
470
- /**
471
- * @deprecated The method should not be used
472
- */
473
- getVariantPriceDiscount(item) {
474
- 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)));
475
- }
476
- removeItem(item) {
477
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
478
- const index = checkout.lineItems.findIndex((lineItem) => lineItem.sku === item.sku);
479
- if (index >= 0)
480
- checkout.lineItems.splice(index, 1);
481
- return checkout;
482
- }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
483
- }
484
- updateUserCart(user) {
485
- return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => {
486
- var _a;
487
- 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) => __awaiter(this, void 0, void 0, function* () { return yield this.buildLineItem({ checkout, item }); }))) || [] })));
488
- }), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
489
- }
490
- clearCart() {
491
- return this.checkoutService.getCheckout().pipe(map((checkout) => {
492
- this.checkoutService.clearCheckoutFromSession();
493
- return checkout;
494
- }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
495
- }
496
- buildCartFromCheckout(checkoutData) {
497
- return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
498
- }
499
- }
500
- 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' }], target: i0.ɵɵFactoryTarget.Injectable });
501
- CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
502
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
503
- type: Injectable
504
- }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i2.Shops, decorators: [{
505
- type: Inject,
506
- args: [DEFAULT_SHOP]
507
- }] }, { type: undefined, decorators: [{
508
- type: Inject,
509
- args: ['ProductRepository']
388
+ class CartService {
389
+ constructor(authService, checkoutService, defaultShop, productRepository) {
390
+ this.authService = authService;
391
+ this.checkoutService = checkoutService;
392
+ this.defaultShop = defaultShop;
393
+ this.productRepository = productRepository;
394
+ this.cartSubject = new Subject();
395
+ this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
396
+ var _a;
397
+ const items = [];
398
+ const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.sku).indexOf(lineItem.sku);
399
+ if (index > -1) {
400
+ checkoutLoaded.lineItems[index].quantity += quantity;
401
+ checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
402
+ }
403
+ else
404
+ checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
405
+ return this.checkoutService
406
+ .updateCheckoutLineItems(checkoutLoaded)
407
+ .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
408
+ }));
409
+ this.generateCartObject = (items) => {
410
+ const cart = {};
411
+ items === null || items === void 0 ? void 0 : items.forEach((item) => {
412
+ var _a;
413
+ 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) })));
414
+ });
415
+ return cart;
416
+ };
417
+ this.buildLineItem = ({ checkout, item, quantity, }) => __awaiter(this, void 0, void 0, function* () {
418
+ var _a, _b, _c, _d, _e, _f, _g;
419
+ const product = yield this.productRepository.get({ id: item.id });
420
+ 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;
421
+ if (this.checkMaxStock(item, quantity || 0))
422
+ throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
423
+ const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
424
+ const { id, name, EAN, brand, slug, stock, price, weight, categories, sku } = item;
425
+ const isGift = item.isGift || null;
426
+ const pricePaid = this.getProductPrice({
427
+ product: item,
428
+ shop: checkout.shop || this.defaultShop,
429
+ isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
430
+ });
431
+ return {
432
+ checkout,
433
+ lineItem: LineItem.toInstance({
434
+ id,
435
+ name: name !== null && name !== void 0 ? name : product.name,
436
+ EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
437
+ brand: product.brand,
438
+ slug: slug !== null && slug !== void 0 ? slug : product.slug,
439
+ sku: sku !== null && sku !== void 0 ? sku : product.sku,
440
+ stock,
441
+ price,
442
+ image,
443
+ weight: weight !== null && weight !== void 0 ? weight : product.weight,
444
+ quantity: (item.quantity || 0) + (quantity || 0),
445
+ pricePaid,
446
+ categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
447
+ isGift: isGift !== null && isGift !== void 0 ? isGift : null,
448
+ costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
449
+ }),
450
+ };
451
+ });
452
+ this.getProductPrice = ({ product, shop, isSubscriber, }) => {
453
+ const info = product.getInfoByShop(shop);
454
+ if (product.isGift)
455
+ return 0;
456
+ return isSubscriber && info.subscriberPrice > 0 ? info.subscriberPrice : info.price;
457
+ };
458
+ this.checkMaxStock = (item, quantity) => {
459
+ var _a;
460
+ const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
461
+ const currentItemAmount = item.quantity || 0;
462
+ return currentItemAmount + quantity > maxStock;
463
+ };
464
+ }
465
+ addItem(item, quantity = 1) {
466
+ 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)));
467
+ }
468
+ decreaseItem(item) {
469
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
470
+ var _a;
471
+ const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.sku === item.sku);
472
+ if (!isNil(checkoutItem))
473
+ checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
474
+ return checkout;
475
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
476
+ }
477
+ getCart(checkout) {
478
+ this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
479
+ return this.cartSubject;
480
+ }
481
+ /**
482
+ * @deprecated The method should not be used
483
+ */
484
+ getVariantPriceDiscount(item, shop) {
485
+ 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)));
486
+ }
487
+ removeItem(item) {
488
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
489
+ const index = checkout.lineItems.findIndex((lineItem) => lineItem.sku === item.sku);
490
+ if (index >= 0)
491
+ checkout.lineItems.splice(index, 1);
492
+ return checkout;
493
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
494
+ }
495
+ updateUserCart(user) {
496
+ return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => {
497
+ var _a;
498
+ 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) => __awaiter(this, void 0, void 0, function* () { return yield this.buildLineItem({ checkout, item }); }))) || [] })));
499
+ }), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
500
+ }
501
+ clearCart() {
502
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
503
+ this.checkoutService.clearCheckoutFromSession();
504
+ return checkout;
505
+ }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
506
+ }
507
+ buildCartFromCheckout(checkoutData) {
508
+ return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
509
+ }
510
+ getSubTotalDiscount(coupon) {
511
+ return (subTotalPrice) => {
512
+ switch (coupon.type) {
513
+ case CouponTypes.ABSOLUTE:
514
+ return subTotalPrice - coupon.discount;
515
+ case CouponTypes.PERCENTAGE:
516
+ return subTotalPrice * (1 - coupon.discount / 100);
517
+ }
518
+ };
519
+ }
520
+ }
521
+ 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' }], target: i0.ɵɵFactoryTarget.Injectable });
522
+ CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
523
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
524
+ type: Injectable
525
+ }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i2.Shops, decorators: [{
526
+ type: Inject,
527
+ args: [DEFAULT_SHOP]
528
+ }] }, { type: undefined, decorators: [{
529
+ type: Inject,
530
+ args: ['ProductRepository']
510
531
  }] }]; } });
511
532
 
512
- class CheckoutSubscriptionService {
513
- constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
514
- this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
515
- this.subscriptionRepository = subscriptionRepository;
516
- this.couponService = couponService;
517
- }
518
- getCheckoutSubscription(checkoutData) {
519
- const checkoutId = cookie.get('checkoutSubscriptionId');
520
- if (!isNil(checkoutId))
521
- return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
522
- return from(this.createCheckoutSubscription(checkoutData));
523
- }
524
- createCheckoutSubscription(checkoutData) {
525
- return __awaiter(this, void 0, void 0, function* () {
526
- const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
527
- cookie.set('checkoutSubscriptionId', checkout.id);
528
- return checkout;
529
- });
530
- }
531
- clearCheckoutSubscriptionFromSession() {
532
- cookie.remove('checkoutSubscriptionId');
533
- return of();
534
- }
535
- checkCoupon(nickname, userEmail) {
536
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, null, true).pipe()));
537
- }
538
- calcDiscountSubscription(coupon) {
539
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
540
- }
541
- }
542
- 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 });
543
- CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService });
544
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
545
- type: Injectable
546
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
547
- type: Inject,
548
- args: ['CheckoutSubscriptionRepository']
549
- }] }, { type: undefined, decorators: [{
550
- type: Inject,
551
- args: ['SubscriptionRepository']
533
+ class CheckoutSubscriptionService {
534
+ constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
535
+ this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
536
+ this.subscriptionRepository = subscriptionRepository;
537
+ this.couponService = couponService;
538
+ }
539
+ getCheckoutSubscription(checkoutData) {
540
+ const checkoutId = cookie.get('checkoutSubscriptionId');
541
+ if (!isNil(checkoutId))
542
+ return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
543
+ return from(this.createCheckoutSubscription(checkoutData));
544
+ }
545
+ createCheckoutSubscription(checkoutData) {
546
+ return __awaiter(this, void 0, void 0, function* () {
547
+ const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
548
+ cookie.set('checkoutSubscriptionId', checkout.id);
549
+ return checkout;
550
+ });
551
+ }
552
+ clearCheckoutSubscriptionFromSession() {
553
+ cookie.remove('checkoutSubscriptionId');
554
+ return of();
555
+ }
556
+ checkCoupon(nickname, userEmail) {
557
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, null, true).pipe()));
558
+ }
559
+ calcDiscountSubscription(coupon) {
560
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
561
+ }
562
+ }
563
+ 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 });
564
+ CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService });
565
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
566
+ type: Injectable
567
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
568
+ type: Inject,
569
+ args: ['CheckoutSubscriptionRepository']
570
+ }] }, { type: undefined, decorators: [{
571
+ type: Inject,
572
+ args: ['SubscriptionRepository']
552
573
  }] }, { type: CouponService }]; } });
553
574
 
554
- class OrderService {
555
- constructor(angularFirestore, orderRepository) {
556
- this.angularFirestore = angularFirestore;
557
- this.orderRepository = orderRepository;
558
- this.orderSubject = new Subject();
559
- }
560
- getOrder(id) {
561
- this.angularFirestore
562
- .doc(`${this.orderRepository.collectionName}/${id}`)
563
- .valueChanges()
564
- .pipe(map((doc) => Order.toInstance(doc)))
565
- .subscribe((doc) => this.orderSubject.next(doc));
566
- return this.orderSubject;
567
- }
568
- }
569
- 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 });
570
- OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
571
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
572
- type: Injectable
573
- }], ctorParameters: function () { return [{ type: i1$1.AngularFirestore }, { type: i2.OrderFirestoreRepository, decorators: [{
574
- type: Inject,
575
- args: ['OrderRepository']
575
+ class OrderService {
576
+ constructor(angularFirestore, orderRepository) {
577
+ this.angularFirestore = angularFirestore;
578
+ this.orderRepository = orderRepository;
579
+ this.orderSubject = new Subject();
580
+ }
581
+ getOrder(id) {
582
+ this.angularFirestore
583
+ .doc(`${this.orderRepository.collectionName}/${id}`)
584
+ .valueChanges()
585
+ .pipe(map((doc) => Order.toInstance(doc)))
586
+ .subscribe((doc) => this.orderSubject.next(doc));
587
+ return this.orderSubject;
588
+ }
589
+ }
590
+ 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 });
591
+ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
592
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
593
+ type: Injectable
594
+ }], ctorParameters: function () { return [{ type: i1$1.AngularFirestore }, { type: i2.OrderFirestoreRepository, decorators: [{
595
+ type: Inject,
596
+ args: ['OrderRepository']
576
597
  }] }]; } });
577
598
 
578
- class HomeShopService {
579
- constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
580
- this.categoryRepository = categoryRepository;
581
- this.homeRepository = homeRepository;
582
- this.productRepository = productRepository;
583
- this.defaultShop = defaultShop;
584
- this.buildCategoryGroupWithRequiredData = (group) => ({
585
- category: Category.toInstance(pick(group.category.toPlain(), ['id', 'name', 'slug', 'conditions'])),
586
- products: group.products.map((product) => Product.toInstance(pick(product.toPlain(), [
587
- 'id',
588
- 'price',
589
- 'reviews',
590
- 'hasVariants',
591
- 'slug',
592
- 'sku',
593
- 'stock',
594
- 'costPrice',
595
- 'images',
596
- 'miniatures',
597
- 'name',
598
- 'weight',
599
- 'rate',
600
- ]))),
601
- });
602
- }
603
- get homeId() {
604
- if (this.defaultShop === Shops.GLAMSHOP)
605
- return 'glamshop';
606
- if (this.defaultShop === Shops.MENSMARKET)
607
- return 'mens_market';
608
- return null;
609
- }
610
- getHomeData() {
611
- 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
612
- ? of(home)
613
- : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
614
- discoverProducts,
615
- featuredProducts,
616
- verticalProducts,
617
- })), concatMap((data) => this.saveHomeData(data)))));
618
- }
619
- getBanners(type) {
620
- return this.getHomeConfiguration().pipe(map((home) => {
621
- if (type === 'brand')
622
- return home.brandsCarousel;
623
- if (type === 'buyToWin')
624
- return [home.buyToWinBanner];
625
- if (type === 'block')
626
- return home.blockBanners;
627
- if (type === 'blog')
628
- return [home.blogBanner];
629
- }));
630
- }
631
- getMinValueForFreeShipping() {
632
- return this.getHomeConfiguration().pipe(map(home => home.minValueForFreeShipping));
633
- }
634
- getDiscoverProducts() {
635
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
636
- }
637
- getFeaturedProducts() {
638
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
639
- }
640
- getVerticalProducts() {
641
- 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({
642
- filters: { categories: { operator: Where.IN, value: [category.id] } },
643
- limits: { limit: 12 },
644
- })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
645
- }
646
- getHomeConfiguration() {
647
- return of(this.homeConfiguration).pipe(concatMap((home) => home
648
- ? of(home)
649
- : !this.homeId
650
- ? throwError(new RequiredArgumentError(['homeId']))
651
- : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
652
- }
653
- saveHomeData(homeData) {
654
- const data = {
655
- createdAt: new Date(),
656
- expiresAt: add(new Date(), { hours: 1 }),
657
- data: homeData,
658
- };
659
- return from(this.homeRepository.update({
660
- id: this.homeId,
661
- data,
662
- })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
663
- }
664
- }
665
- 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 });
666
- HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService });
667
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, decorators: [{
668
- type: Injectable
669
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
670
- type: Inject,
671
- args: ['CategoryRepository']
672
- }] }, { type: undefined, decorators: [{
673
- type: Inject,
674
- args: ['HomeRepository']
675
- }] }, { type: undefined, decorators: [{
676
- type: Inject,
677
- args: ['ProductRepository']
678
- }] }, { type: i2.Shops, decorators: [{
679
- type: Inject,
680
- args: [DEFAULT_SHOP]
599
+ class HomeShopService {
600
+ constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
601
+ this.categoryRepository = categoryRepository;
602
+ this.homeRepository = homeRepository;
603
+ this.productRepository = productRepository;
604
+ this.defaultShop = defaultShop;
605
+ this.buildCategoryGroupWithRequiredData = (group) => ({
606
+ category: Category.toInstance(pick(group.category.toPlain(), ['id', 'name', 'slug', 'conditions'])),
607
+ products: group.products.map((product) => Product.toInstance(pick(product.toPlain(), [
608
+ 'id',
609
+ 'price',
610
+ 'reviews',
611
+ 'hasVariants',
612
+ 'slug',
613
+ 'sku',
614
+ 'stock',
615
+ 'costPrice',
616
+ 'images',
617
+ 'miniatures',
618
+ 'name',
619
+ 'weight',
620
+ 'rate',
621
+ ]))),
622
+ });
623
+ }
624
+ get homeId() {
625
+ if (this.defaultShop === Shops.GLAMSHOP)
626
+ return 'glamshop';
627
+ if (this.defaultShop === Shops.MENSMARKET)
628
+ return 'mens_market';
629
+ return null;
630
+ }
631
+ getHomeData() {
632
+ 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
633
+ ? of(home)
634
+ : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
635
+ discoverProducts,
636
+ featuredProducts,
637
+ verticalProducts,
638
+ })), concatMap((data) => this.saveHomeData(data)))));
639
+ }
640
+ getBanners(type) {
641
+ return this.getHomeConfiguration().pipe(map((home) => {
642
+ if (type === 'brand')
643
+ return home.brandsCarousel;
644
+ if (type === 'buyToWin')
645
+ return [home.buyToWinBanner];
646
+ if (type === 'block')
647
+ return home.blockBanners;
648
+ if (type === 'blog')
649
+ return [home.blogBanner];
650
+ }));
651
+ }
652
+ getMinValueForFreeShipping() {
653
+ return this.getHomeConfiguration().pipe(map(home => home.minValueForFreeShipping));
654
+ }
655
+ getDiscoverProducts() {
656
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
657
+ }
658
+ getFeaturedProducts() {
659
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
660
+ }
661
+ getVerticalProducts() {
662
+ 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({
663
+ filters: { categories: { operator: Where.IN, value: [category.id] } },
664
+ limits: { limit: 12 },
665
+ })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
666
+ }
667
+ getHomeConfiguration() {
668
+ return of(this.homeConfiguration).pipe(concatMap((home) => home
669
+ ? of(home)
670
+ : !this.homeId
671
+ ? throwError(new RequiredArgumentError(['homeId']))
672
+ : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
673
+ }
674
+ saveHomeData(homeData) {
675
+ const data = {
676
+ createdAt: new Date(),
677
+ expiresAt: add(new Date(), { hours: 1 }),
678
+ data: homeData,
679
+ };
680
+ return from(this.homeRepository.update({
681
+ id: this.homeId,
682
+ data,
683
+ })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
684
+ }
685
+ }
686
+ 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 });
687
+ HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService });
688
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, decorators: [{
689
+ type: Injectable
690
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
691
+ type: Inject,
692
+ args: ['CategoryRepository']
693
+ }] }, { type: undefined, decorators: [{
694
+ type: Inject,
695
+ args: ['HomeRepository']
696
+ }] }, { type: undefined, decorators: [{
697
+ type: Inject,
698
+ args: ['ProductRepository']
699
+ }] }, { type: i2.Shops, decorators: [{
700
+ type: Inject,
701
+ args: [DEFAULT_SHOP]
681
702
  }] }]; } });
682
703
 
683
- class AngularFirebaseAuthModule {
684
- static initializeApp(options, nameOrConfig) {
685
- return {
686
- ngModule: AngularFirebaseAuthModule,
687
- providers: [
688
- { provide: FIREBASE_OPTIONS, useValue: options },
689
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
690
- ],
691
- };
692
- }
693
- }
694
- AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
695
- AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
696
- AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
697
- {
698
- provide: 'Authentication',
699
- useFactory: (authenticationService, userRepository) => {
700
- return new Authentication(authenticationService, userRepository);
701
- },
702
- deps: ['AuthenticationService', 'UserRepository'],
703
- },
704
- {
705
- provide: 'AuthenticationService',
706
- useFactory: (angularFireAuth) => {
707
- return new AuthenticationFirebaseAuthService(angularFireAuth);
708
- },
709
- deps: [AngularFireAuth],
710
- },
711
- {
712
- provide: 'Register',
713
- useFactory: (registerService, userRepository) => {
714
- return new Register(registerService, userRepository);
715
- },
716
- deps: ['RegisterService', 'UserRepository'],
717
- },
718
- {
719
- provide: 'RegisterService',
720
- useFactory: (angularFireAuth) => {
721
- return new RegisterFirebaseAuthService(angularFireAuth);
722
- },
723
- deps: [AngularFireAuth],
724
- },
725
- {
726
- provide: 'SignOut',
727
- useFactory: (authenticationService) => {
728
- return new SignOut(authenticationService);
729
- },
730
- deps: ['AuthenticationService'],
731
- },
732
- {
733
- provide: 'RecoveryPassword',
734
- useFactory: (authenticationService) => {
735
- return new RecoveryPassword(authenticationService);
736
- },
737
- deps: ['AuthenticationService'],
738
- },
739
- ], imports: [[AngularFireModule]] });
740
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
741
- type: NgModule,
742
- args: [{
743
- imports: [AngularFireModule],
744
- providers: [
745
- {
746
- provide: 'Authentication',
747
- useFactory: (authenticationService, userRepository) => {
748
- return new Authentication(authenticationService, userRepository);
749
- },
750
- deps: ['AuthenticationService', 'UserRepository'],
751
- },
752
- {
753
- provide: 'AuthenticationService',
754
- useFactory: (angularFireAuth) => {
755
- return new AuthenticationFirebaseAuthService(angularFireAuth);
756
- },
757
- deps: [AngularFireAuth],
758
- },
759
- {
760
- provide: 'Register',
761
- useFactory: (registerService, userRepository) => {
762
- return new Register(registerService, userRepository);
763
- },
764
- deps: ['RegisterService', 'UserRepository'],
765
- },
766
- {
767
- provide: 'RegisterService',
768
- useFactory: (angularFireAuth) => {
769
- return new RegisterFirebaseAuthService(angularFireAuth);
770
- },
771
- deps: [AngularFireAuth],
772
- },
773
- {
774
- provide: 'SignOut',
775
- useFactory: (authenticationService) => {
776
- return new SignOut(authenticationService);
777
- },
778
- deps: ['AuthenticationService'],
779
- },
780
- {
781
- provide: 'RecoveryPassword',
782
- useFactory: (authenticationService) => {
783
- return new RecoveryPassword(authenticationService);
784
- },
785
- deps: ['AuthenticationService'],
786
- },
787
- ],
788
- }]
704
+ class AngularFirebaseAuthModule {
705
+ static initializeApp(options, nameOrConfig) {
706
+ return {
707
+ ngModule: AngularFirebaseAuthModule,
708
+ providers: [
709
+ { provide: FIREBASE_OPTIONS, useValue: options },
710
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
711
+ ],
712
+ };
713
+ }
714
+ }
715
+ AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
716
+ AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
717
+ AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
718
+ {
719
+ provide: 'Authentication',
720
+ useFactory: (authenticationService, userRepository) => {
721
+ return new Authentication(authenticationService, userRepository);
722
+ },
723
+ deps: ['AuthenticationService', 'UserRepository'],
724
+ },
725
+ {
726
+ provide: 'AuthenticationService',
727
+ useFactory: (angularFireAuth) => {
728
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
729
+ },
730
+ deps: [AngularFireAuth],
731
+ },
732
+ {
733
+ provide: 'Register',
734
+ useFactory: (registerService, userRepository) => {
735
+ return new Register(registerService, userRepository);
736
+ },
737
+ deps: ['RegisterService', 'UserRepository'],
738
+ },
739
+ {
740
+ provide: 'RegisterService',
741
+ useFactory: (angularFireAuth) => {
742
+ return new RegisterFirebaseAuthService(angularFireAuth);
743
+ },
744
+ deps: [AngularFireAuth],
745
+ },
746
+ {
747
+ provide: 'SignOut',
748
+ useFactory: (authenticationService) => {
749
+ return new SignOut(authenticationService);
750
+ },
751
+ deps: ['AuthenticationService'],
752
+ },
753
+ {
754
+ provide: 'RecoveryPassword',
755
+ useFactory: (authenticationService) => {
756
+ return new RecoveryPassword(authenticationService);
757
+ },
758
+ deps: ['AuthenticationService'],
759
+ },
760
+ ], imports: [[AngularFireModule]] });
761
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
762
+ type: NgModule,
763
+ args: [{
764
+ imports: [AngularFireModule],
765
+ providers: [
766
+ {
767
+ provide: 'Authentication',
768
+ useFactory: (authenticationService, userRepository) => {
769
+ return new Authentication(authenticationService, userRepository);
770
+ },
771
+ deps: ['AuthenticationService', 'UserRepository'],
772
+ },
773
+ {
774
+ provide: 'AuthenticationService',
775
+ useFactory: (angularFireAuth) => {
776
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
777
+ },
778
+ deps: [AngularFireAuth],
779
+ },
780
+ {
781
+ provide: 'Register',
782
+ useFactory: (registerService, userRepository) => {
783
+ return new Register(registerService, userRepository);
784
+ },
785
+ deps: ['RegisterService', 'UserRepository'],
786
+ },
787
+ {
788
+ provide: 'RegisterService',
789
+ useFactory: (angularFireAuth) => {
790
+ return new RegisterFirebaseAuthService(angularFireAuth);
791
+ },
792
+ deps: [AngularFireAuth],
793
+ },
794
+ {
795
+ provide: 'SignOut',
796
+ useFactory: (authenticationService) => {
797
+ return new SignOut(authenticationService);
798
+ },
799
+ deps: ['AuthenticationService'],
800
+ },
801
+ {
802
+ provide: 'RecoveryPassword',
803
+ useFactory: (authenticationService) => {
804
+ return new RecoveryPassword(authenticationService);
805
+ },
806
+ deps: ['AuthenticationService'],
807
+ },
808
+ ],
809
+ }]
789
810
  }] });
790
811
 
791
- class AngularElasticSeachModule {
792
- static initializeApp(options) {
793
- return {
794
- ngModule: AngularElasticSeachModule,
795
- providers: [{ provide: ES_CONFIG, useValue: options }],
796
- };
797
- }
798
- }
799
- AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
800
- AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule });
801
- AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, providers: [
802
- {
803
- provide: ProductsIndex,
804
- useFactory: (configuration) => {
805
- return new ProductsIndex(new AxiosAdapter(configuration));
806
- },
807
- deps: [ES_CONFIG],
808
- },
809
- ] });
810
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
811
- type: NgModule,
812
- args: [{
813
- providers: [
814
- {
815
- provide: ProductsIndex,
816
- useFactory: (configuration) => {
817
- return new ProductsIndex(new AxiosAdapter(configuration));
818
- },
819
- deps: [ES_CONFIG],
820
- },
821
- ],
822
- }]
812
+ class AngularElasticSeachModule {
813
+ static initializeApp(options) {
814
+ return {
815
+ ngModule: AngularElasticSeachModule,
816
+ providers: [{ provide: ES_CONFIG, useValue: options }],
817
+ };
818
+ }
819
+ }
820
+ AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
821
+ AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule });
822
+ AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, providers: [
823
+ {
824
+ provide: ProductsIndex,
825
+ useFactory: (configuration) => {
826
+ return new ProductsIndex(new AxiosAdapter(configuration));
827
+ },
828
+ deps: [ES_CONFIG],
829
+ },
830
+ ] });
831
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
832
+ type: NgModule,
833
+ args: [{
834
+ providers: [
835
+ {
836
+ provide: ProductsIndex,
837
+ useFactory: (configuration) => {
838
+ return new ProductsIndex(new AxiosAdapter(configuration));
839
+ },
840
+ deps: [ES_CONFIG],
841
+ },
842
+ ],
843
+ }]
823
844
  }] });
824
845
 
825
- class AngularFirestoreModule {
826
- static initializeApp(options, nameOrConfig) {
827
- return {
828
- ngModule: AngularFirestoreModule,
829
- providers: [
830
- { provide: FIREBASE_OPTIONS, useValue: options.firebase },
831
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
832
- { provide: ES_CONFIG, useValue: options.elasticSearch },
833
- ],
834
- };
835
- }
836
- }
837
- AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
838
- AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule, AngularElasticSeachModule] });
839
- AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
840
- {
841
- provide: 'BeautyProfileRepository',
842
- useFactory: (firestore, userRepository) => {
843
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
844
- },
845
- deps: [AngularFirestore, 'UserRepository'],
846
- },
847
- {
848
- provide: 'Buy2WinRepository',
849
- useFactory: (firestore) => {
850
- return new Buy2WinFirestoreRepository(firestore.firestore);
851
- },
852
- deps: [AngularFirestore],
853
- },
854
- {
855
- provide: CategoryFirestoreRepository,
856
- useFactory: (firestore) => {
857
- return new CategoryFirestoreRepository(firestore.firestore);
858
- },
859
- deps: [AngularFirestore],
860
- },
861
- {
862
- provide: 'CheckoutRepository',
863
- useFactory: (firestore) => {
864
- return new CheckoutFirestoreRepository(firestore.firestore);
865
- },
866
- deps: [AngularFirestore],
867
- },
868
- {
869
- provide: 'CheckoutSubscriptionRepository',
870
- useFactory: (firestore) => {
871
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
872
- },
873
- deps: [AngularFirestore],
874
- },
875
- {
876
- provide: 'CouponRepository',
877
- useFactory: (firestore) => {
878
- return new CouponFirestoreRepository(firestore.firestore);
879
- },
880
- deps: [AngularFirestore],
881
- },
882
- {
883
- provide: 'EditionRepository',
884
- useFactory: (firestore, subscriptionRepository) => {
885
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
886
- },
887
- deps: [AngularFirestore, 'SubscriptionRepository'],
888
- },
889
- {
890
- provide: 'HomeRepository',
891
- useFactory: (firestore) => {
892
- return new HomeFirestoreRepository(firestore.firestore);
893
- },
894
- deps: [AngularFirestore],
895
- },
896
- {
897
- provide: 'LeadRepository',
898
- useFactory: (firestore) => {
899
- return new LeadFirestoreRepository(firestore.firestore);
900
- },
901
- deps: [AngularFirestore],
902
- },
903
- {
904
- provide: 'LegacyOrderRepository',
905
- useFactory: (firestore) => {
906
- return new LegacyOrderFirestoreRepository(firestore.firestore);
907
- },
908
- deps: [AngularFirestore],
909
- },
910
- {
911
- provide: 'ShopMenuRepository',
912
- useFactory: (firestore) => {
913
- return new ShopMenuFirestoreRepository(firestore.firestore);
914
- },
915
- deps: [AngularFirestore],
916
- },
917
- {
918
- provide: 'OrderRepository',
919
- useFactory: (firestore) => {
920
- return new OrderFirestoreRepository(firestore.firestore);
921
- },
922
- deps: [AngularFirestore],
923
- },
924
- {
925
- provide: 'PaymentRepository',
926
- useFactory: (firestore) => {
927
- return new PaymentFirestoreRepository(firestore.firestore);
928
- },
929
- deps: [AngularFirestore],
930
- },
931
- {
932
- provide: ProductFirestoreRepository,
933
- useFactory: (firestore) => {
934
- return new ProductFirestoreRepository(firestore.firestore);
935
- },
936
- deps: [AngularFirestore],
937
- },
938
- {
939
- provide: 'SubscriptionPaymentRepository',
940
- useFactory: (firestore, subscriptionRepository) => {
941
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
942
- },
943
- deps: [AngularFirestore, 'SubscriptionRepository'],
944
- },
945
- {
946
- provide: 'SubscriptionPlanRepository',
947
- useFactory: (firestore) => {
948
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
949
- },
950
- deps: [AngularFirestore],
951
- },
952
- {
953
- provide: 'SubscriptionProductRepository',
954
- useFactory: (firestore) => {
955
- return new SubscriptionProductFirestoreRepository(firestore.firestore);
956
- },
957
- deps: [AngularFirestore],
958
- },
959
- {
960
- provide: 'SubscriptionRepository',
961
- useFactory: (firestore) => {
962
- return new SubscriptionFirestoreRepository(firestore.firestore);
963
- },
964
- deps: [AngularFirestore],
965
- },
966
- {
967
- provide: 'UserRepository',
968
- useFactory: (firestore) => {
969
- return new UserFirestoreRepository(firestore.firestore);
970
- },
971
- deps: [AngularFirestore],
972
- },
973
- {
974
- provide: 'UserAddressRepository',
975
- useFactory: (firestore, userRepository) => {
976
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
977
- },
978
- deps: [AngularFirestore, 'UserRepository'],
979
- },
980
- {
981
- provide: 'UserPaymentMethodRepository',
982
- useFactory: (firestore, userRepository) => {
983
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
984
- },
985
- deps: [AngularFirestore, 'UserRepository'],
986
- },
987
- {
988
- provide: ProductVariantFirestoreRepository,
989
- useFactory: (firestore, productRepository) => {
990
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
991
- },
992
- deps: [AngularFirestore, ProductFirestoreRepository],
993
- },
994
- ], imports: [[AngularFireModule, AngularElasticSeachModule]] });
995
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
996
- type: NgModule,
997
- args: [{
998
- imports: [AngularFireModule, AngularElasticSeachModule],
999
- providers: [
1000
- {
1001
- provide: 'BeautyProfileRepository',
1002
- useFactory: (firestore, userRepository) => {
1003
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1004
- },
1005
- deps: [AngularFirestore, 'UserRepository'],
1006
- },
1007
- {
1008
- provide: 'Buy2WinRepository',
1009
- useFactory: (firestore) => {
1010
- return new Buy2WinFirestoreRepository(firestore.firestore);
1011
- },
1012
- deps: [AngularFirestore],
1013
- },
1014
- {
1015
- provide: CategoryFirestoreRepository,
1016
- useFactory: (firestore) => {
1017
- return new CategoryFirestoreRepository(firestore.firestore);
1018
- },
1019
- deps: [AngularFirestore],
1020
- },
1021
- {
1022
- provide: 'CheckoutRepository',
1023
- useFactory: (firestore) => {
1024
- return new CheckoutFirestoreRepository(firestore.firestore);
1025
- },
1026
- deps: [AngularFirestore],
1027
- },
1028
- {
1029
- provide: 'CheckoutSubscriptionRepository',
1030
- useFactory: (firestore) => {
1031
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1032
- },
1033
- deps: [AngularFirestore],
1034
- },
1035
- {
1036
- provide: 'CouponRepository',
1037
- useFactory: (firestore) => {
1038
- return new CouponFirestoreRepository(firestore.firestore);
1039
- },
1040
- deps: [AngularFirestore],
1041
- },
1042
- {
1043
- provide: 'EditionRepository',
1044
- useFactory: (firestore, subscriptionRepository) => {
1045
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1046
- },
1047
- deps: [AngularFirestore, 'SubscriptionRepository'],
1048
- },
1049
- {
1050
- provide: 'HomeRepository',
1051
- useFactory: (firestore) => {
1052
- return new HomeFirestoreRepository(firestore.firestore);
1053
- },
1054
- deps: [AngularFirestore],
1055
- },
1056
- {
1057
- provide: 'LeadRepository',
1058
- useFactory: (firestore) => {
1059
- return new LeadFirestoreRepository(firestore.firestore);
1060
- },
1061
- deps: [AngularFirestore],
1062
- },
1063
- {
1064
- provide: 'LegacyOrderRepository',
1065
- useFactory: (firestore) => {
1066
- return new LegacyOrderFirestoreRepository(firestore.firestore);
1067
- },
1068
- deps: [AngularFirestore],
1069
- },
1070
- {
1071
- provide: 'ShopMenuRepository',
1072
- useFactory: (firestore) => {
1073
- return new ShopMenuFirestoreRepository(firestore.firestore);
1074
- },
1075
- deps: [AngularFirestore],
1076
- },
1077
- {
1078
- provide: 'OrderRepository',
1079
- useFactory: (firestore) => {
1080
- return new OrderFirestoreRepository(firestore.firestore);
1081
- },
1082
- deps: [AngularFirestore],
1083
- },
1084
- {
1085
- provide: 'PaymentRepository',
1086
- useFactory: (firestore) => {
1087
- return new PaymentFirestoreRepository(firestore.firestore);
1088
- },
1089
- deps: [AngularFirestore],
1090
- },
1091
- {
1092
- provide: ProductFirestoreRepository,
1093
- useFactory: (firestore) => {
1094
- return new ProductFirestoreRepository(firestore.firestore);
1095
- },
1096
- deps: [AngularFirestore],
1097
- },
1098
- {
1099
- provide: 'SubscriptionPaymentRepository',
1100
- useFactory: (firestore, subscriptionRepository) => {
1101
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1102
- },
1103
- deps: [AngularFirestore, 'SubscriptionRepository'],
1104
- },
1105
- {
1106
- provide: 'SubscriptionPlanRepository',
1107
- useFactory: (firestore) => {
1108
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1109
- },
1110
- deps: [AngularFirestore],
1111
- },
1112
- {
1113
- provide: 'SubscriptionProductRepository',
1114
- useFactory: (firestore) => {
1115
- return new SubscriptionProductFirestoreRepository(firestore.firestore);
1116
- },
1117
- deps: [AngularFirestore],
1118
- },
1119
- {
1120
- provide: 'SubscriptionRepository',
1121
- useFactory: (firestore) => {
1122
- return new SubscriptionFirestoreRepository(firestore.firestore);
1123
- },
1124
- deps: [AngularFirestore],
1125
- },
1126
- {
1127
- provide: 'UserRepository',
1128
- useFactory: (firestore) => {
1129
- return new UserFirestoreRepository(firestore.firestore);
1130
- },
1131
- deps: [AngularFirestore],
1132
- },
1133
- {
1134
- provide: 'UserAddressRepository',
1135
- useFactory: (firestore, userRepository) => {
1136
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1137
- },
1138
- deps: [AngularFirestore, 'UserRepository'],
1139
- },
1140
- {
1141
- provide: 'UserPaymentMethodRepository',
1142
- useFactory: (firestore, userRepository) => {
1143
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1144
- },
1145
- deps: [AngularFirestore, 'UserRepository'],
1146
- },
1147
- {
1148
- provide: ProductVariantFirestoreRepository,
1149
- useFactory: (firestore, productRepository) => {
1150
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1151
- },
1152
- deps: [AngularFirestore, ProductFirestoreRepository],
1153
- },
1154
- ],
1155
- }]
846
+ class AngularFirestoreModule {
847
+ static initializeApp(options, nameOrConfig) {
848
+ return {
849
+ ngModule: AngularFirestoreModule,
850
+ providers: [
851
+ { provide: FIREBASE_OPTIONS, useValue: options.firebase },
852
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
853
+ { provide: ES_CONFIG, useValue: options.elasticSearch },
854
+ ],
855
+ };
856
+ }
857
+ }
858
+ AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
859
+ AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule, AngularElasticSeachModule] });
860
+ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
861
+ {
862
+ provide: 'BeautyProfileRepository',
863
+ useFactory: (firestore, userRepository) => {
864
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
865
+ },
866
+ deps: [AngularFirestore, 'UserRepository'],
867
+ },
868
+ {
869
+ provide: 'Buy2WinRepository',
870
+ useFactory: (firestore) => {
871
+ return new Buy2WinFirestoreRepository(firestore.firestore);
872
+ },
873
+ deps: [AngularFirestore],
874
+ },
875
+ {
876
+ provide: CategoryFirestoreRepository,
877
+ useFactory: (firestore) => {
878
+ return new CategoryFirestoreRepository(firestore.firestore);
879
+ },
880
+ deps: [AngularFirestore],
881
+ },
882
+ {
883
+ provide: 'CheckoutRepository',
884
+ useFactory: (firestore) => {
885
+ return new CheckoutFirestoreRepository(firestore.firestore);
886
+ },
887
+ deps: [AngularFirestore],
888
+ },
889
+ {
890
+ provide: 'CheckoutSubscriptionRepository',
891
+ useFactory: (firestore) => {
892
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
893
+ },
894
+ deps: [AngularFirestore],
895
+ },
896
+ {
897
+ provide: 'CouponRepository',
898
+ useFactory: (firestore) => {
899
+ return new CouponFirestoreRepository(firestore.firestore);
900
+ },
901
+ deps: [AngularFirestore],
902
+ },
903
+ {
904
+ provide: 'EditionRepository',
905
+ useFactory: (firestore, subscriptionRepository) => {
906
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
907
+ },
908
+ deps: [AngularFirestore, 'SubscriptionRepository'],
909
+ },
910
+ {
911
+ provide: 'HomeRepository',
912
+ useFactory: (firestore) => {
913
+ return new HomeFirestoreRepository(firestore.firestore);
914
+ },
915
+ deps: [AngularFirestore],
916
+ },
917
+ {
918
+ provide: 'LeadRepository',
919
+ useFactory: (firestore) => {
920
+ return new LeadFirestoreRepository(firestore.firestore);
921
+ },
922
+ deps: [AngularFirestore],
923
+ },
924
+ {
925
+ provide: 'LegacyOrderRepository',
926
+ useFactory: (firestore) => {
927
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
928
+ },
929
+ deps: [AngularFirestore],
930
+ },
931
+ {
932
+ provide: 'ShopMenuRepository',
933
+ useFactory: (firestore) => {
934
+ return new ShopMenuFirestoreRepository(firestore.firestore);
935
+ },
936
+ deps: [AngularFirestore],
937
+ },
938
+ {
939
+ provide: 'OrderRepository',
940
+ useFactory: (firestore) => {
941
+ return new OrderFirestoreRepository(firestore.firestore);
942
+ },
943
+ deps: [AngularFirestore],
944
+ },
945
+ {
946
+ provide: 'PaymentRepository',
947
+ useFactory: (firestore) => {
948
+ return new PaymentFirestoreRepository(firestore.firestore);
949
+ },
950
+ deps: [AngularFirestore],
951
+ },
952
+ {
953
+ provide: ProductFirestoreRepository,
954
+ useFactory: (firestore) => {
955
+ return new ProductFirestoreRepository(firestore.firestore);
956
+ },
957
+ deps: [AngularFirestore],
958
+ },
959
+ {
960
+ provide: 'SubscriptionPaymentRepository',
961
+ useFactory: (firestore, subscriptionRepository) => {
962
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
963
+ },
964
+ deps: [AngularFirestore, 'SubscriptionRepository'],
965
+ },
966
+ {
967
+ provide: 'SubscriptionPlanRepository',
968
+ useFactory: (firestore) => {
969
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
970
+ },
971
+ deps: [AngularFirestore],
972
+ },
973
+ {
974
+ provide: 'SubscriptionProductRepository',
975
+ useFactory: (firestore) => {
976
+ return new SubscriptionProductFirestoreRepository(firestore.firestore);
977
+ },
978
+ deps: [AngularFirestore],
979
+ },
980
+ {
981
+ provide: 'SubscriptionRepository',
982
+ useFactory: (firestore) => {
983
+ return new SubscriptionFirestoreRepository(firestore.firestore);
984
+ },
985
+ deps: [AngularFirestore],
986
+ },
987
+ {
988
+ provide: 'UserRepository',
989
+ useFactory: (firestore) => {
990
+ return new UserFirestoreRepository(firestore.firestore);
991
+ },
992
+ deps: [AngularFirestore],
993
+ },
994
+ {
995
+ provide: 'UserAddressRepository',
996
+ useFactory: (firestore, userRepository) => {
997
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
998
+ },
999
+ deps: [AngularFirestore, 'UserRepository'],
1000
+ },
1001
+ {
1002
+ provide: 'UserPaymentMethodRepository',
1003
+ useFactory: (firestore, userRepository) => {
1004
+ return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1005
+ },
1006
+ deps: [AngularFirestore, 'UserRepository'],
1007
+ },
1008
+ {
1009
+ provide: ProductVariantFirestoreRepository,
1010
+ useFactory: (firestore, productRepository) => {
1011
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1012
+ },
1013
+ deps: [AngularFirestore, ProductFirestoreRepository],
1014
+ },
1015
+ ], imports: [[AngularFireModule, AngularElasticSeachModule]] });
1016
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
1017
+ type: NgModule,
1018
+ args: [{
1019
+ imports: [AngularFireModule, AngularElasticSeachModule],
1020
+ providers: [
1021
+ {
1022
+ provide: 'BeautyProfileRepository',
1023
+ useFactory: (firestore, userRepository) => {
1024
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1025
+ },
1026
+ deps: [AngularFirestore, 'UserRepository'],
1027
+ },
1028
+ {
1029
+ provide: 'Buy2WinRepository',
1030
+ useFactory: (firestore) => {
1031
+ return new Buy2WinFirestoreRepository(firestore.firestore);
1032
+ },
1033
+ deps: [AngularFirestore],
1034
+ },
1035
+ {
1036
+ provide: CategoryFirestoreRepository,
1037
+ useFactory: (firestore) => {
1038
+ return new CategoryFirestoreRepository(firestore.firestore);
1039
+ },
1040
+ deps: [AngularFirestore],
1041
+ },
1042
+ {
1043
+ provide: 'CheckoutRepository',
1044
+ useFactory: (firestore) => {
1045
+ return new CheckoutFirestoreRepository(firestore.firestore);
1046
+ },
1047
+ deps: [AngularFirestore],
1048
+ },
1049
+ {
1050
+ provide: 'CheckoutSubscriptionRepository',
1051
+ useFactory: (firestore) => {
1052
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1053
+ },
1054
+ deps: [AngularFirestore],
1055
+ },
1056
+ {
1057
+ provide: 'CouponRepository',
1058
+ useFactory: (firestore) => {
1059
+ return new CouponFirestoreRepository(firestore.firestore);
1060
+ },
1061
+ deps: [AngularFirestore],
1062
+ },
1063
+ {
1064
+ provide: 'EditionRepository',
1065
+ useFactory: (firestore, subscriptionRepository) => {
1066
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1067
+ },
1068
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1069
+ },
1070
+ {
1071
+ provide: 'HomeRepository',
1072
+ useFactory: (firestore) => {
1073
+ return new HomeFirestoreRepository(firestore.firestore);
1074
+ },
1075
+ deps: [AngularFirestore],
1076
+ },
1077
+ {
1078
+ provide: 'LeadRepository',
1079
+ useFactory: (firestore) => {
1080
+ return new LeadFirestoreRepository(firestore.firestore);
1081
+ },
1082
+ deps: [AngularFirestore],
1083
+ },
1084
+ {
1085
+ provide: 'LegacyOrderRepository',
1086
+ useFactory: (firestore) => {
1087
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
1088
+ },
1089
+ deps: [AngularFirestore],
1090
+ },
1091
+ {
1092
+ provide: 'ShopMenuRepository',
1093
+ useFactory: (firestore) => {
1094
+ return new ShopMenuFirestoreRepository(firestore.firestore);
1095
+ },
1096
+ deps: [AngularFirestore],
1097
+ },
1098
+ {
1099
+ provide: 'OrderRepository',
1100
+ useFactory: (firestore) => {
1101
+ return new OrderFirestoreRepository(firestore.firestore);
1102
+ },
1103
+ deps: [AngularFirestore],
1104
+ },
1105
+ {
1106
+ provide: 'PaymentRepository',
1107
+ useFactory: (firestore) => {
1108
+ return new PaymentFirestoreRepository(firestore.firestore);
1109
+ },
1110
+ deps: [AngularFirestore],
1111
+ },
1112
+ {
1113
+ provide: ProductFirestoreRepository,
1114
+ useFactory: (firestore) => {
1115
+ return new ProductFirestoreRepository(firestore.firestore);
1116
+ },
1117
+ deps: [AngularFirestore],
1118
+ },
1119
+ {
1120
+ provide: 'SubscriptionPaymentRepository',
1121
+ useFactory: (firestore, subscriptionRepository) => {
1122
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1123
+ },
1124
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1125
+ },
1126
+ {
1127
+ provide: 'SubscriptionPlanRepository',
1128
+ useFactory: (firestore) => {
1129
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1130
+ },
1131
+ deps: [AngularFirestore],
1132
+ },
1133
+ {
1134
+ provide: 'SubscriptionProductRepository',
1135
+ useFactory: (firestore) => {
1136
+ return new SubscriptionProductFirestoreRepository(firestore.firestore);
1137
+ },
1138
+ deps: [AngularFirestore],
1139
+ },
1140
+ {
1141
+ provide: 'SubscriptionRepository',
1142
+ useFactory: (firestore) => {
1143
+ return new SubscriptionFirestoreRepository(firestore.firestore);
1144
+ },
1145
+ deps: [AngularFirestore],
1146
+ },
1147
+ {
1148
+ provide: 'UserRepository',
1149
+ useFactory: (firestore) => {
1150
+ return new UserFirestoreRepository(firestore.firestore);
1151
+ },
1152
+ deps: [AngularFirestore],
1153
+ },
1154
+ {
1155
+ provide: 'UserAddressRepository',
1156
+ useFactory: (firestore, userRepository) => {
1157
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1158
+ },
1159
+ deps: [AngularFirestore, 'UserRepository'],
1160
+ },
1161
+ {
1162
+ provide: 'UserPaymentMethodRepository',
1163
+ useFactory: (firestore, userRepository) => {
1164
+ return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1165
+ },
1166
+ deps: [AngularFirestore, 'UserRepository'],
1167
+ },
1168
+ {
1169
+ provide: ProductVariantFirestoreRepository,
1170
+ useFactory: (firestore, productRepository) => {
1171
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1172
+ },
1173
+ deps: [AngularFirestore, ProductFirestoreRepository],
1174
+ },
1175
+ ],
1176
+ }]
1156
1177
  }] });
1157
1178
 
1158
- class AngularHasuraGraphQLModule {
1159
- static initializeApp(options) {
1160
- return {
1161
- ngModule: AngularHasuraGraphQLModule,
1162
- providers: [{ provide: HASURA_OPTIONS, useValue: options }],
1163
- };
1164
- }
1165
- }
1166
- AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1167
- AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule });
1168
- AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
1169
- {
1170
- provide: 'CategoryRepository',
1171
- useExisting: CategoryHasuraGraphQLRepository,
1172
- },
1173
- {
1174
- provide: CategoryHasuraGraphQLRepository,
1175
- useFactory: (options, productRepository) => {
1176
- return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository);
1177
- },
1178
- deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository],
1179
- },
1180
- {
1181
- provide: 'ProductRepository',
1182
- useExisting: ProductHasuraGraphQLRepository,
1183
- },
1184
- {
1185
- provide: ProductHasuraGraphQLRepository,
1186
- useFactory: (options) => {
1187
- return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1188
- },
1189
- deps: [HASURA_OPTIONS],
1190
- },
1191
- {
1192
- provide: 'VariantRepository',
1193
- useExisting: VariantHasuraGraphQLRepository,
1194
- },
1195
- {
1196
- provide: VariantHasuraGraphQLRepository,
1197
- useFactory: (options) => {
1198
- return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1199
- },
1200
- deps: [HASURA_OPTIONS],
1201
- },
1202
- ] });
1203
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
1204
- type: NgModule,
1205
- args: [{
1206
- providers: [
1207
- {
1208
- provide: 'CategoryRepository',
1209
- useExisting: CategoryHasuraGraphQLRepository,
1210
- },
1211
- {
1212
- provide: CategoryHasuraGraphQLRepository,
1213
- useFactory: (options, productRepository) => {
1214
- return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository);
1215
- },
1216
- deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository],
1217
- },
1218
- {
1219
- provide: 'ProductRepository',
1220
- useExisting: ProductHasuraGraphQLRepository,
1221
- },
1222
- {
1223
- provide: ProductHasuraGraphQLRepository,
1224
- useFactory: (options) => {
1225
- return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1226
- },
1227
- deps: [HASURA_OPTIONS],
1228
- },
1229
- {
1230
- provide: 'VariantRepository',
1231
- useExisting: VariantHasuraGraphQLRepository,
1232
- },
1233
- {
1234
- provide: VariantHasuraGraphQLRepository,
1235
- useFactory: (options) => {
1236
- return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1237
- },
1238
- deps: [HASURA_OPTIONS],
1239
- },
1240
- ],
1241
- }]
1179
+ class AngularHasuraGraphQLModule {
1180
+ static initializeApp(options) {
1181
+ return {
1182
+ ngModule: AngularHasuraGraphQLModule,
1183
+ providers: [{ provide: HASURA_OPTIONS, useValue: options }],
1184
+ };
1185
+ }
1186
+ }
1187
+ AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1188
+ AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule });
1189
+ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
1190
+ {
1191
+ provide: 'CategoryRepository',
1192
+ useExisting: CategoryHasuraGraphQLRepository,
1193
+ },
1194
+ {
1195
+ provide: CategoryHasuraGraphQLRepository,
1196
+ useFactory: (options, productRepository) => {
1197
+ return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository);
1198
+ },
1199
+ deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository],
1200
+ },
1201
+ {
1202
+ provide: 'ProductRepository',
1203
+ useExisting: ProductHasuraGraphQLRepository,
1204
+ },
1205
+ {
1206
+ provide: ProductHasuraGraphQLRepository,
1207
+ useFactory: (options) => {
1208
+ return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1209
+ },
1210
+ deps: [HASURA_OPTIONS],
1211
+ },
1212
+ {
1213
+ provide: 'VariantRepository',
1214
+ useExisting: VariantHasuraGraphQLRepository,
1215
+ },
1216
+ {
1217
+ provide: VariantHasuraGraphQLRepository,
1218
+ useFactory: (options) => {
1219
+ return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1220
+ },
1221
+ deps: [HASURA_OPTIONS],
1222
+ },
1223
+ ] });
1224
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
1225
+ type: NgModule,
1226
+ args: [{
1227
+ providers: [
1228
+ {
1229
+ provide: 'CategoryRepository',
1230
+ useExisting: CategoryHasuraGraphQLRepository,
1231
+ },
1232
+ {
1233
+ provide: CategoryHasuraGraphQLRepository,
1234
+ useFactory: (options, productRepository) => {
1235
+ return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository);
1236
+ },
1237
+ deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository],
1238
+ },
1239
+ {
1240
+ provide: 'ProductRepository',
1241
+ useExisting: ProductHasuraGraphQLRepository,
1242
+ },
1243
+ {
1244
+ provide: ProductHasuraGraphQLRepository,
1245
+ useFactory: (options) => {
1246
+ return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1247
+ },
1248
+ deps: [HASURA_OPTIONS],
1249
+ },
1250
+ {
1251
+ provide: 'VariantRepository',
1252
+ useExisting: VariantHasuraGraphQLRepository,
1253
+ },
1254
+ {
1255
+ provide: VariantHasuraGraphQLRepository,
1256
+ useFactory: (options) => {
1257
+ return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1258
+ },
1259
+ deps: [HASURA_OPTIONS],
1260
+ },
1261
+ ],
1262
+ }]
1242
1263
  }] });
1243
1264
 
1244
- class AngularConnectModule {
1245
- static initializeApp(defaultShop, options, nameOrConfig) {
1246
- return {
1247
- ngModule: AngularConnectModule,
1248
- providers: [
1249
- ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
1250
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
1251
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
1252
- ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
1253
- ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
1254
- ],
1255
- };
1256
- }
1257
- }
1258
- AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1259
- AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
1260
- AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [
1261
- AuthService,
1262
- CartService,
1263
- CheckoutService,
1264
- CheckoutSubscriptionService,
1265
- CouponService,
1266
- HomeShopService,
1267
- OrderService,
1268
- ], imports: [[AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
1269
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
1270
- type: NgModule,
1271
- args: [{
1272
- imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule],
1273
- providers: [
1274
- AuthService,
1275
- CartService,
1276
- CheckoutService,
1277
- CheckoutSubscriptionService,
1278
- CouponService,
1279
- HomeShopService,
1280
- OrderService,
1281
- ],
1282
- }]
1265
+ class AngularConnectModule {
1266
+ static initializeApp(defaultShop, options, nameOrConfig) {
1267
+ return {
1268
+ ngModule: AngularConnectModule,
1269
+ providers: [
1270
+ ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
1271
+ ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
1272
+ ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
1273
+ ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
1274
+ ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
1275
+ ],
1276
+ };
1277
+ }
1278
+ }
1279
+ AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1280
+ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
1281
+ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [
1282
+ AuthService,
1283
+ CartService,
1284
+ CheckoutService,
1285
+ CheckoutSubscriptionService,
1286
+ CouponService,
1287
+ HomeShopService,
1288
+ OrderService,
1289
+ ], imports: [[AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
1290
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
1291
+ type: NgModule,
1292
+ args: [{
1293
+ imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule],
1294
+ providers: [
1295
+ AuthService,
1296
+ CartService,
1297
+ CheckoutService,
1298
+ CheckoutSubscriptionService,
1299
+ CouponService,
1300
+ HomeShopService,
1301
+ OrderService,
1302
+ ],
1303
+ }]
1283
1304
  }] });
1284
1305
 
1285
- /**
1286
- * Generated bundle index. Do not edit.
1306
+ /**
1307
+ * Generated bundle index. Do not edit.
1287
1308
  */
1288
1309
 
1289
1310
  export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService };