@infrab4a/connect-angular 3.9.0-beta.7 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +2142 -2140
  7. package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
  8. package/consts/backend-url.const.d.ts +1 -1
  9. package/consts/default-shop.const.d.ts +1 -1
  10. package/consts/es-config.const.d.ts +1 -1
  11. package/consts/hasura-options.const.d.ts +1 -1
  12. package/consts/index.d.ts +4 -4
  13. package/esm2015/angular-connect.module.js +52 -52
  14. package/esm2015/angular-elastic-search.module.js +34 -34
  15. package/esm2015/angular-firebase-auth.module.js +113 -113
  16. package/esm2015/angular-firestore.module.js +394 -394
  17. package/esm2015/angular-hasura-graphql.module.js +156 -156
  18. package/esm2015/consts/backend-url.const.js +1 -1
  19. package/esm2015/consts/default-shop.const.js +2 -2
  20. package/esm2015/consts/es-config.const.js +2 -2
  21. package/esm2015/consts/hasura-options.const.js +2 -2
  22. package/esm2015/consts/index.js +5 -5
  23. package/esm2015/index.js +6 -6
  24. package/esm2015/infrab4a-connect-angular.js +4 -4
  25. package/esm2015/services/auth.service.js +42 -42
  26. package/esm2015/services/cart.service.js +261 -259
  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 +1561 -1559
  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 +2 -2
  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 ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
36
- }
37
- getTokenId() {
38
- return this.angularFireAuth.idToken;
39
- }
40
- getFireUser() {
41
- return this.angularFireAuth.user.pipe(catchError(() => of(null)));
42
- }
43
- }
44
- AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, deps: [{ token: i1.AngularFireAuth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
45
- AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService });
46
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, decorators: [{
47
- type: Injectable
48
- }], ctorParameters: function () { return [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
49
- type: Inject,
50
- args: ['UserRepository']
17
+ class AuthService {
18
+ constructor(angularFireAuth, userRepository) {
19
+ this.angularFireAuth = angularFireAuth;
20
+ this.userRepository = userRepository;
21
+ }
22
+ getAuthstate() {
23
+ const observables = [
24
+ this.angularFireAuth.authState.pipe(catchError(() => of(null))),
25
+ this.getUser().pipe(catchError(() => of(null))),
26
+ ];
27
+ return combineLatest(observables).pipe(map(([fireUser, user]) => {
28
+ return {
29
+ user,
30
+ isAnonymous: fireUser === null || fireUser === void 0 ? void 0 : fireUser.isAnonymous,
31
+ };
32
+ }));
33
+ }
34
+ getUser() {
35
+ return this.getFireUser().pipe(map((user) => user === null || user === void 0 ? void 0 : user.uid), mergeMap((id) => (id ? from(this.userRepository.get({ id })).pipe(catchError(() => of(null))) : of(null))));
36
+ }
37
+ getTokenId() {
38
+ return this.angularFireAuth.idToken;
39
+ }
40
+ getFireUser() {
41
+ return this.angularFireAuth.user.pipe(catchError(() => of(null)));
42
+ }
43
+ }
44
+ AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, deps: [{ token: i1.AngularFireAuth }, { token: 'UserRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
45
+ AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService });
46
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AuthService, decorators: [{
47
+ type: Injectable
48
+ }], ctorParameters: function () { return [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
49
+ type: Inject,
50
+ args: ['UserRepository']
51
51
  }] }]; } });
52
52
 
53
53
  const BACKEND_URL = 'BACKEND_URL';
@@ -58,1559 +58,1561 @@ 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.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.id] || item)), { quantity: (((_a = cart[item.id]) === 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.id === item.id)) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
410
- if (this.checkMaxStock(item, quantity || 0))
411
- throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
412
- const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
413
- const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
414
- const isGift = item.isGift || null;
415
- const pricePaid = this.getProductPrice({
416
- product: item,
417
- shop: checkout.shop || this.defaultShop,
418
- isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
419
- });
420
- 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.id === item.id);
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.id === item.id);
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 notGiftItems = checkout.lineItems.filter((item) => !item.isGift);
523
- if (!notGiftItems.length)
524
- return Object.assign(Object.assign({}, checkout), { lineItems: [] });
525
- const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
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
- if (!campaigns.length)
535
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
536
- const elegibleCampaigns = [];
537
- for (const campaign of campaigns) {
538
- const today = new Date();
539
- if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
540
- continue;
541
- if (campaign.activeCategory) {
542
- const categoriesCampaing = campaign.categories.map((c) => c.id);
543
- const filterProductsCategories = checkout.lineItems.filter((l) => {
544
- var _a;
545
- if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
546
- return true;
547
- return l.categories.some((c) => categoriesCampaing.some((cat) => cat == c));
548
- });
549
- if (filterProductsCategories.length) {
550
- const cartTotalCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
551
- if (cartTotalCategories >= campaign.cartValueMin)
552
- elegibleCampaigns.push(campaign);
553
- }
554
- }
555
- else {
556
- if (campaign.cartValue && campaign.cartValue > 0) {
557
- if (campaign.cartValue <= cartTotal)
558
- elegibleCampaigns.push(campaign);
559
- }
560
- }
561
- }
562
- if (!elegibleCampaigns.length)
563
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
564
- const campaingnProducts = [];
565
- for (const campaign of elegibleCampaigns) {
566
- let elegibleProducts = [];
567
- for (const product of campaign.products) {
568
- const { data: productData } = yield this.productRepository.find({ filters: { sku: product } });
569
- if (!productData.length)
570
- continue;
571
- const gift = productData.shift();
572
- if (gift.stock.quantity < 1)
573
- continue;
574
- elegibleProducts.push(gift);
575
- }
576
- campaingnProducts.push(elegibleProducts);
577
- }
578
- if (!campaingnProducts.length)
579
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
580
- const gifts = this.giftToLineItems([].concat(...campaingnProducts));
581
- return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
582
- })), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
583
- }
584
- giftToLineItems(items) {
585
- return items.map((item) => {
586
- var _a;
587
- const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
588
- 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];
589
- return LineItem.toInstance({
590
- brand,
591
- categories,
592
- id: id.toString(),
593
- name,
594
- price,
595
- sku,
596
- slug,
597
- stock,
598
- weight,
599
- EAN,
600
- image,
601
- pricePaid: 0,
602
- quantity: 1,
603
- isGift: true,
604
- });
605
- });
606
- }
607
- }
608
- 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 });
609
- CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
610
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
611
- type: Injectable
612
- }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
613
- type: Inject,
614
- args: [DEFAULT_SHOP]
615
- }] }, { type: undefined, decorators: [{
616
- type: Inject,
617
- args: ['ProductRepository']
618
- }] }, { type: undefined, decorators: [{
619
- type: Inject,
620
- args: ['VariantRepository']
621
- }] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
622
- type: Inject,
623
- 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
403
+ ? items.reduce((cart, item) => {
404
+ var _a;
405
+ return (Object.assign(Object.assign({}, cart), { [item.id]: LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.id] || item)), { quantity: (((_a = cart[item.id]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })) }));
406
+ }, {})
407
+ : [];
408
+ this.buildLineItem = ({ checkout, item, quantity, }) => __awaiter(this, void 0, void 0, function* () {
409
+ var _a, _b, _c, _d, _e, _f, _g;
410
+ const product = yield this.getProductData(item.id);
411
+ item.quantity = (item === null || item === void 0 ? void 0 : item.quantity) || ((_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id)) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
412
+ if (this.checkMaxStock(item, quantity || 0))
413
+ throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
414
+ const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
415
+ const { id, name, EAN, slug, stock, price, weight, sku, type } = item;
416
+ const isGift = item.isGift || null;
417
+ const pricePaid = this.getProductPrice({
418
+ product: item,
419
+ shop: checkout.shop || this.defaultShop,
420
+ isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
421
+ });
422
+ return {
423
+ checkout,
424
+ lineItem: LineItem.toInstance({
425
+ id,
426
+ name: name !== null && name !== void 0 ? name : product.name,
427
+ EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
428
+ brand: product.brand,
429
+ slug: slug !== null && slug !== void 0 ? slug : product.slug,
430
+ sku: sku !== null && sku !== void 0 ? sku : product.sku,
431
+ stock,
432
+ price,
433
+ image,
434
+ weight: weight !== null && weight !== void 0 ? weight : product.weight,
435
+ quantity: (item.quantity || 0) + (quantity || 0),
436
+ pricePaid,
437
+ categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
438
+ isGift: isGift !== null && isGift !== void 0 ? isGift : null,
439
+ costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
440
+ type,
441
+ }),
442
+ };
443
+ });
444
+ this.getProductPrice = ({ product, isSubscriber, }) => {
445
+ const info = product.price;
446
+ if (product.isGift)
447
+ return 0;
448
+ return isSubscriber && info.subscriberPrice > 0 ? info.subscriberPrice : info.price;
449
+ };
450
+ this.checkMaxStock = (item, quantity) => {
451
+ var _a;
452
+ const maxStock = ((_a = item.stock) === null || _a === void 0 ? void 0 : _a.quantity) || 0;
453
+ const currentItemAmount = item.quantity || 0;
454
+ return currentItemAmount + quantity > maxStock;
455
+ };
456
+ }
457
+ addItem(item, quantity = 1) {
458
+ 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)));
459
+ }
460
+ decreaseItem(item) {
461
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
462
+ var _a;
463
+ const checkoutItem = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find((lineItem) => lineItem.id === item.id);
464
+ if (!isNil(checkoutItem))
465
+ checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
466
+ return checkout;
467
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
468
+ }
469
+ getCart(checkout) {
470
+ this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
471
+ return this.cartSubject;
472
+ }
473
+ /**
474
+ * @deprecated The method should not be used
475
+ */
476
+ getVariantPriceDiscount(item) {
477
+ 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)));
478
+ }
479
+ removeItem(item) {
480
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
481
+ const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
482
+ if (index >= 0)
483
+ checkout.lineItems.splice(index, 1);
484
+ return checkout;
485
+ }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
486
+ }
487
+ updateUserCart(user) {
488
+ 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* () {
489
+ var _a, _b;
490
+ return this.checkoutService
491
+ .updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length)
492
+ ? 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; })))
493
+ : [] })))
494
+ .toPromise();
495
+ })), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
496
+ }
497
+ clearCart() {
498
+ return this.checkoutService.getCheckout().pipe(map((checkout) => {
499
+ this.checkoutService.clearCheckoutFromSession();
500
+ return checkout;
501
+ }), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
502
+ }
503
+ buildCartFromCheckout(checkoutData) {
504
+ return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
505
+ }
506
+ getProductData(productId) {
507
+ return __awaiter(this, void 0, void 0, function* () {
508
+ let product;
509
+ let variant;
510
+ try {
511
+ product = yield this.productRepository.get({ id: productId });
512
+ }
513
+ catch (error) {
514
+ if (!(error instanceof NotFoundError))
515
+ throw error;
516
+ variant = yield this.variantRepository.get({ id: productId });
517
+ product = yield this.productRepository.get({ id: variant.productId });
518
+ }
519
+ return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
520
+ });
521
+ }
522
+ getGifts() {
523
+ return this.checkoutService.getCheckout().pipe(mergeMap((checkout) => __awaiter(this, void 0, void 0, function* () {
524
+ const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
525
+ if (!notGiftItems.length)
526
+ return Object.assign(Object.assign({}, checkout), { lineItems: [] });
527
+ const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
528
+ const campaigns = yield this.buy2WinRepository
529
+ .find({
530
+ filters: {
531
+ active: { operator: Where.EQUALS, value: true },
532
+ shop: { operator: Where.EQUALS, value: this.defaultShop },
533
+ },
534
+ })
535
+ .then((data) => data.data);
536
+ if (!campaigns.length)
537
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
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 { data: productData } = yield this.productRepository.find({ filters: { sku: product } });
571
+ if (!productData.length)
572
+ continue;
573
+ const gift = productData.shift();
574
+ if (gift.stock.quantity < 1)
575
+ continue;
576
+ elegibleProducts.push(gift);
577
+ }
578
+ campaingnProducts.push(elegibleProducts);
579
+ }
580
+ if (!campaingnProducts.length)
581
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
582
+ const gifts = this.giftToLineItems([].concat(...campaingnProducts));
583
+ return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
584
+ })), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
585
+ }
586
+ giftToLineItems(items) {
587
+ return items.map((item) => {
588
+ var _a;
589
+ const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
590
+ 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];
591
+ return LineItem.toInstance({
592
+ brand,
593
+ categories,
594
+ id: id.toString(),
595
+ name,
596
+ price,
597
+ sku,
598
+ slug,
599
+ stock,
600
+ weight,
601
+ EAN,
602
+ image,
603
+ pricePaid: 0,
604
+ quantity: 1,
605
+ isGift: true,
606
+ });
607
+ });
608
+ }
609
+ }
610
+ 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 });
611
+ CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
612
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
613
+ type: Injectable
614
+ }], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i3.Shops, decorators: [{
615
+ type: Inject,
616
+ args: [DEFAULT_SHOP]
617
+ }] }, { type: undefined, decorators: [{
618
+ type: Inject,
619
+ args: ['ProductRepository']
620
+ }] }, { type: undefined, decorators: [{
621
+ type: Inject,
622
+ args: ['VariantRepository']
623
+ }] }, { type: i3.Buy2WinFirestoreRepository, decorators: [{
624
+ type: Inject,
625
+ args: ['Buy2WinRepository']
624
626
  }] }]; } });
625
627
 
626
- class CheckoutSubscriptionService {
627
- constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
628
- this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
629
- this.subscriptionRepository = subscriptionRepository;
630
- this.couponService = couponService;
631
- }
632
- getCheckoutSubscription(checkoutData) {
633
- const checkoutId = cookie.get('checkoutSubscriptionId');
634
- if (!isNil(checkoutId))
635
- return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
636
- return from(this.createCheckoutSubscription(checkoutData));
637
- }
638
- createCheckoutSubscription(checkoutData) {
639
- return __awaiter(this, void 0, void 0, function* () {
640
- const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
641
- cookie.set('checkoutSubscriptionId', checkout.id);
642
- return checkout;
643
- });
644
- }
645
- clearCheckoutSubscriptionFromSession() {
646
- cookie.remove('checkoutSubscriptionId');
647
- return of();
648
- }
649
- checkCoupon(nickname, userEmail) {
650
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
651
- .checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, checkout, true)
652
- .pipe()));
653
- }
654
- calcDiscountSubscription(coupon) {
655
- return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
656
- }
657
- }
658
- 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 });
659
- CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService });
660
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
661
- type: Injectable
662
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
663
- type: Inject,
664
- args: ['CheckoutSubscriptionRepository']
665
- }] }, { type: undefined, decorators: [{
666
- type: Inject,
667
- args: ['SubscriptionRepository']
628
+ class CheckoutSubscriptionService {
629
+ constructor(checkoutSubscriptionRepository, subscriptionRepository, couponService) {
630
+ this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
631
+ this.subscriptionRepository = subscriptionRepository;
632
+ this.couponService = couponService;
633
+ }
634
+ getCheckoutSubscription(checkoutData) {
635
+ const checkoutId = cookie.get('checkoutSubscriptionId');
636
+ if (!isNil(checkoutId))
637
+ return from(this.checkoutSubscriptionRepository.get({ id: checkoutId }));
638
+ return from(this.createCheckoutSubscription(checkoutData));
639
+ }
640
+ createCheckoutSubscription(checkoutData) {
641
+ return __awaiter(this, void 0, void 0, function* () {
642
+ const checkout = yield this.checkoutSubscriptionRepository.create(Object.assign({ createdAt: new Date() }, CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain()));
643
+ cookie.set('checkoutSubscriptionId', checkout.id);
644
+ return checkout;
645
+ });
646
+ }
647
+ clearCheckoutSubscriptionFromSession() {
648
+ cookie.remove('checkoutSubscriptionId');
649
+ return of();
650
+ }
651
+ checkCoupon(nickname, userEmail) {
652
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService
653
+ .checkCoupon(nickname, userEmail, CheckoutTypes.SUBSCRIPTION, checkout.subscriptionPlan.name, checkout, true)
654
+ .pipe()));
655
+ }
656
+ calcDiscountSubscription(coupon) {
657
+ return this.getCheckoutSubscription().pipe(concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()));
658
+ }
659
+ }
660
+ 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 });
661
+ CheckoutSubscriptionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService });
662
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CheckoutSubscriptionService, decorators: [{
663
+ type: Injectable
664
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
665
+ type: Inject,
666
+ args: ['CheckoutSubscriptionRepository']
667
+ }] }, { type: undefined, decorators: [{
668
+ type: Inject,
669
+ args: ['SubscriptionRepository']
668
670
  }] }, { type: CouponService }]; } });
669
671
 
670
- class HomeShopService {
671
- constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
672
- this.categoryRepository = categoryRepository;
673
- this.homeRepository = homeRepository;
674
- this.productRepository = productRepository;
675
- this.defaultShop = defaultShop;
676
- this.buildCategoryGroupWithRequiredData = (group) => {
677
- var _a, _b;
678
- return ({
679
- 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'])),
680
- 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()) || {}, [
681
- 'id',
682
- 'price',
683
- 'reviews',
684
- 'hasVariants',
685
- 'slug',
686
- 'sku',
687
- 'stock',
688
- 'costPrice',
689
- 'images',
690
- 'miniatures',
691
- 'name',
692
- 'weight',
693
- 'rate',
694
- 'type',
695
- ])))) || [],
696
- });
697
- };
698
- }
699
- get homeId() {
700
- if (this.defaultShop === Shops.GLAMSHOP)
701
- return 'glamshop';
702
- if (this.defaultShop === Shops.MENSMARKET)
703
- return 'mens_market';
704
- return null;
705
- }
706
- getHomeData() {
707
- 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
708
- ? of(home)
709
- : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
710
- discoverProducts,
711
- featuredProducts,
712
- verticalProducts,
713
- })), concatMap((data) => this.saveHomeData(data)))));
714
- }
715
- getBanners(type) {
716
- return this.getHomeConfiguration().pipe(map((home) => {
717
- if (type === 'brand')
718
- return home.brandsCarousel;
719
- if (type === 'buyToWin')
720
- return [home.buyToWinBanner];
721
- if (type === 'block')
722
- return home.blockBanners;
723
- if (type === 'blog')
724
- return [home.blogBanner];
725
- }));
726
- }
727
- getMinValueForFreeShipping() {
728
- return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
729
- }
730
- getDiscoverProducts() {
731
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
732
- }
733
- getFeaturedProducts() {
734
- return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
735
- }
736
- getVerticalProducts() {
737
- 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({
738
- filters: { categories: { operator: Where.IN, value: [category.id] } },
739
- limits: { limit: 12 },
740
- })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
741
- }
742
- getHomeConfiguration() {
743
- return of(this.homeConfiguration).pipe(concatMap((home) => home
744
- ? of(home)
745
- : !this.homeId
746
- ? throwError(new RequiredArgumentError(['homeId']))
747
- : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
748
- }
749
- saveHomeData(homeData) {
750
- const data = {
751
- createdAt: new Date(),
752
- expiresAt: add(new Date(), { hours: 1 }),
753
- data: homeData,
754
- };
755
- return from(this.homeRepository.update({
756
- id: this.homeId,
757
- data,
758
- })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
759
- }
760
- }
761
- 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 });
762
- HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService });
763
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, decorators: [{
764
- type: Injectable
765
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
766
- type: Inject,
767
- args: ['CategoryRepository']
768
- }] }, { type: undefined, decorators: [{
769
- type: Inject,
770
- args: ['HomeRepository']
771
- }] }, { type: undefined, decorators: [{
772
- type: Inject,
773
- args: ['ProductRepository']
774
- }] }, { type: i3.Shops, decorators: [{
775
- type: Inject,
776
- args: [DEFAULT_SHOP]
672
+ class HomeShopService {
673
+ constructor(categoryRepository, homeRepository, productRepository, defaultShop) {
674
+ this.categoryRepository = categoryRepository;
675
+ this.homeRepository = homeRepository;
676
+ this.productRepository = productRepository;
677
+ this.defaultShop = defaultShop;
678
+ this.buildCategoryGroupWithRequiredData = (group) => {
679
+ var _a, _b;
680
+ return ({
681
+ 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'])),
682
+ 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()) || {}, [
683
+ 'id',
684
+ 'price',
685
+ 'reviews',
686
+ 'hasVariants',
687
+ 'slug',
688
+ 'sku',
689
+ 'stock',
690
+ 'costPrice',
691
+ 'images',
692
+ 'miniatures',
693
+ 'name',
694
+ 'weight',
695
+ 'rate',
696
+ 'type',
697
+ ])))) || [],
698
+ });
699
+ };
700
+ }
701
+ get homeId() {
702
+ if (this.defaultShop === Shops.GLAMSHOP)
703
+ return 'glamshop';
704
+ if (this.defaultShop === Shops.MENSMARKET)
705
+ return 'mens_market';
706
+ return null;
707
+ }
708
+ getHomeData() {
709
+ 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
710
+ ? of(home)
711
+ : forkJoin([this.getDiscoverProducts(), this.getFeaturedProducts(), this.getVerticalProducts()]).pipe(map(([discoverProducts, featuredProducts, verticalProducts]) => ({
712
+ discoverProducts,
713
+ featuredProducts,
714
+ verticalProducts,
715
+ })), concatMap((data) => this.saveHomeData(data)))));
716
+ }
717
+ getBanners(type) {
718
+ return this.getHomeConfiguration().pipe(map((home) => {
719
+ if (type === 'brand')
720
+ return home.brandsCarousel;
721
+ if (type === 'buyToWin')
722
+ return [home.buyToWinBanner];
723
+ if (type === 'block')
724
+ return home.blockBanners;
725
+ if (type === 'blog')
726
+ return [home.blogBanner];
727
+ }));
728
+ }
729
+ getMinValueForFreeShipping() {
730
+ return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
731
+ }
732
+ getDiscoverProducts() {
733
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
734
+ }
735
+ getFeaturedProducts() {
736
+ return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.featuredCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
737
+ }
738
+ getVerticalProducts() {
739
+ 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({
740
+ filters: { categories: { operator: Where.IN, value: [category.id] } },
741
+ limits: { limit: 12 },
742
+ })).pipe(map((products) => ({ category, products })))), map(({ category, products }) => ({ category, products: products.data })), map(this.buildCategoryGroupWithRequiredData))))));
743
+ }
744
+ getHomeConfiguration() {
745
+ return of(this.homeConfiguration).pipe(concatMap((home) => home
746
+ ? of(home)
747
+ : !this.homeId
748
+ ? throwError(new RequiredArgumentError(['homeId']))
749
+ : from(this.homeRepository.get({ id: this.homeId })).pipe(tap((homeLoaded) => (this.homeConfiguration = homeLoaded)))));
750
+ }
751
+ saveHomeData(homeData) {
752
+ const data = {
753
+ createdAt: new Date(),
754
+ expiresAt: add(new Date(), { hours: 1 }),
755
+ data: homeData,
756
+ };
757
+ return from(this.homeRepository.update({
758
+ id: this.homeId,
759
+ data,
760
+ })).pipe(tap(() => (this.homeConfiguration.data = data)), map(() => this.homeConfiguration));
761
+ }
762
+ }
763
+ 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 });
764
+ HomeShopService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService });
765
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: HomeShopService, decorators: [{
766
+ type: Injectable
767
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
768
+ type: Inject,
769
+ args: ['CategoryRepository']
770
+ }] }, { type: undefined, decorators: [{
771
+ type: Inject,
772
+ args: ['HomeRepository']
773
+ }] }, { type: undefined, decorators: [{
774
+ type: Inject,
775
+ args: ['ProductRepository']
776
+ }] }, { type: i3.Shops, decorators: [{
777
+ type: Inject,
778
+ args: [DEFAULT_SHOP]
777
779
  }] }]; } });
778
780
 
779
- class OrderService {
780
- constructor(angularFirestore, orderRepository) {
781
- this.angularFirestore = angularFirestore;
782
- this.orderRepository = orderRepository;
783
- this.orderSubject = new Subject();
784
- }
785
- getOrder(id) {
786
- this.angularFirestore
787
- .doc(`${this.orderRepository.collectionName}/${id}`)
788
- .valueChanges()
789
- .pipe(map((doc) => Order.toInstance(doc)))
790
- .subscribe((doc) => this.orderSubject.next(doc));
791
- return this.orderSubject;
792
- }
793
- }
794
- 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 });
795
- OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
796
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
797
- type: Injectable
798
- }], ctorParameters: function () { return [{ type: i1$1.AngularFirestore }, { type: i3.OrderFirestoreRepository, decorators: [{
799
- type: Inject,
800
- args: ['OrderRepository']
781
+ class OrderService {
782
+ constructor(angularFirestore, orderRepository) {
783
+ this.angularFirestore = angularFirestore;
784
+ this.orderRepository = orderRepository;
785
+ this.orderSubject = new Subject();
786
+ }
787
+ getOrder(id) {
788
+ this.angularFirestore
789
+ .doc(`${this.orderRepository.collectionName}/${id}`)
790
+ .valueChanges()
791
+ .pipe(map((doc) => Order.toInstance(doc)))
792
+ .subscribe((doc) => this.orderSubject.next(doc));
793
+ return this.orderSubject;
794
+ }
795
+ }
796
+ 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 });
797
+ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService });
798
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: OrderService, decorators: [{
799
+ type: Injectable
800
+ }], ctorParameters: function () { return [{ type: i1$1.AngularFirestore }, { type: i3.OrderFirestoreRepository, decorators: [{
801
+ type: Inject,
802
+ args: ['OrderRepository']
801
803
  }] }]; } });
802
804
 
803
- class ShippingService {
804
- constructor(http, apiUrl, homeService) {
805
- this.http = http;
806
- this.apiUrl = apiUrl;
807
- this.homeService = homeService;
808
- }
809
- getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
810
- return combineLatest([
811
- this.homeService.getHomeData(),
812
- this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
813
- ]).pipe(map(([datas, shippingMethodsResponse]) => {
814
- let shippingMethods = shippingMethodsResponse.result;
815
- if (!shippingMethods.length)
816
- return [];
817
- shippingMethods = shippingMethods.map((s) => {
818
- if (s.ShippingCompanyName == 'Same Day EG')
819
- s.ShippingCompanyName = 'Same Day';
820
- else
821
- return s;
822
- });
823
- const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
824
- if (this.isHolidays(datasSameDayNotAvaliable)) {
825
- shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
826
- }
827
- if (totalPrice >= 200) {
828
- shippingMethods = shippingMethods.map((s) => {
829
- if (s.serviceName !== 'Same Day')
830
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
831
- else
832
- return s;
833
- });
834
- }
835
- if (shop == Shops.GLAMSHOP)
836
- return shippingMethods;
837
- if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
838
- shippingMethods = shippingMethods.map((s) => {
839
- if (s.serviceName == 'Same Day')
840
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
841
- else
842
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
843
- });
844
- }
845
- if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
846
- shippingMethods = shippingMethods.map((s) => {
847
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
848
- });
849
- }
850
- return shippingMethods;
851
- }));
852
- }
853
- isFreeShippingBySubscription(shop, subscriptionPlan) {
854
- if (!subscriptionPlan)
855
- return false;
856
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT') {
857
- return true;
858
- }
859
- return false;
860
- }
861
- isHalfShippingBySubscription(shop, subscriptionPlan) {
862
- if (!subscriptionPlan)
863
- return false;
864
- if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
865
- return true;
866
- }
867
- return false;
868
- }
869
- isHolidays(datas) {
870
- const today = new Date();
871
- for (const key in datas) {
872
- let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
873
- let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
874
- if (start > end)
875
- end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
876
- if (today >= start && today <= end)
877
- return true;
878
- }
879
- return false;
880
- }
881
- }
882
- 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 });
883
- ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService });
884
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, decorators: [{
885
- type: Injectable
886
- }], ctorParameters: function () { return [{ type: i1$2.HttpClient }, { type: undefined, decorators: [{
887
- type: Inject,
888
- args: [BACKEND_URL]
805
+ class ShippingService {
806
+ constructor(http, apiUrl, homeService) {
807
+ this.http = http;
808
+ this.apiUrl = apiUrl;
809
+ this.homeService = homeService;
810
+ }
811
+ getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
812
+ return combineLatest([
813
+ this.homeService.getHomeData(),
814
+ this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
815
+ ]).pipe(map(([datas, shippingMethodsResponse]) => {
816
+ let shippingMethods = shippingMethodsResponse.result;
817
+ if (!shippingMethods.length)
818
+ return [];
819
+ shippingMethods = shippingMethods.map((s) => {
820
+ if (s.ShippingCompanyName == 'Same Day EG')
821
+ s.ShippingCompanyName = 'Same Day';
822
+ else
823
+ return s;
824
+ });
825
+ const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
826
+ if (this.isHolidays(datasSameDayNotAvaliable)) {
827
+ shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
828
+ }
829
+ if (totalPrice >= 200) {
830
+ shippingMethods = shippingMethods.map((s) => {
831
+ if (s.serviceName !== 'Same Day')
832
+ return Object.assign(Object.assign({}, s), { totalPrice: 0 });
833
+ else
834
+ return s;
835
+ });
836
+ }
837
+ if (shop == Shops.GLAMSHOP)
838
+ return shippingMethods;
839
+ if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
840
+ shippingMethods = shippingMethods.map((s) => {
841
+ if (s.serviceName == 'Same Day')
842
+ return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
843
+ else
844
+ return Object.assign(Object.assign({}, s), { totalPrice: 0 });
845
+ });
846
+ }
847
+ if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
848
+ shippingMethods = shippingMethods.map((s) => {
849
+ return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
850
+ });
851
+ }
852
+ return shippingMethods;
853
+ }));
854
+ }
855
+ isFreeShippingBySubscription(shop, subscriptionPlan) {
856
+ if (!subscriptionPlan)
857
+ return false;
858
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT') {
859
+ return true;
860
+ }
861
+ return false;
862
+ }
863
+ isHalfShippingBySubscription(shop, subscriptionPlan) {
864
+ if (!subscriptionPlan)
865
+ return false;
866
+ if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
867
+ return true;
868
+ }
869
+ return false;
870
+ }
871
+ isHolidays(datas) {
872
+ const today = new Date();
873
+ for (const key in datas) {
874
+ let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
875
+ let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
876
+ if (start > end)
877
+ end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
878
+ if (today >= start && today <= end)
879
+ return true;
880
+ }
881
+ return false;
882
+ }
883
+ }
884
+ 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 });
885
+ ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService });
886
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: ShippingService, decorators: [{
887
+ type: Injectable
888
+ }], ctorParameters: function () { return [{ type: i1$2.HttpClient }, { type: undefined, decorators: [{
889
+ type: Inject,
890
+ args: [BACKEND_URL]
889
891
  }] }, { type: HomeShopService }]; } });
890
892
 
891
- class AngularFirebaseAuthModule {
892
- static initializeApp(options, nameOrConfig) {
893
- return {
894
- ngModule: AngularFirebaseAuthModule,
895
- providers: [
896
- { provide: FIREBASE_OPTIONS, useValue: options },
897
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
898
- ],
899
- };
900
- }
901
- }
902
- AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
903
- AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
904
- AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
905
- {
906
- provide: 'Authentication',
907
- useFactory: (authenticationService, userRepository) => {
908
- return new Authentication(authenticationService, userRepository);
909
- },
910
- deps: ['AuthenticationService', 'UserRepository'],
911
- },
912
- {
913
- provide: 'AuthenticationService',
914
- useFactory: (angularFireAuth) => {
915
- return new AuthenticationFirebaseAuthService(angularFireAuth);
916
- },
917
- deps: [AngularFireAuth],
918
- },
919
- {
920
- provide: 'Register',
921
- useFactory: (registerService, userRepository) => {
922
- return new Register(registerService, userRepository);
923
- },
924
- deps: ['RegisterService', 'UserRepository'],
925
- },
926
- {
927
- provide: 'RegisterService',
928
- useFactory: (angularFireAuth) => {
929
- return new RegisterFirebaseAuthService(angularFireAuth);
930
- },
931
- deps: [AngularFireAuth],
932
- },
933
- {
934
- provide: 'SignOut',
935
- useFactory: (authenticationService) => {
936
- return new SignOut(authenticationService);
937
- },
938
- deps: ['AuthenticationService'],
939
- },
940
- {
941
- provide: 'RecoveryPassword',
942
- useFactory: (authenticationService) => {
943
- return new RecoveryPassword(authenticationService);
944
- },
945
- deps: ['AuthenticationService'],
946
- },
947
- ], imports: [[AngularFireModule]] });
948
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
949
- type: NgModule,
950
- args: [{
951
- imports: [AngularFireModule],
952
- providers: [
953
- {
954
- provide: 'Authentication',
955
- useFactory: (authenticationService, userRepository) => {
956
- return new Authentication(authenticationService, userRepository);
957
- },
958
- deps: ['AuthenticationService', 'UserRepository'],
959
- },
960
- {
961
- provide: 'AuthenticationService',
962
- useFactory: (angularFireAuth) => {
963
- return new AuthenticationFirebaseAuthService(angularFireAuth);
964
- },
965
- deps: [AngularFireAuth],
966
- },
967
- {
968
- provide: 'Register',
969
- useFactory: (registerService, userRepository) => {
970
- return new Register(registerService, userRepository);
971
- },
972
- deps: ['RegisterService', 'UserRepository'],
973
- },
974
- {
975
- provide: 'RegisterService',
976
- useFactory: (angularFireAuth) => {
977
- return new RegisterFirebaseAuthService(angularFireAuth);
978
- },
979
- deps: [AngularFireAuth],
980
- },
981
- {
982
- provide: 'SignOut',
983
- useFactory: (authenticationService) => {
984
- return new SignOut(authenticationService);
985
- },
986
- deps: ['AuthenticationService'],
987
- },
988
- {
989
- provide: 'RecoveryPassword',
990
- useFactory: (authenticationService) => {
991
- return new RecoveryPassword(authenticationService);
992
- },
993
- deps: ['AuthenticationService'],
994
- },
995
- ],
996
- }]
893
+ class AngularFirebaseAuthModule {
894
+ static initializeApp(options, nameOrConfig) {
895
+ return {
896
+ ngModule: AngularFirebaseAuthModule,
897
+ providers: [
898
+ { provide: FIREBASE_OPTIONS, useValue: options },
899
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
900
+ ],
901
+ };
902
+ }
903
+ }
904
+ AngularFirebaseAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
905
+ AngularFirebaseAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, imports: [AngularFireModule] });
906
+ AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, providers: [
907
+ {
908
+ provide: 'Authentication',
909
+ useFactory: (authenticationService, userRepository) => {
910
+ return new Authentication(authenticationService, userRepository);
911
+ },
912
+ deps: ['AuthenticationService', 'UserRepository'],
913
+ },
914
+ {
915
+ provide: 'AuthenticationService',
916
+ useFactory: (angularFireAuth) => {
917
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
918
+ },
919
+ deps: [AngularFireAuth],
920
+ },
921
+ {
922
+ provide: 'Register',
923
+ useFactory: (registerService, userRepository) => {
924
+ return new Register(registerService, userRepository);
925
+ },
926
+ deps: ['RegisterService', 'UserRepository'],
927
+ },
928
+ {
929
+ provide: 'RegisterService',
930
+ useFactory: (angularFireAuth) => {
931
+ return new RegisterFirebaseAuthService(angularFireAuth);
932
+ },
933
+ deps: [AngularFireAuth],
934
+ },
935
+ {
936
+ provide: 'SignOut',
937
+ useFactory: (authenticationService) => {
938
+ return new SignOut(authenticationService);
939
+ },
940
+ deps: ['AuthenticationService'],
941
+ },
942
+ {
943
+ provide: 'RecoveryPassword',
944
+ useFactory: (authenticationService) => {
945
+ return new RecoveryPassword(authenticationService);
946
+ },
947
+ deps: ['AuthenticationService'],
948
+ },
949
+ ], imports: [[AngularFireModule]] });
950
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
951
+ type: NgModule,
952
+ args: [{
953
+ imports: [AngularFireModule],
954
+ providers: [
955
+ {
956
+ provide: 'Authentication',
957
+ useFactory: (authenticationService, userRepository) => {
958
+ return new Authentication(authenticationService, userRepository);
959
+ },
960
+ deps: ['AuthenticationService', 'UserRepository'],
961
+ },
962
+ {
963
+ provide: 'AuthenticationService',
964
+ useFactory: (angularFireAuth) => {
965
+ return new AuthenticationFirebaseAuthService(angularFireAuth);
966
+ },
967
+ deps: [AngularFireAuth],
968
+ },
969
+ {
970
+ provide: 'Register',
971
+ useFactory: (registerService, userRepository) => {
972
+ return new Register(registerService, userRepository);
973
+ },
974
+ deps: ['RegisterService', 'UserRepository'],
975
+ },
976
+ {
977
+ provide: 'RegisterService',
978
+ useFactory: (angularFireAuth) => {
979
+ return new RegisterFirebaseAuthService(angularFireAuth);
980
+ },
981
+ deps: [AngularFireAuth],
982
+ },
983
+ {
984
+ provide: 'SignOut',
985
+ useFactory: (authenticationService) => {
986
+ return new SignOut(authenticationService);
987
+ },
988
+ deps: ['AuthenticationService'],
989
+ },
990
+ {
991
+ provide: 'RecoveryPassword',
992
+ useFactory: (authenticationService) => {
993
+ return new RecoveryPassword(authenticationService);
994
+ },
995
+ deps: ['AuthenticationService'],
996
+ },
997
+ ],
998
+ }]
997
999
  }] });
998
1000
 
999
- class AngularElasticSeachModule {
1000
- static initializeApp(options) {
1001
- return {
1002
- ngModule: AngularElasticSeachModule,
1003
- providers: [{ provide: ES_CONFIG, useValue: options }],
1004
- };
1005
- }
1006
- }
1007
- AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1008
- AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule });
1009
- AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, providers: [
1010
- {
1011
- provide: ProductsIndex,
1012
- useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
1013
- deps: [ES_CONFIG],
1014
- },
1015
- ] });
1016
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
1017
- type: NgModule,
1018
- args: [{
1019
- providers: [
1020
- {
1021
- provide: ProductsIndex,
1022
- useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
1023
- deps: [ES_CONFIG],
1024
- },
1025
- ],
1026
- }]
1001
+ class AngularElasticSeachModule {
1002
+ static initializeApp(options) {
1003
+ return {
1004
+ ngModule: AngularElasticSeachModule,
1005
+ providers: [{ provide: ES_CONFIG, useValue: options }],
1006
+ };
1007
+ }
1008
+ }
1009
+ AngularElasticSeachModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1010
+ AngularElasticSeachModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule });
1011
+ AngularElasticSeachModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, providers: [
1012
+ {
1013
+ provide: ProductsIndex,
1014
+ useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
1015
+ deps: [ES_CONFIG],
1016
+ },
1017
+ ] });
1018
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularElasticSeachModule, decorators: [{
1019
+ type: NgModule,
1020
+ args: [{
1021
+ providers: [
1022
+ {
1023
+ provide: ProductsIndex,
1024
+ useFactory: (configuration) => new ProductsIndex(new AxiosAdapter(configuration)),
1025
+ deps: [ES_CONFIG],
1026
+ },
1027
+ ],
1028
+ }]
1027
1029
  }] });
1028
1030
 
1029
- class AngularFirestoreModule {
1030
- static initializeApp(options, nameOrConfig) {
1031
- return {
1032
- ngModule: AngularFirestoreModule,
1033
- providers: [
1034
- { provide: FIREBASE_OPTIONS, useValue: options.firebase },
1035
- { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
1036
- { provide: ES_CONFIG, useValue: options.elasticSearch },
1037
- ],
1038
- };
1039
- }
1040
- }
1041
- AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1042
- AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule, AngularElasticSeachModule] });
1043
- AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
1044
- {
1045
- provide: 'BeautyProfileRepository',
1046
- useFactory: (firestore, userRepository) => {
1047
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1048
- },
1049
- deps: [AngularFirestore, 'UserRepository'],
1050
- },
1051
- {
1052
- provide: 'Buy2WinRepository',
1053
- useFactory: (firestore) => {
1054
- return new Buy2WinFirestoreRepository(firestore.firestore);
1055
- },
1056
- deps: [AngularFirestore],
1057
- },
1058
- {
1059
- provide: CategoryFirestoreRepository,
1060
- useFactory: (firestore) => {
1061
- return new CategoryFirestoreRepository(firestore.firestore);
1062
- },
1063
- deps: [AngularFirestore],
1064
- },
1065
- {
1066
- provide: 'CheckoutRepository',
1067
- useFactory: (firestore) => {
1068
- return new CheckoutFirestoreRepository(firestore.firestore);
1069
- },
1070
- deps: [AngularFirestore],
1071
- },
1072
- {
1073
- provide: 'CheckoutSubscriptionRepository',
1074
- useFactory: (firestore) => {
1075
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1076
- },
1077
- deps: [AngularFirestore],
1078
- },
1079
- {
1080
- provide: 'CouponRepository',
1081
- useFactory: (firestore) => {
1082
- return new CouponFirestoreRepository(firestore.firestore);
1083
- },
1084
- deps: [AngularFirestore],
1085
- },
1086
- {
1087
- provide: 'CampaignHashtagRepository',
1088
- useFactory: (firestore) => {
1089
- return new CampaignHashtagFirestoreRepository(firestore.firestore);
1090
- },
1091
- deps: [AngularFirestore],
1092
- },
1093
- {
1094
- provide: 'CampaignDashboardRepository',
1095
- useFactory: (firestore) => {
1096
- return new CampaignDashboardFirestoreRepository(firestore.firestore);
1097
- },
1098
- deps: [AngularFirestore],
1099
- },
1100
- {
1101
- provide: 'EditionRepository',
1102
- useFactory: (firestore, subscriptionRepository) => {
1103
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1104
- },
1105
- deps: [AngularFirestore, 'SubscriptionRepository'],
1106
- },
1107
- {
1108
- provide: 'HomeRepository',
1109
- useFactory: (firestore) => {
1110
- return new HomeFirestoreRepository(firestore.firestore);
1111
- },
1112
- deps: [AngularFirestore],
1113
- },
1114
- {
1115
- provide: 'LeadRepository',
1116
- useFactory: (firestore) => {
1117
- return new LeadFirestoreRepository(firestore.firestore);
1118
- },
1119
- deps: [AngularFirestore],
1120
- },
1121
- {
1122
- provide: 'LegacyOrderRepository',
1123
- useFactory: (firestore) => {
1124
- return new LegacyOrderFirestoreRepository(firestore.firestore);
1125
- },
1126
- deps: [AngularFirestore],
1127
- },
1128
- {
1129
- provide: 'ShopMenuRepository',
1130
- useFactory: (firestore) => {
1131
- return new ShopMenuFirestoreRepository(firestore.firestore);
1132
- },
1133
- deps: [AngularFirestore],
1134
- },
1135
- {
1136
- provide: 'OrderRepository',
1137
- useFactory: (firestore) => {
1138
- return new OrderFirestoreRepository(firestore.firestore);
1139
- },
1140
- deps: [AngularFirestore],
1141
- },
1142
- {
1143
- provide: 'PaymentRepository',
1144
- useFactory: (firestore) => {
1145
- return new PaymentFirestoreRepository(firestore.firestore);
1146
- },
1147
- deps: [AngularFirestore],
1148
- },
1149
- {
1150
- provide: ProductFirestoreRepository,
1151
- useFactory: (firestore) => {
1152
- return new ProductFirestoreRepository(firestore.firestore);
1153
- },
1154
- deps: [AngularFirestore],
1155
- },
1156
- {
1157
- provide: 'ShopSettingsRepository',
1158
- useFactory: (firestore) => {
1159
- return new ShopSettingsFirestoreRepository(firestore.firestore);
1160
- },
1161
- deps: [AngularFirestore],
1162
- },
1163
- {
1164
- provide: 'SubscriptionPaymentRepository',
1165
- useFactory: (firestore, subscriptionRepository) => {
1166
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1167
- },
1168
- deps: [AngularFirestore, 'SubscriptionRepository'],
1169
- },
1170
- {
1171
- provide: 'SubscriptionPlanRepository',
1172
- useFactory: (firestore) => {
1173
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1174
- },
1175
- deps: [AngularFirestore],
1176
- },
1177
- {
1178
- provide: 'SubscriptionProductRepository',
1179
- useFactory: (firestore) => {
1180
- return new SubscriptionProductFirestoreRepository(firestore.firestore);
1181
- },
1182
- deps: [AngularFirestore],
1183
- },
1184
- {
1185
- provide: 'SubscriptionRepository',
1186
- useFactory: (firestore) => {
1187
- return new SubscriptionFirestoreRepository(firestore.firestore);
1188
- },
1189
- deps: [AngularFirestore],
1190
- },
1191
- {
1192
- provide: 'UserRepository',
1193
- useFactory: (firestore) => {
1194
- return new UserFirestoreRepository(firestore.firestore);
1195
- },
1196
- deps: [AngularFirestore],
1197
- },
1198
- {
1199
- provide: 'UserAddressRepository',
1200
- useFactory: (firestore, userRepository) => {
1201
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1202
- },
1203
- deps: [AngularFirestore, 'UserRepository'],
1204
- },
1205
- {
1206
- provide: 'UserPaymentMethodRepository',
1207
- useFactory: (firestore, userRepository) => {
1208
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1209
- },
1210
- deps: [AngularFirestore, 'UserRepository'],
1211
- },
1212
- {
1213
- provide: ProductVariantFirestoreRepository,
1214
- useFactory: (firestore, productRepository) => {
1215
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1216
- },
1217
- deps: [AngularFirestore, ProductFirestoreRepository],
1218
- },
1219
- {
1220
- provide: APP_INITIALIZER,
1221
- useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
1222
- deps: [AngularFirestore],
1223
- multi: true,
1224
- },
1225
- ], imports: [[AngularFireModule, AngularElasticSeachModule]] });
1226
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
1227
- type: NgModule,
1228
- args: [{
1229
- imports: [AngularFireModule, AngularElasticSeachModule],
1230
- providers: [
1231
- {
1232
- provide: 'BeautyProfileRepository',
1233
- useFactory: (firestore, userRepository) => {
1234
- return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1235
- },
1236
- deps: [AngularFirestore, 'UserRepository'],
1237
- },
1238
- {
1239
- provide: 'Buy2WinRepository',
1240
- useFactory: (firestore) => {
1241
- return new Buy2WinFirestoreRepository(firestore.firestore);
1242
- },
1243
- deps: [AngularFirestore],
1244
- },
1245
- {
1246
- provide: CategoryFirestoreRepository,
1247
- useFactory: (firestore) => {
1248
- return new CategoryFirestoreRepository(firestore.firestore);
1249
- },
1250
- deps: [AngularFirestore],
1251
- },
1252
- {
1253
- provide: 'CheckoutRepository',
1254
- useFactory: (firestore) => {
1255
- return new CheckoutFirestoreRepository(firestore.firestore);
1256
- },
1257
- deps: [AngularFirestore],
1258
- },
1259
- {
1260
- provide: 'CheckoutSubscriptionRepository',
1261
- useFactory: (firestore) => {
1262
- return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1263
- },
1264
- deps: [AngularFirestore],
1265
- },
1266
- {
1267
- provide: 'CouponRepository',
1268
- useFactory: (firestore) => {
1269
- return new CouponFirestoreRepository(firestore.firestore);
1270
- },
1271
- deps: [AngularFirestore],
1272
- },
1273
- {
1274
- provide: 'CampaignHashtagRepository',
1275
- useFactory: (firestore) => {
1276
- return new CampaignHashtagFirestoreRepository(firestore.firestore);
1277
- },
1278
- deps: [AngularFirestore],
1279
- },
1280
- {
1281
- provide: 'CampaignDashboardRepository',
1282
- useFactory: (firestore) => {
1283
- return new CampaignDashboardFirestoreRepository(firestore.firestore);
1284
- },
1285
- deps: [AngularFirestore],
1286
- },
1287
- {
1288
- provide: 'EditionRepository',
1289
- useFactory: (firestore, subscriptionRepository) => {
1290
- return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1291
- },
1292
- deps: [AngularFirestore, 'SubscriptionRepository'],
1293
- },
1294
- {
1295
- provide: 'HomeRepository',
1296
- useFactory: (firestore) => {
1297
- return new HomeFirestoreRepository(firestore.firestore);
1298
- },
1299
- deps: [AngularFirestore],
1300
- },
1301
- {
1302
- provide: 'LeadRepository',
1303
- useFactory: (firestore) => {
1304
- return new LeadFirestoreRepository(firestore.firestore);
1305
- },
1306
- deps: [AngularFirestore],
1307
- },
1308
- {
1309
- provide: 'LegacyOrderRepository',
1310
- useFactory: (firestore) => {
1311
- return new LegacyOrderFirestoreRepository(firestore.firestore);
1312
- },
1313
- deps: [AngularFirestore],
1314
- },
1315
- {
1316
- provide: 'ShopMenuRepository',
1317
- useFactory: (firestore) => {
1318
- return new ShopMenuFirestoreRepository(firestore.firestore);
1319
- },
1320
- deps: [AngularFirestore],
1321
- },
1322
- {
1323
- provide: 'OrderRepository',
1324
- useFactory: (firestore) => {
1325
- return new OrderFirestoreRepository(firestore.firestore);
1326
- },
1327
- deps: [AngularFirestore],
1328
- },
1329
- {
1330
- provide: 'PaymentRepository',
1331
- useFactory: (firestore) => {
1332
- return new PaymentFirestoreRepository(firestore.firestore);
1333
- },
1334
- deps: [AngularFirestore],
1335
- },
1336
- {
1337
- provide: ProductFirestoreRepository,
1338
- useFactory: (firestore) => {
1339
- return new ProductFirestoreRepository(firestore.firestore);
1340
- },
1341
- deps: [AngularFirestore],
1342
- },
1343
- {
1344
- provide: 'ShopSettingsRepository',
1345
- useFactory: (firestore) => {
1346
- return new ShopSettingsFirestoreRepository(firestore.firestore);
1347
- },
1348
- deps: [AngularFirestore],
1349
- },
1350
- {
1351
- provide: 'SubscriptionPaymentRepository',
1352
- useFactory: (firestore, subscriptionRepository) => {
1353
- return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1354
- },
1355
- deps: [AngularFirestore, 'SubscriptionRepository'],
1356
- },
1357
- {
1358
- provide: 'SubscriptionPlanRepository',
1359
- useFactory: (firestore) => {
1360
- return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1361
- },
1362
- deps: [AngularFirestore],
1363
- },
1364
- {
1365
- provide: 'SubscriptionProductRepository',
1366
- useFactory: (firestore) => {
1367
- return new SubscriptionProductFirestoreRepository(firestore.firestore);
1368
- },
1369
- deps: [AngularFirestore],
1370
- },
1371
- {
1372
- provide: 'SubscriptionRepository',
1373
- useFactory: (firestore) => {
1374
- return new SubscriptionFirestoreRepository(firestore.firestore);
1375
- },
1376
- deps: [AngularFirestore],
1377
- },
1378
- {
1379
- provide: 'UserRepository',
1380
- useFactory: (firestore) => {
1381
- return new UserFirestoreRepository(firestore.firestore);
1382
- },
1383
- deps: [AngularFirestore],
1384
- },
1385
- {
1386
- provide: 'UserAddressRepository',
1387
- useFactory: (firestore, userRepository) => {
1388
- return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1389
- },
1390
- deps: [AngularFirestore, 'UserRepository'],
1391
- },
1392
- {
1393
- provide: 'UserPaymentMethodRepository',
1394
- useFactory: (firestore, userRepository) => {
1395
- return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1396
- },
1397
- deps: [AngularFirestore, 'UserRepository'],
1398
- },
1399
- {
1400
- provide: ProductVariantFirestoreRepository,
1401
- useFactory: (firestore, productRepository) => {
1402
- return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1403
- },
1404
- deps: [AngularFirestore, ProductFirestoreRepository],
1405
- },
1406
- {
1407
- provide: APP_INITIALIZER,
1408
- useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
1409
- deps: [AngularFirestore],
1410
- multi: true,
1411
- },
1412
- ],
1413
- }]
1031
+ class AngularFirestoreModule {
1032
+ static initializeApp(options, nameOrConfig) {
1033
+ return {
1034
+ ngModule: AngularFirestoreModule,
1035
+ providers: [
1036
+ { provide: FIREBASE_OPTIONS, useValue: options.firebase },
1037
+ { provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
1038
+ { provide: ES_CONFIG, useValue: options.elasticSearch },
1039
+ ],
1040
+ };
1041
+ }
1042
+ }
1043
+ AngularFirestoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1044
+ AngularFirestoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, imports: [AngularFireModule, AngularElasticSeachModule] });
1045
+ AngularFirestoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, providers: [
1046
+ {
1047
+ provide: 'BeautyProfileRepository',
1048
+ useFactory: (firestore, userRepository) => {
1049
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1050
+ },
1051
+ deps: [AngularFirestore, 'UserRepository'],
1052
+ },
1053
+ {
1054
+ provide: 'Buy2WinRepository',
1055
+ useFactory: (firestore) => {
1056
+ return new Buy2WinFirestoreRepository(firestore.firestore);
1057
+ },
1058
+ deps: [AngularFirestore],
1059
+ },
1060
+ {
1061
+ provide: CategoryFirestoreRepository,
1062
+ useFactory: (firestore) => {
1063
+ return new CategoryFirestoreRepository(firestore.firestore);
1064
+ },
1065
+ deps: [AngularFirestore],
1066
+ },
1067
+ {
1068
+ provide: 'CheckoutRepository',
1069
+ useFactory: (firestore) => {
1070
+ return new CheckoutFirestoreRepository(firestore.firestore);
1071
+ },
1072
+ deps: [AngularFirestore],
1073
+ },
1074
+ {
1075
+ provide: 'CheckoutSubscriptionRepository',
1076
+ useFactory: (firestore) => {
1077
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1078
+ },
1079
+ deps: [AngularFirestore],
1080
+ },
1081
+ {
1082
+ provide: 'CouponRepository',
1083
+ useFactory: (firestore) => {
1084
+ return new CouponFirestoreRepository(firestore.firestore);
1085
+ },
1086
+ deps: [AngularFirestore],
1087
+ },
1088
+ {
1089
+ provide: 'CampaignHashtagRepository',
1090
+ useFactory: (firestore) => {
1091
+ return new CampaignHashtagFirestoreRepository(firestore.firestore);
1092
+ },
1093
+ deps: [AngularFirestore],
1094
+ },
1095
+ {
1096
+ provide: 'CampaignDashboardRepository',
1097
+ useFactory: (firestore) => {
1098
+ return new CampaignDashboardFirestoreRepository(firestore.firestore);
1099
+ },
1100
+ deps: [AngularFirestore],
1101
+ },
1102
+ {
1103
+ provide: 'EditionRepository',
1104
+ useFactory: (firestore, subscriptionRepository) => {
1105
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1106
+ },
1107
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1108
+ },
1109
+ {
1110
+ provide: 'HomeRepository',
1111
+ useFactory: (firestore) => {
1112
+ return new HomeFirestoreRepository(firestore.firestore);
1113
+ },
1114
+ deps: [AngularFirestore],
1115
+ },
1116
+ {
1117
+ provide: 'LeadRepository',
1118
+ useFactory: (firestore) => {
1119
+ return new LeadFirestoreRepository(firestore.firestore);
1120
+ },
1121
+ deps: [AngularFirestore],
1122
+ },
1123
+ {
1124
+ provide: 'LegacyOrderRepository',
1125
+ useFactory: (firestore) => {
1126
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
1127
+ },
1128
+ deps: [AngularFirestore],
1129
+ },
1130
+ {
1131
+ provide: 'ShopMenuRepository',
1132
+ useFactory: (firestore) => {
1133
+ return new ShopMenuFirestoreRepository(firestore.firestore);
1134
+ },
1135
+ deps: [AngularFirestore],
1136
+ },
1137
+ {
1138
+ provide: 'OrderRepository',
1139
+ useFactory: (firestore) => {
1140
+ return new OrderFirestoreRepository(firestore.firestore);
1141
+ },
1142
+ deps: [AngularFirestore],
1143
+ },
1144
+ {
1145
+ provide: 'PaymentRepository',
1146
+ useFactory: (firestore) => {
1147
+ return new PaymentFirestoreRepository(firestore.firestore);
1148
+ },
1149
+ deps: [AngularFirestore],
1150
+ },
1151
+ {
1152
+ provide: ProductFirestoreRepository,
1153
+ useFactory: (firestore) => {
1154
+ return new ProductFirestoreRepository(firestore.firestore);
1155
+ },
1156
+ deps: [AngularFirestore],
1157
+ },
1158
+ {
1159
+ provide: 'ShopSettingsRepository',
1160
+ useFactory: (firestore) => {
1161
+ return new ShopSettingsFirestoreRepository(firestore.firestore);
1162
+ },
1163
+ deps: [AngularFirestore],
1164
+ },
1165
+ {
1166
+ provide: 'SubscriptionPaymentRepository',
1167
+ useFactory: (firestore, subscriptionRepository) => {
1168
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1169
+ },
1170
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1171
+ },
1172
+ {
1173
+ provide: 'SubscriptionPlanRepository',
1174
+ useFactory: (firestore) => {
1175
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1176
+ },
1177
+ deps: [AngularFirestore],
1178
+ },
1179
+ {
1180
+ provide: 'SubscriptionProductRepository',
1181
+ useFactory: (firestore) => {
1182
+ return new SubscriptionProductFirestoreRepository(firestore.firestore);
1183
+ },
1184
+ deps: [AngularFirestore],
1185
+ },
1186
+ {
1187
+ provide: 'SubscriptionRepository',
1188
+ useFactory: (firestore) => {
1189
+ return new SubscriptionFirestoreRepository(firestore.firestore);
1190
+ },
1191
+ deps: [AngularFirestore],
1192
+ },
1193
+ {
1194
+ provide: 'UserRepository',
1195
+ useFactory: (firestore) => {
1196
+ return new UserFirestoreRepository(firestore.firestore);
1197
+ },
1198
+ deps: [AngularFirestore],
1199
+ },
1200
+ {
1201
+ provide: 'UserAddressRepository',
1202
+ useFactory: (firestore, userRepository) => {
1203
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1204
+ },
1205
+ deps: [AngularFirestore, 'UserRepository'],
1206
+ },
1207
+ {
1208
+ provide: 'UserPaymentMethodRepository',
1209
+ useFactory: (firestore, userRepository) => {
1210
+ return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1211
+ },
1212
+ deps: [AngularFirestore, 'UserRepository'],
1213
+ },
1214
+ {
1215
+ provide: ProductVariantFirestoreRepository,
1216
+ useFactory: (firestore, productRepository) => {
1217
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1218
+ },
1219
+ deps: [AngularFirestore, ProductFirestoreRepository],
1220
+ },
1221
+ {
1222
+ provide: APP_INITIALIZER,
1223
+ useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
1224
+ deps: [AngularFirestore],
1225
+ multi: true,
1226
+ },
1227
+ ], imports: [[AngularFireModule, AngularElasticSeachModule]] });
1228
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularFirestoreModule, decorators: [{
1229
+ type: NgModule,
1230
+ args: [{
1231
+ imports: [AngularFireModule, AngularElasticSeachModule],
1232
+ providers: [
1233
+ {
1234
+ provide: 'BeautyProfileRepository',
1235
+ useFactory: (firestore, userRepository) => {
1236
+ return new UserBeautyProfileFirestoreRepository(firestore.firestore, userRepository);
1237
+ },
1238
+ deps: [AngularFirestore, 'UserRepository'],
1239
+ },
1240
+ {
1241
+ provide: 'Buy2WinRepository',
1242
+ useFactory: (firestore) => {
1243
+ return new Buy2WinFirestoreRepository(firestore.firestore);
1244
+ },
1245
+ deps: [AngularFirestore],
1246
+ },
1247
+ {
1248
+ provide: CategoryFirestoreRepository,
1249
+ useFactory: (firestore) => {
1250
+ return new CategoryFirestoreRepository(firestore.firestore);
1251
+ },
1252
+ deps: [AngularFirestore],
1253
+ },
1254
+ {
1255
+ provide: 'CheckoutRepository',
1256
+ useFactory: (firestore) => {
1257
+ return new CheckoutFirestoreRepository(firestore.firestore);
1258
+ },
1259
+ deps: [AngularFirestore],
1260
+ },
1261
+ {
1262
+ provide: 'CheckoutSubscriptionRepository',
1263
+ useFactory: (firestore) => {
1264
+ return new CheckoutSubscriptionFirestoreRepository(firestore.firestore);
1265
+ },
1266
+ deps: [AngularFirestore],
1267
+ },
1268
+ {
1269
+ provide: 'CouponRepository',
1270
+ useFactory: (firestore) => {
1271
+ return new CouponFirestoreRepository(firestore.firestore);
1272
+ },
1273
+ deps: [AngularFirestore],
1274
+ },
1275
+ {
1276
+ provide: 'CampaignHashtagRepository',
1277
+ useFactory: (firestore) => {
1278
+ return new CampaignHashtagFirestoreRepository(firestore.firestore);
1279
+ },
1280
+ deps: [AngularFirestore],
1281
+ },
1282
+ {
1283
+ provide: 'CampaignDashboardRepository',
1284
+ useFactory: (firestore) => {
1285
+ return new CampaignDashboardFirestoreRepository(firestore.firestore);
1286
+ },
1287
+ deps: [AngularFirestore],
1288
+ },
1289
+ {
1290
+ provide: 'EditionRepository',
1291
+ useFactory: (firestore, subscriptionRepository) => {
1292
+ return new SubscriptionEditionFirestoreRepository(firestore.firestore, subscriptionRepository);
1293
+ },
1294
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1295
+ },
1296
+ {
1297
+ provide: 'HomeRepository',
1298
+ useFactory: (firestore) => {
1299
+ return new HomeFirestoreRepository(firestore.firestore);
1300
+ },
1301
+ deps: [AngularFirestore],
1302
+ },
1303
+ {
1304
+ provide: 'LeadRepository',
1305
+ useFactory: (firestore) => {
1306
+ return new LeadFirestoreRepository(firestore.firestore);
1307
+ },
1308
+ deps: [AngularFirestore],
1309
+ },
1310
+ {
1311
+ provide: 'LegacyOrderRepository',
1312
+ useFactory: (firestore) => {
1313
+ return new LegacyOrderFirestoreRepository(firestore.firestore);
1314
+ },
1315
+ deps: [AngularFirestore],
1316
+ },
1317
+ {
1318
+ provide: 'ShopMenuRepository',
1319
+ useFactory: (firestore) => {
1320
+ return new ShopMenuFirestoreRepository(firestore.firestore);
1321
+ },
1322
+ deps: [AngularFirestore],
1323
+ },
1324
+ {
1325
+ provide: 'OrderRepository',
1326
+ useFactory: (firestore) => {
1327
+ return new OrderFirestoreRepository(firestore.firestore);
1328
+ },
1329
+ deps: [AngularFirestore],
1330
+ },
1331
+ {
1332
+ provide: 'PaymentRepository',
1333
+ useFactory: (firestore) => {
1334
+ return new PaymentFirestoreRepository(firestore.firestore);
1335
+ },
1336
+ deps: [AngularFirestore],
1337
+ },
1338
+ {
1339
+ provide: ProductFirestoreRepository,
1340
+ useFactory: (firestore) => {
1341
+ return new ProductFirestoreRepository(firestore.firestore);
1342
+ },
1343
+ deps: [AngularFirestore],
1344
+ },
1345
+ {
1346
+ provide: 'ShopSettingsRepository',
1347
+ useFactory: (firestore) => {
1348
+ return new ShopSettingsFirestoreRepository(firestore.firestore);
1349
+ },
1350
+ deps: [AngularFirestore],
1351
+ },
1352
+ {
1353
+ provide: 'SubscriptionPaymentRepository',
1354
+ useFactory: (firestore, subscriptionRepository) => {
1355
+ return new SubscriptionPaymentFirestoreRepository(firestore.firestore, subscriptionRepository);
1356
+ },
1357
+ deps: [AngularFirestore, 'SubscriptionRepository'],
1358
+ },
1359
+ {
1360
+ provide: 'SubscriptionPlanRepository',
1361
+ useFactory: (firestore) => {
1362
+ return new SubscriptionPlanFirestoreRepository(firestore.firestore);
1363
+ },
1364
+ deps: [AngularFirestore],
1365
+ },
1366
+ {
1367
+ provide: 'SubscriptionProductRepository',
1368
+ useFactory: (firestore) => {
1369
+ return new SubscriptionProductFirestoreRepository(firestore.firestore);
1370
+ },
1371
+ deps: [AngularFirestore],
1372
+ },
1373
+ {
1374
+ provide: 'SubscriptionRepository',
1375
+ useFactory: (firestore) => {
1376
+ return new SubscriptionFirestoreRepository(firestore.firestore);
1377
+ },
1378
+ deps: [AngularFirestore],
1379
+ },
1380
+ {
1381
+ provide: 'UserRepository',
1382
+ useFactory: (firestore) => {
1383
+ return new UserFirestoreRepository(firestore.firestore);
1384
+ },
1385
+ deps: [AngularFirestore],
1386
+ },
1387
+ {
1388
+ provide: 'UserAddressRepository',
1389
+ useFactory: (firestore, userRepository) => {
1390
+ return new UserAddressFirestoreRepository(firestore.firestore, userRepository);
1391
+ },
1392
+ deps: [AngularFirestore, 'UserRepository'],
1393
+ },
1394
+ {
1395
+ provide: 'UserPaymentMethodRepository',
1396
+ useFactory: (firestore, userRepository) => {
1397
+ return new UserPaymentMethodFirestoreRepository(firestore.firestore, userRepository);
1398
+ },
1399
+ deps: [AngularFirestore, 'UserRepository'],
1400
+ },
1401
+ {
1402
+ provide: ProductVariantFirestoreRepository,
1403
+ useFactory: (firestore, productRepository) => {
1404
+ return new ProductVariantFirestoreRepository(firestore.firestore, productRepository);
1405
+ },
1406
+ deps: [AngularFirestore, ProductFirestoreRepository],
1407
+ },
1408
+ {
1409
+ provide: APP_INITIALIZER,
1410
+ useFactory: (firestore) => () => firestore.firestore.settings({ ignoreUndefinedProperties: true }),
1411
+ deps: [AngularFirestore],
1412
+ multi: true,
1413
+ },
1414
+ ],
1415
+ }]
1414
1416
  }] });
1415
1417
 
1416
- class AngularHasuraGraphQLModule {
1417
- static initializeApp(options) {
1418
- return {
1419
- ngModule: AngularHasuraGraphQLModule,
1420
- providers: [{ provide: HASURA_OPTIONS, useValue: options }],
1421
- };
1422
- }
1423
- }
1424
- AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1425
- AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule });
1426
- AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
1427
- {
1428
- provide: 'CategoryRepository',
1429
- useExisting: CategoryHasuraGraphQLRepository,
1430
- },
1431
- {
1432
- provide: CategoryHasuraGraphQLRepository,
1433
- useFactory: (options, productRepository, categoryFilterRepository) => {
1434
- return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
1435
- },
1436
- deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1437
- },
1438
- {
1439
- provide: 'ProductRepository',
1440
- useExisting: ProductHasuraGraphQLRepository,
1441
- },
1442
- {
1443
- provide: ProductHasuraGraphQLRepository,
1444
- useFactory: (options) => {
1445
- return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1446
- },
1447
- deps: [HASURA_OPTIONS],
1448
- },
1449
- {
1450
- provide: 'VariantRepository',
1451
- useExisting: VariantHasuraGraphQLRepository,
1452
- },
1453
- {
1454
- provide: VariantHasuraGraphQLRepository,
1455
- useFactory: (options) => {
1456
- return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1457
- },
1458
- deps: [HASURA_OPTIONS],
1459
- },
1460
- {
1461
- provide: 'CategoryFilterRepository',
1462
- useExisting: CategoryFilterHasuraGraphQLRepository,
1463
- },
1464
- {
1465
- provide: CategoryFilterHasuraGraphQLRepository,
1466
- useFactory: (options) => {
1467
- return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
1468
- },
1469
- deps: [HASURA_OPTIONS],
1470
- },
1471
- {
1472
- provide: 'FilterOptionRepository',
1473
- useExisting: FilterOptionHasuraGraphQLRepository,
1474
- },
1475
- {
1476
- provide: FilterOptionHasuraGraphQLRepository,
1477
- useFactory: (options) => {
1478
- return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
1479
- },
1480
- deps: [HASURA_OPTIONS],
1481
- },
1482
- {
1483
- provide: 'FilterRepository',
1484
- useExisting: FilterHasuraGraphQLRepository,
1485
- },
1486
- {
1487
- provide: FilterHasuraGraphQLRepository,
1488
- useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
1489
- return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
1490
- },
1491
- deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1492
- },
1493
- ] });
1494
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
1495
- type: NgModule,
1496
- args: [{
1497
- providers: [
1498
- {
1499
- provide: 'CategoryRepository',
1500
- useExisting: CategoryHasuraGraphQLRepository,
1501
- },
1502
- {
1503
- provide: CategoryHasuraGraphQLRepository,
1504
- useFactory: (options, productRepository, categoryFilterRepository) => {
1505
- return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
1506
- },
1507
- deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1508
- },
1509
- {
1510
- provide: 'ProductRepository',
1511
- useExisting: ProductHasuraGraphQLRepository,
1512
- },
1513
- {
1514
- provide: ProductHasuraGraphQLRepository,
1515
- useFactory: (options) => {
1516
- return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1517
- },
1518
- deps: [HASURA_OPTIONS],
1519
- },
1520
- {
1521
- provide: 'VariantRepository',
1522
- useExisting: VariantHasuraGraphQLRepository,
1523
- },
1524
- {
1525
- provide: VariantHasuraGraphQLRepository,
1526
- useFactory: (options) => {
1527
- return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1528
- },
1529
- deps: [HASURA_OPTIONS],
1530
- },
1531
- {
1532
- provide: 'CategoryFilterRepository',
1533
- useExisting: CategoryFilterHasuraGraphQLRepository,
1534
- },
1535
- {
1536
- provide: CategoryFilterHasuraGraphQLRepository,
1537
- useFactory: (options) => {
1538
- return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
1539
- },
1540
- deps: [HASURA_OPTIONS],
1541
- },
1542
- {
1543
- provide: 'FilterOptionRepository',
1544
- useExisting: FilterOptionHasuraGraphQLRepository,
1545
- },
1546
- {
1547
- provide: FilterOptionHasuraGraphQLRepository,
1548
- useFactory: (options) => {
1549
- return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
1550
- },
1551
- deps: [HASURA_OPTIONS],
1552
- },
1553
- {
1554
- provide: 'FilterRepository',
1555
- useExisting: FilterHasuraGraphQLRepository,
1556
- },
1557
- {
1558
- provide: FilterHasuraGraphQLRepository,
1559
- useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
1560
- return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
1561
- },
1562
- deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1563
- },
1564
- ],
1565
- }]
1418
+ class AngularHasuraGraphQLModule {
1419
+ static initializeApp(options) {
1420
+ return {
1421
+ ngModule: AngularHasuraGraphQLModule,
1422
+ providers: [{ provide: HASURA_OPTIONS, useValue: options }],
1423
+ };
1424
+ }
1425
+ }
1426
+ AngularHasuraGraphQLModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1427
+ AngularHasuraGraphQLModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule });
1428
+ AngularHasuraGraphQLModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, providers: [
1429
+ {
1430
+ provide: 'CategoryRepository',
1431
+ useExisting: CategoryHasuraGraphQLRepository,
1432
+ },
1433
+ {
1434
+ provide: CategoryHasuraGraphQLRepository,
1435
+ useFactory: (options, productRepository, categoryFilterRepository) => {
1436
+ return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
1437
+ },
1438
+ deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1439
+ },
1440
+ {
1441
+ provide: 'ProductRepository',
1442
+ useExisting: ProductHasuraGraphQLRepository,
1443
+ },
1444
+ {
1445
+ provide: ProductHasuraGraphQLRepository,
1446
+ useFactory: (options) => {
1447
+ return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1448
+ },
1449
+ deps: [HASURA_OPTIONS],
1450
+ },
1451
+ {
1452
+ provide: 'VariantRepository',
1453
+ useExisting: VariantHasuraGraphQLRepository,
1454
+ },
1455
+ {
1456
+ provide: VariantHasuraGraphQLRepository,
1457
+ useFactory: (options) => {
1458
+ return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1459
+ },
1460
+ deps: [HASURA_OPTIONS],
1461
+ },
1462
+ {
1463
+ provide: 'CategoryFilterRepository',
1464
+ useExisting: CategoryFilterHasuraGraphQLRepository,
1465
+ },
1466
+ {
1467
+ provide: CategoryFilterHasuraGraphQLRepository,
1468
+ useFactory: (options) => {
1469
+ return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
1470
+ },
1471
+ deps: [HASURA_OPTIONS],
1472
+ },
1473
+ {
1474
+ provide: 'FilterOptionRepository',
1475
+ useExisting: FilterOptionHasuraGraphQLRepository,
1476
+ },
1477
+ {
1478
+ provide: FilterOptionHasuraGraphQLRepository,
1479
+ useFactory: (options) => {
1480
+ return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
1481
+ },
1482
+ deps: [HASURA_OPTIONS],
1483
+ },
1484
+ {
1485
+ provide: 'FilterRepository',
1486
+ useExisting: FilterHasuraGraphQLRepository,
1487
+ },
1488
+ {
1489
+ provide: FilterHasuraGraphQLRepository,
1490
+ useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
1491
+ return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
1492
+ },
1493
+ deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1494
+ },
1495
+ ] });
1496
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularHasuraGraphQLModule, decorators: [{
1497
+ type: NgModule,
1498
+ args: [{
1499
+ providers: [
1500
+ {
1501
+ provide: 'CategoryRepository',
1502
+ useExisting: CategoryHasuraGraphQLRepository,
1503
+ },
1504
+ {
1505
+ provide: CategoryHasuraGraphQLRepository,
1506
+ useFactory: (options, productRepository, categoryFilterRepository) => {
1507
+ return new CategoryHasuraGraphQLRepository(options.endpoint, options.credentials, productRepository, categoryFilterRepository);
1508
+ },
1509
+ deps: [HASURA_OPTIONS, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1510
+ },
1511
+ {
1512
+ provide: 'ProductRepository',
1513
+ useExisting: ProductHasuraGraphQLRepository,
1514
+ },
1515
+ {
1516
+ provide: ProductHasuraGraphQLRepository,
1517
+ useFactory: (options) => {
1518
+ return new ProductHasuraGraphQLRepository(options.endpoint, options.credentials);
1519
+ },
1520
+ deps: [HASURA_OPTIONS],
1521
+ },
1522
+ {
1523
+ provide: 'VariantRepository',
1524
+ useExisting: VariantHasuraGraphQLRepository,
1525
+ },
1526
+ {
1527
+ provide: VariantHasuraGraphQLRepository,
1528
+ useFactory: (options) => {
1529
+ return new VariantHasuraGraphQLRepository(options.endpoint, options.credentials);
1530
+ },
1531
+ deps: [HASURA_OPTIONS],
1532
+ },
1533
+ {
1534
+ provide: 'CategoryFilterRepository',
1535
+ useExisting: CategoryFilterHasuraGraphQLRepository,
1536
+ },
1537
+ {
1538
+ provide: CategoryFilterHasuraGraphQLRepository,
1539
+ useFactory: (options) => {
1540
+ return new CategoryFilterHasuraGraphQLRepository(options.endpoint, options.credentials);
1541
+ },
1542
+ deps: [HASURA_OPTIONS],
1543
+ },
1544
+ {
1545
+ provide: 'FilterOptionRepository',
1546
+ useExisting: FilterOptionHasuraGraphQLRepository,
1547
+ },
1548
+ {
1549
+ provide: FilterOptionHasuraGraphQLRepository,
1550
+ useFactory: (options) => {
1551
+ return new FilterOptionHasuraGraphQLRepository(options.endpoint, options.credentials);
1552
+ },
1553
+ deps: [HASURA_OPTIONS],
1554
+ },
1555
+ {
1556
+ provide: 'FilterRepository',
1557
+ useExisting: FilterHasuraGraphQLRepository,
1558
+ },
1559
+ {
1560
+ provide: FilterHasuraGraphQLRepository,
1561
+ useFactory: (options, filterOptionRepository, categoryFilterRepository) => {
1562
+ return new FilterHasuraGraphQLRepository(options.endpoint, options.credentials, filterOptionRepository, categoryFilterRepository);
1563
+ },
1564
+ deps: [HASURA_OPTIONS, FilterOptionHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository],
1565
+ },
1566
+ ],
1567
+ }]
1566
1568
  }] });
1567
1569
 
1568
- class AngularConnectModule {
1569
- static initializeApp(defaultShop, options, nameOrConfig) {
1570
- return {
1571
- ngModule: AngularConnectModule,
1572
- providers: [
1573
- ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
1574
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
1575
- ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
1576
- ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
1577
- ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
1578
- ...(isNil(options === null || options === void 0 ? void 0 : options.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
1579
- ],
1580
- };
1581
- }
1582
- }
1583
- AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1584
- AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
1585
- AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [
1586
- AuthService,
1587
- CartService,
1588
- CheckoutService,
1589
- CheckoutSubscriptionService,
1590
- CouponService,
1591
- HomeShopService,
1592
- OrderService,
1593
- ShippingService,
1594
- ], imports: [[AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
1595
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
1596
- type: NgModule,
1597
- args: [{
1598
- imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule],
1599
- providers: [
1600
- AuthService,
1601
- CartService,
1602
- CheckoutService,
1603
- CheckoutSubscriptionService,
1604
- CouponService,
1605
- HomeShopService,
1606
- OrderService,
1607
- ShippingService,
1608
- ],
1609
- }]
1570
+ class AngularConnectModule {
1571
+ static initializeApp(defaultShop, options, nameOrConfig) {
1572
+ return {
1573
+ ngModule: AngularConnectModule,
1574
+ providers: [
1575
+ ...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
1576
+ ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
1577
+ ...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
1578
+ ...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
1579
+ ...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
1580
+ ...(isNil(options === null || options === void 0 ? void 0 : options.backendUrl) ? [] : [{ provide: BACKEND_URL, useValue: options.backendUrl }]),
1581
+ ],
1582
+ };
1583
+ }
1584
+ }
1585
+ AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1586
+ AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule] });
1587
+ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, providers: [
1588
+ AuthService,
1589
+ CartService,
1590
+ CheckoutService,
1591
+ CheckoutSubscriptionService,
1592
+ CouponService,
1593
+ HomeShopService,
1594
+ OrderService,
1595
+ ShippingService,
1596
+ ], imports: [[AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule]] });
1597
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: AngularConnectModule, decorators: [{
1598
+ type: NgModule,
1599
+ args: [{
1600
+ imports: [AngularFireModule, AngularFirestoreModule, AngularHasuraGraphQLModule],
1601
+ providers: [
1602
+ AuthService,
1603
+ CartService,
1604
+ CheckoutService,
1605
+ CheckoutSubscriptionService,
1606
+ CouponService,
1607
+ HomeShopService,
1608
+ OrderService,
1609
+ ShippingService,
1610
+ ],
1611
+ }]
1610
1612
  }] });
1611
1613
 
1612
- /**
1613
- * Generated bundle index. Do not edit.
1614
+ /**
1615
+ * Generated bundle index. Do not edit.
1614
1616
  */
1615
1617
 
1616
1618
  export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CheckoutService, CheckoutSubscriptionService, CouponService, HomeShopService, OrderService, ShippingService };