@infrab4a/connect-angular 2.0.8 → 2.0.9

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