@infrab4a/connect-angular 3.7.7 → 3.7.8-beta.1

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