@infrab4a/connect-angular 4.17.3-beta.8 → 4.18.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.
- package/angular-connect.module.d.ts +11 -8
- package/angular-hasura-graphql.module.d.ts +1 -1
- package/consts/firebase-const.d.ts +1 -0
- package/esm2020/angular-connect.module.mjs +52 -9
- package/esm2020/angular-firebase-auth.module.mjs +30 -4
- package/esm2020/angular-hasura-graphql.module.mjs +1 -1
- package/esm2020/consts/firebase-const.mjs +2 -1
- package/esm2020/services/cart.service.mjs +13 -126
- package/esm2020/services/checkout.service.mjs +43 -27
- package/esm2020/services/coupon.service.mjs +2 -58
- package/fesm2015/infrab4a-connect-angular.mjs +416 -499
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +363 -444
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +2 -8
- package/services/checkout.service.d.ts +12 -19
- package/services/coupon.service.d.ts +1 -7
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { NgModule, InjectionToken, PLATFORM_ID, Injectable, Inject } from '@angular/core';
|
|
3
|
-
import * as i1$
|
|
3
|
+
import * as i1$4 from '@angular/fire/app';
|
|
4
4
|
import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
|
|
5
|
-
import * as i2
|
|
5
|
+
import * as i2 from '@angular/fire/app-check';
|
|
6
|
+
import { provideAppCheck, initializeAppCheck } from '@angular/fire/app-check';
|
|
7
|
+
import * as i3 from '@angular/fire/storage';
|
|
6
8
|
import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
|
|
7
|
-
import * as i1$
|
|
8
|
-
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryProductHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter,
|
|
9
|
+
import * as i1$3 from '@infrab4a/connect';
|
|
10
|
+
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryProductHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, isNil, NotFoundError, Checkout, pick, LineItem, Where, set, InvalidArgumentError, RoundProductPricesHelper, isEmpty, Shops, Category, PersonTypes, WishlistLogType, Wishlist, CheckoutTypes, CouponTypes, Exclusivities, OrderStatus, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
|
|
9
11
|
import * as i1 from '@angular/fire/auth';
|
|
10
|
-
import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
|
|
12
|
+
import { Auth, provideAuth, initializeAuth, indexedDBLocalPersistence, browserLocalPersistence, getAuth, getIdToken, authState } from '@angular/fire/auth';
|
|
11
13
|
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
|
|
12
14
|
import * as i1$1 from '@angular/fire/firestore';
|
|
13
15
|
import { Firestore, provideFirestore, initializeFirestore, memoryLocalCache, docSnapshots, doc } from '@angular/fire/firestore';
|
|
@@ -15,7 +17,7 @@ import cookie from 'js-cookie';
|
|
|
15
17
|
import { of, from, combineLatest, throwError, Subject, forkJoin } from 'rxjs';
|
|
16
18
|
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
17
19
|
import { __awaiter, __decorate, __metadata } from 'tslib';
|
|
18
|
-
import * as
|
|
20
|
+
import * as i1$2 from '@angular/common/http';
|
|
19
21
|
import { Type } from 'class-transformer';
|
|
20
22
|
|
|
21
23
|
const ES_CONFIG = 'ES_CONFIG';
|
|
@@ -57,7 +59,8 @@ const CATEGORY_STRUCTURE = 'CATEGORY_STRUCTURE';
|
|
|
57
59
|
const DEFAULT_SHOP = 'DEFAULT_SHOP';
|
|
58
60
|
|
|
59
61
|
const FIREBASE_APP_NAME = new InjectionToken('firebaseAppName');
|
|
60
|
-
const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
|
|
62
|
+
const FIREBASE_OPTIONS = new InjectionToken('firebaseOptions');
|
|
63
|
+
const APP_CHECK_PROVIDER = new InjectionToken('appCheckProvider');
|
|
61
64
|
|
|
62
65
|
const HASURA_OPTIONS = 'HASURA_OPTIONS';
|
|
63
66
|
|
|
@@ -121,11 +124,37 @@ AngularFirebaseAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0
|
|
|
121
124
|
},
|
|
122
125
|
deps: ['AuthenticationService'],
|
|
123
126
|
},
|
|
124
|
-
], imports: [provideAuth((injector) =>
|
|
127
|
+
], imports: [provideAuth((injector) => {
|
|
128
|
+
const app = injector.get(FirebaseApp);
|
|
129
|
+
try {
|
|
130
|
+
return initializeAuth(app, {
|
|
131
|
+
persistence: [indexedDBLocalPersistence, browserLocalPersistence],
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error instanceof Error)
|
|
136
|
+
console.error('Error initializing auth', error.message);
|
|
137
|
+
return getAuth(app);
|
|
138
|
+
}
|
|
139
|
+
})] });
|
|
125
140
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularFirebaseAuthModule, decorators: [{
|
|
126
141
|
type: NgModule,
|
|
127
142
|
args: [{
|
|
128
|
-
imports: [
|
|
143
|
+
imports: [
|
|
144
|
+
provideAuth((injector) => {
|
|
145
|
+
const app = injector.get(FirebaseApp);
|
|
146
|
+
try {
|
|
147
|
+
return initializeAuth(app, {
|
|
148
|
+
persistence: [indexedDBLocalPersistence, browserLocalPersistence],
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
if (error instanceof Error)
|
|
153
|
+
console.error('Error initializing auth', error.message);
|
|
154
|
+
return getAuth(app);
|
|
155
|
+
}
|
|
156
|
+
}),
|
|
157
|
+
],
|
|
129
158
|
providers: [
|
|
130
159
|
{
|
|
131
160
|
provide: 'Authentication',
|
|
@@ -1084,372 +1113,85 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1084
1113
|
}] }];
|
|
1085
1114
|
} });
|
|
1086
1115
|
|
|
1087
|
-
class
|
|
1088
|
-
constructor(
|
|
1089
|
-
this.
|
|
1116
|
+
class CheckoutService {
|
|
1117
|
+
constructor(checkoutRepository, userRepository, defaultShop, dataPersistence, firebaseOptions, http) {
|
|
1118
|
+
this.checkoutRepository = checkoutRepository;
|
|
1119
|
+
this.userRepository = userRepository;
|
|
1090
1120
|
this.defaultShop = defaultShop;
|
|
1091
|
-
this.
|
|
1092
|
-
this.
|
|
1093
|
-
this.
|
|
1121
|
+
this.dataPersistence = dataPersistence;
|
|
1122
|
+
this.firebaseOptions = firebaseOptions;
|
|
1123
|
+
this.http = http;
|
|
1124
|
+
this.checkoutUrl = null;
|
|
1125
|
+
this.checkoutUrl = `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`;
|
|
1094
1126
|
}
|
|
1095
|
-
|
|
1096
|
-
return
|
|
1097
|
-
.
|
|
1098
|
-
|
|
1099
|
-
nickname: { operator: Where.EQUALS, value: nickname },
|
|
1100
|
-
active: { operator: Where.EQUALS, value: true },
|
|
1101
|
-
},
|
|
1102
|
-
})
|
|
1103
|
-
.then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
|
|
1127
|
+
getCheckout(checkoutData) {
|
|
1128
|
+
return this.dataPersistence
|
|
1129
|
+
.get('checkoutId')
|
|
1130
|
+
.pipe(concatMap((id) => (!isNil(id) ? this.checkoutRepository.get({ id }) : this.createCheckout(checkoutData))));
|
|
1104
1131
|
}
|
|
1105
|
-
|
|
1106
|
-
return
|
|
1107
|
-
if (!coupon)
|
|
1108
|
-
throw 'Cupom inválido.';
|
|
1109
|
-
if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt.getTime()) > new Date().getTime())
|
|
1110
|
-
throw 'Cupom inválido.';
|
|
1111
|
-
if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn.getTime()) < new Date().getTime())
|
|
1112
|
-
throw 'Cupom expirado.';
|
|
1113
|
-
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
1114
|
-
if (!isInShop)
|
|
1115
|
-
throw 'Cupom inválido para loja.';
|
|
1116
|
-
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
1117
|
-
if (!isCheckoutType)
|
|
1118
|
-
throw 'Cupom inválido. Erro de checkout.';
|
|
1119
|
-
return coupon;
|
|
1120
|
-
});
|
|
1132
|
+
getUserByCheckout(checkoutId) {
|
|
1133
|
+
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'))));
|
|
1121
1134
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1125
|
-
if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
|
|
1126
|
-
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
|
|
1127
|
-
throw 'Cupom inválido para sua assinatura.';
|
|
1128
|
-
return coupon;
|
|
1129
|
-
}
|
|
1130
|
-
const validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
|
|
1131
|
-
if (!validUser)
|
|
1132
|
-
throw 'Usuário não elegível.';
|
|
1133
|
-
const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
1134
|
-
if (couponUseLimits.firstOrder) {
|
|
1135
|
-
const ordersUser = yield this.getOrdersFromUser(checkout.user.email.toLocaleLowerCase());
|
|
1136
|
-
if (couponUseLimits.firstOrder && ordersUser.length >= 1)
|
|
1137
|
-
throw 'Limite de uso atingido';
|
|
1138
|
-
}
|
|
1139
|
-
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
1140
|
-
const ordersCoupon = yield this.getOrdersWithCoupon(coupon);
|
|
1141
|
-
if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total)
|
|
1142
|
-
throw 'Limite de uso atingido.';
|
|
1143
|
-
if (couponUseLimits.limitedPerUser) {
|
|
1144
|
-
const ordersWithUser = this.countOrdersWithUser(ordersCoupon, checkout.user.email);
|
|
1145
|
-
if (ordersWithUser > 0)
|
|
1146
|
-
throw 'Limite de uso por usuário atingido.';
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
|
|
1150
|
-
if (!hasProductCategories)
|
|
1151
|
-
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
1152
|
-
const hasMinSubTotal = yield this.hasMinSubTotal(coupon, checkout);
|
|
1153
|
-
if (!hasMinSubTotal) {
|
|
1154
|
-
if ((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1155
|
-
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido na(s) categoria(s) elegíveis para o desconto.`;
|
|
1156
|
-
}
|
|
1157
|
-
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido.`;
|
|
1158
|
-
}
|
|
1159
|
-
return coupon;
|
|
1160
|
-
});
|
|
1135
|
+
updateCheckoutLineItems(checkout) {
|
|
1136
|
+
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
|
|
1161
1137
|
}
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
|
|
1165
|
-
discount = coupon.discount.subscription.value;
|
|
1166
|
-
else
|
|
1167
|
-
discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
|
|
1168
|
-
return of(discount);
|
|
1138
|
+
updateCheckoutUser(checkout) {
|
|
1139
|
+
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
|
|
1169
1140
|
}
|
|
1170
|
-
|
|
1171
|
-
return
|
|
1172
|
-
let discountInfo = null;
|
|
1173
|
-
if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
|
|
1174
|
-
discountInfo = yield this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
|
|
1175
|
-
}
|
|
1176
|
-
else {
|
|
1177
|
-
discountInfo = yield this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
|
|
1178
|
-
}
|
|
1179
|
-
return { discount: discountInfo.discount, lineItems: discountInfo.lineItems };
|
|
1180
|
-
});
|
|
1141
|
+
clearCheckoutFromSession() {
|
|
1142
|
+
return this.dataPersistence.remove('checkoutId');
|
|
1181
1143
|
}
|
|
1182
|
-
|
|
1183
|
-
return
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
const subTotal = checkout.shipping.ShippingPrice;
|
|
1187
|
-
const discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
|
|
1188
|
-
return { discount, lineItems: checkout.lineItems };
|
|
1189
|
-
}
|
|
1190
|
-
const lineItensElegibleForDiscount = yield this.getLineItensEligebleForDiscount(categories, checkout);
|
|
1191
|
-
const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user);
|
|
1192
|
-
if (type == CouponTypes.ABSOLUTE) {
|
|
1193
|
-
discount = value > subTotal ? subTotal : value;
|
|
1194
|
-
}
|
|
1195
|
-
else {
|
|
1196
|
-
discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
|
|
1197
|
-
}
|
|
1198
|
-
const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
|
|
1199
|
-
return { discount, lineItems };
|
|
1200
|
-
});
|
|
1144
|
+
resetCheckoutValues() {
|
|
1145
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutResetValues`, {
|
|
1146
|
+
checkoutId: checkout.id,
|
|
1147
|
+
})), concatMap(() => this.getCheckout()));
|
|
1201
1148
|
}
|
|
1202
|
-
|
|
1203
|
-
return
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
if (coupon.minSubTotalValue <= subTotal)
|
|
1209
|
-
return true;
|
|
1210
|
-
return false;
|
|
1211
|
-
});
|
|
1149
|
+
applyCouponDiscount(nickname, checkoutType) {
|
|
1150
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutApplyDiscount`, {
|
|
1151
|
+
checkoutId: checkout.id,
|
|
1152
|
+
coupon: nickname,
|
|
1153
|
+
checkoutType,
|
|
1154
|
+
})), concatMap(() => this.getCheckout()), map((checkout) => checkout.coupon));
|
|
1212
1155
|
}
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
return true;
|
|
1218
|
-
}
|
|
1219
|
-
const couponCategories = yield this.getCouponCategoriesId(coupon.productsCategories);
|
|
1220
|
-
const hasCategories = (_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.filter((item) => {
|
|
1221
|
-
var _a;
|
|
1222
|
-
if (item.isGift)
|
|
1223
|
-
return false;
|
|
1224
|
-
if (!item.categories || !((_a = item.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
1225
|
-
return true;
|
|
1226
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
1227
|
-
});
|
|
1228
|
-
return hasCategories.length ? true : false;
|
|
1229
|
-
});
|
|
1156
|
+
removeCouponDiscount() {
|
|
1157
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutRemoveDiscount`, {
|
|
1158
|
+
checkoutId: checkout.id,
|
|
1159
|
+
})), concatMap(() => this.getCheckout()));
|
|
1230
1160
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
|
|
1236
|
-
this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
|
|
1237
|
-
userTypes.push(Exclusivities.COLLABORATORS);
|
|
1238
|
-
if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) &&
|
|
1239
|
-
coupon.userExclusiveEmail.includes(user.email.toLocaleLowerCase()))
|
|
1240
|
-
userTypes.push(Exclusivities.SPECIFIC_USER);
|
|
1241
|
-
if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
1242
|
-
user.isSubscriber &&
|
|
1243
|
-
user.subscriptionPlan != '')
|
|
1244
|
-
userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
|
|
1245
|
-
if (user.isSubscriber &&
|
|
1246
|
-
user.subscriptionPlan == '' &&
|
|
1247
|
-
coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
|
|
1248
|
-
userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
|
|
1249
|
-
if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
|
|
1250
|
-
userTypes.push(Exclusivities.NON_SUBSCRIBER);
|
|
1251
|
-
return coupon.exclusivityType.some((r) => userTypes.includes(r));
|
|
1161
|
+
validateStockProducts() {
|
|
1162
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutValidateProductStock`, {
|
|
1163
|
+
checkoutId: checkout.id,
|
|
1164
|
+
})));
|
|
1252
1165
|
}
|
|
1253
|
-
|
|
1254
|
-
return
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
const category = yield this.categoryRepository.get({
|
|
1258
|
-
id: productsCategories[index],
|
|
1259
|
-
});
|
|
1260
|
-
if (category) {
|
|
1261
|
-
const children = yield this.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
1262
|
-
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
return [...new Set(couponCategories)];
|
|
1266
|
-
});
|
|
1166
|
+
selectShippingAddress(address) {
|
|
1167
|
+
return this.getCheckout().pipe(concatMap((checkout) => {
|
|
1168
|
+
return this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, shippingAddress: address, billingAddress: address }));
|
|
1169
|
+
}));
|
|
1267
1170
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
const couponCategories = yield this.getCouponCategoriesId(productsCategories);
|
|
1273
|
-
if (productsCategories && productsCategories.length) {
|
|
1274
|
-
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((item) => {
|
|
1275
|
-
var _a;
|
|
1276
|
-
if (item.isGift)
|
|
1277
|
-
return false;
|
|
1278
|
-
if ((_a = item.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1279
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
1280
|
-
}
|
|
1281
|
-
return true;
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
|
-
else {
|
|
1285
|
-
lineItensDiscount = checkout.lineItems.filter((item) => !item.isGift);
|
|
1286
|
-
}
|
|
1287
|
-
return lineItensDiscount;
|
|
1171
|
+
getAvailableShippingForProduct(productShipping) {
|
|
1172
|
+
return this.http.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
|
|
1173
|
+
checkoutId: null,
|
|
1174
|
+
productShipping,
|
|
1288
1175
|
});
|
|
1289
1176
|
}
|
|
1290
|
-
|
|
1291
|
-
return (
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
: acc + curr.pricePaid * curr.quantity;
|
|
1296
|
-
}, 0)) || 0);
|
|
1177
|
+
getAvailableShippingForCheckout() {
|
|
1178
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
|
|
1179
|
+
checkoutId: checkout.id,
|
|
1180
|
+
productShipping: null,
|
|
1181
|
+
})));
|
|
1297
1182
|
}
|
|
1298
|
-
|
|
1299
|
-
return
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
coupon: { id: coupon.id },
|
|
1304
|
-
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
1305
|
-
},
|
|
1306
|
-
})
|
|
1307
|
-
.then((result) => result.data);
|
|
1308
|
-
});
|
|
1183
|
+
selectShipping(option) {
|
|
1184
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutSelectShipping`, {
|
|
1185
|
+
checkoutId: checkout.id,
|
|
1186
|
+
shippingOption: option,
|
|
1187
|
+
})), concatMap(() => this.getCheckout()));
|
|
1309
1188
|
}
|
|
1310
|
-
|
|
1311
|
-
return
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
filters: {
|
|
1315
|
-
user: { email: { operator: Where.EQUALS, value: email } },
|
|
1316
|
-
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
1317
|
-
},
|
|
1318
|
-
})
|
|
1319
|
-
.then((result) => result.data);
|
|
1189
|
+
createOrder(checkoutPayload, paymentProvider, applicationVersion) {
|
|
1190
|
+
return this.http.post(`${this.checkoutUrl}/checkout`, {
|
|
1191
|
+
data: Object.assign(Object.assign({}, checkoutPayload), { applicationVersion,
|
|
1192
|
+
paymentProvider }),
|
|
1320
1193
|
});
|
|
1321
1194
|
}
|
|
1322
|
-
countOrdersWithUser(orders, email) {
|
|
1323
|
-
return orders.filter((o) => o.user.email == email).length;
|
|
1324
|
-
}
|
|
1325
|
-
getCouponUseLimits(coupon, checkoutType, user) {
|
|
1326
|
-
let couponUseLimits;
|
|
1327
|
-
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
1328
|
-
if (coupon.exclusivityType.length === 1 &&
|
|
1329
|
-
(coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
|
|
1330
|
-
coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
|
|
1331
|
-
couponUseLimits = coupon.useLimits.non_subscriber;
|
|
1332
|
-
else
|
|
1333
|
-
couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
1334
|
-
}
|
|
1335
|
-
else {
|
|
1336
|
-
couponUseLimits = coupon.useLimits.subscription;
|
|
1337
|
-
}
|
|
1338
|
-
return couponUseLimits;
|
|
1339
|
-
}
|
|
1340
|
-
calcLineItenDiscount(type, lineItems, couponDiscount, subTotal) {
|
|
1341
|
-
let lineItemsDiscount = [];
|
|
1342
|
-
if (type === CouponTypes.ABSOLUTE) {
|
|
1343
|
-
const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
|
|
1344
|
-
lineItemsDiscount = lineItems.map((item) => {
|
|
1345
|
-
if (item.isGift)
|
|
1346
|
-
return item;
|
|
1347
|
-
const totalItemPercentage = item.pricePaid / subTotal;
|
|
1348
|
-
const discountItem = couponDiscountMax * totalItemPercentage;
|
|
1349
|
-
return Object.assign(Object.assign({}, item), { discount: Number(discountItem.toFixed(2)) });
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
else {
|
|
1353
|
-
lineItemsDiscount = lineItems.map((item) => {
|
|
1354
|
-
if (item.isGift)
|
|
1355
|
-
return item;
|
|
1356
|
-
const discountItem = item.pricePaid * (couponDiscount / 100);
|
|
1357
|
-
return Object.assign(Object.assign({}, item), { discount: Number(discountItem.toFixed(2)) });
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1360
|
-
return lineItemsDiscount;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1364
|
-
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
1365
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
|
|
1366
|
-
type: Injectable,
|
|
1367
|
-
args: [{
|
|
1368
|
-
providedIn: 'root',
|
|
1369
|
-
}]
|
|
1370
|
-
}], ctorParameters: function () {
|
|
1371
|
-
return [{ type: undefined, decorators: [{
|
|
1372
|
-
type: Inject,
|
|
1373
|
-
args: ['CouponRepository']
|
|
1374
|
-
}] }, { type: i1$2.Shops, decorators: [{
|
|
1375
|
-
type: Inject,
|
|
1376
|
-
args: [DEFAULT_SHOP]
|
|
1377
|
-
}] }, { type: undefined, decorators: [{
|
|
1378
|
-
type: Inject,
|
|
1379
|
-
args: ['OrderRepository']
|
|
1380
|
-
}] }, { type: undefined, decorators: [{
|
|
1381
|
-
type: Inject,
|
|
1382
|
-
args: ['CategoryRepository']
|
|
1383
|
-
}] }];
|
|
1384
|
-
} });
|
|
1385
|
-
|
|
1386
|
-
class CheckoutService {
|
|
1387
|
-
constructor(couponService, checkoutRepository, userRepository, defaultShop, dataPersistence, http) {
|
|
1388
|
-
this.couponService = couponService;
|
|
1389
|
-
this.checkoutRepository = checkoutRepository;
|
|
1390
|
-
this.userRepository = userRepository;
|
|
1391
|
-
this.defaultShop = defaultShop;
|
|
1392
|
-
this.dataPersistence = dataPersistence;
|
|
1393
|
-
this.http = http;
|
|
1394
|
-
this.checkoutUrl = null;
|
|
1395
|
-
// this.checkoutUrl = `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`
|
|
1396
|
-
this.checkoutUrl = `http://docker.for.localhost:5001/b4astage-cb80a/southamerica-east1`;
|
|
1397
|
-
}
|
|
1398
|
-
getCheckout(checkoutData) {
|
|
1399
|
-
return this.dataPersistence
|
|
1400
|
-
.get('checkoutId')
|
|
1401
|
-
.pipe(concatMap((id) => (!isNil(id) ? this.checkoutRepository.get({ id }) : this.createCheckout(checkoutData))));
|
|
1402
|
-
}
|
|
1403
|
-
getUserByCheckout(checkoutId) {
|
|
1404
|
-
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'))));
|
|
1405
|
-
}
|
|
1406
|
-
updateCheckoutLineItems(checkout) {
|
|
1407
|
-
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems })));
|
|
1408
|
-
}
|
|
1409
|
-
updateCheckoutUser(checkout) {
|
|
1410
|
-
return from(this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })));
|
|
1411
|
-
}
|
|
1412
|
-
clearCheckoutFromSession() {
|
|
1413
|
-
return this.dataPersistence.remove('checkoutId');
|
|
1414
|
-
}
|
|
1415
|
-
// calcDiscount(coupon: Coupon) {
|
|
1416
|
-
// return this.getCheckout().pipe(
|
|
1417
|
-
// concatMap(async (checkout) => await this.couponService.calcDiscountShopping(coupon, checkout)),
|
|
1418
|
-
// )
|
|
1419
|
-
// }
|
|
1420
|
-
checkCoupon(nickname, checkoutType) {
|
|
1421
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutApplyDiscount`, {
|
|
1422
|
-
checkoutId: checkout.id,
|
|
1423
|
-
coupon: nickname,
|
|
1424
|
-
checkoutType,
|
|
1425
|
-
})), concatMap(() => this.getCheckout()), map((checkout) => checkout.coupon));
|
|
1426
|
-
// return this.getCheckout().pipe(
|
|
1427
|
-
// concatMap((checkout) => this.couponService.checkCoupon(nickname, CheckoutTypes.ECOMMERCE, checkout, null).pipe()),
|
|
1428
|
-
// )
|
|
1429
|
-
}
|
|
1430
|
-
validateStockProducts() {
|
|
1431
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutValidateProductStock`, {
|
|
1432
|
-
checkoutId: checkout.id,
|
|
1433
|
-
})));
|
|
1434
|
-
}
|
|
1435
|
-
getShippingProduct(shippingProduct) {
|
|
1436
|
-
return this.http.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
|
|
1437
|
-
checkoutId: null,
|
|
1438
|
-
shippingProduct,
|
|
1439
|
-
});
|
|
1440
|
-
}
|
|
1441
|
-
getAvailableShipping(productShipping) {
|
|
1442
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
|
|
1443
|
-
checkoutId: checkout.id,
|
|
1444
|
-
productShipping,
|
|
1445
|
-
})));
|
|
1446
|
-
}
|
|
1447
|
-
selectShipping(option) {
|
|
1448
|
-
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutSelectShipping`, {
|
|
1449
|
-
checkoutId: checkout.id,
|
|
1450
|
-
shippingOption: option,
|
|
1451
|
-
})), concatMap(() => this.getCheckout()));
|
|
1452
|
-
}
|
|
1453
1195
|
createCheckout(checkoutData) {
|
|
1454
1196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1455
1197
|
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 }));
|
|
@@ -1458,176 +1200,77 @@ class CheckoutService {
|
|
|
1458
1200
|
});
|
|
1459
1201
|
}
|
|
1460
1202
|
}
|
|
1461
|
-
CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token:
|
|
1203
|
+
CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token: 'CheckoutRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }, { token: PERSISTENCE_PROVIDER }, { token: FIREBASE_OPTIONS }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1462
1204
|
CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService });
|
|
1463
1205
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, decorators: [{
|
|
1464
1206
|
type: Injectable
|
|
1465
1207
|
}], ctorParameters: function () {
|
|
1466
|
-
return [{ type:
|
|
1208
|
+
return [{ type: undefined, decorators: [{
|
|
1467
1209
|
type: Inject,
|
|
1468
1210
|
args: ['CheckoutRepository']
|
|
1469
1211
|
}] }, { type: undefined, decorators: [{
|
|
1470
1212
|
type: Inject,
|
|
1471
1213
|
args: ['UserRepository']
|
|
1472
|
-
}] }, { type: i1$
|
|
1214
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
1473
1215
|
type: Inject,
|
|
1474
1216
|
args: [DEFAULT_SHOP]
|
|
1475
1217
|
}] }, { type: undefined, decorators: [{
|
|
1476
1218
|
type: Inject,
|
|
1477
1219
|
args: [PERSISTENCE_PROVIDER]
|
|
1478
|
-
}] }, { type:
|
|
1220
|
+
}] }, { type: undefined, decorators: [{
|
|
1221
|
+
type: Inject,
|
|
1222
|
+
args: [FIREBASE_OPTIONS]
|
|
1223
|
+
}] }, { type: i1$2.HttpClient }];
|
|
1479
1224
|
} });
|
|
1480
1225
|
|
|
1481
1226
|
class CartService {
|
|
1482
|
-
constructor(authService, checkoutService, defaultShop, firebaseOptions,
|
|
1227
|
+
constructor(authService, checkoutService, defaultShop, firebaseOptions, http) {
|
|
1483
1228
|
this.authService = authService;
|
|
1484
1229
|
this.checkoutService = checkoutService;
|
|
1485
1230
|
this.defaultShop = defaultShop;
|
|
1486
1231
|
this.firebaseOptions = firebaseOptions;
|
|
1487
|
-
this.productRepository = productRepository;
|
|
1488
|
-
this.categoryRepository = categoryRepository;
|
|
1489
|
-
this.variantRepository = variantRepository;
|
|
1490
|
-
this.buy2WinRepository = buy2WinRepository;
|
|
1491
1232
|
this.http = http;
|
|
1492
1233
|
this.cartSubject = new Subject();
|
|
1493
1234
|
this.checkoutUrl = null;
|
|
1494
|
-
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
1495
|
-
var _a, _b, _c;
|
|
1496
|
-
const items = [];
|
|
1497
|
-
const index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
|
|
1498
|
-
const isGift = (_c = (_b = checkoutLoaded.lineItems) === null || _b === void 0 ? void 0 : _b[index]) === null || _c === void 0 ? void 0 : _c.isGift;
|
|
1499
|
-
if (index > -1) {
|
|
1500
|
-
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
1501
|
-
checkoutLoaded.lineItems[index].pricePaid = isGift ? 0 : lineItem.pricePaid;
|
|
1502
|
-
checkoutLoaded.lineItems[index].price = lineItem.price;
|
|
1503
|
-
}
|
|
1504
|
-
else
|
|
1505
|
-
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
1506
|
-
return this.checkoutService
|
|
1507
|
-
.updateCheckoutLineItems(checkoutLoaded)
|
|
1508
|
-
.pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
|
|
1509
|
-
}));
|
|
1510
1235
|
this.generateCartObject = (items) => (items === null || items === void 0 ? void 0 : items.reduce((cart, item) => {
|
|
1511
1236
|
var _a;
|
|
1512
1237
|
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) })) }));
|
|
1513
1238
|
}, {})) || {};
|
|
1514
|
-
|
|
1515
|
-
this.checkoutUrl = `http://docker.for.localhost:5001/b4astage-cb80a/southamerica-east1`;
|
|
1239
|
+
this.checkoutUrl = `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`;
|
|
1516
1240
|
}
|
|
1517
1241
|
addItem(item, quantity = 1) {
|
|
1518
|
-
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => {
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
quantity,
|
|
1524
|
-
});
|
|
1525
|
-
}), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => {
|
|
1526
|
-
console.log('updatedCheckout', updatedCheckout);
|
|
1527
|
-
return this.generateCartObject(updatedCheckout.lineItems);
|
|
1528
|
-
}), tap((cart) => this.cartSubject.next(cart)));
|
|
1529
|
-
// return this.generateCartObject(checkoutUpdated.lineItems as LineItem[])
|
|
1530
|
-
// return from(this.checkoutService.getCheckout()).pipe(
|
|
1531
|
-
// concatMap(async (checkout) => await this.buildLineItem({ checkout, item, quantity: quantity || 1 })),
|
|
1532
|
-
// mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout as Checkout)),
|
|
1533
|
-
// tap((cart) => this.cartSubject.next(cart)),
|
|
1534
|
-
// )
|
|
1242
|
+
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutAddItemToCart`, {
|
|
1243
|
+
checkoutId: checkout.id,
|
|
1244
|
+
productId: item.id,
|
|
1245
|
+
quantity,
|
|
1246
|
+
})), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1535
1247
|
}
|
|
1536
1248
|
decreaseItem(item) {
|
|
1537
1249
|
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutDecreaseProductFromCart`, {
|
|
1538
1250
|
checkoutId: checkout.id,
|
|
1539
1251
|
productId: item.id,
|
|
1540
1252
|
quantity: 1,
|
|
1541
|
-
})), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) =>
|
|
1542
|
-
console.log('updatedCheckout', updatedCheckout);
|
|
1543
|
-
return this.generateCartObject(updatedCheckout.lineItems);
|
|
1544
|
-
}), tap((cart) => this.cartSubject.next(cart)));
|
|
1545
|
-
// return this.checkoutService.getCheckout().pipe(
|
|
1546
|
-
// map((checkout) => {
|
|
1547
|
-
// const checkoutItem = checkout.lineItems?.find((lineItem) => lineItem.id === item.id)
|
|
1548
|
-
// if (!isNil(checkoutItem)) checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0
|
|
1549
|
-
// return checkout
|
|
1550
|
-
// }),
|
|
1551
|
-
// concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)),
|
|
1552
|
-
// map((checkout) => this.generateCartObject(checkout.lineItems)),
|
|
1553
|
-
// tap((cart) => this.cartSubject.next(cart)),
|
|
1554
|
-
// )
|
|
1253
|
+
})), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1555
1254
|
}
|
|
1556
1255
|
removeItem(item) {
|
|
1557
1256
|
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutRemoveProductFromCart`, {
|
|
1558
1257
|
checkoutId: checkout.id,
|
|
1559
1258
|
productId: item.id,
|
|
1560
|
-
})), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) =>
|
|
1561
|
-
console.log('updatedCheckout', updatedCheckout);
|
|
1562
|
-
return this.generateCartObject(updatedCheckout.lineItems);
|
|
1563
|
-
}), tap((cart) => this.cartSubject.next(cart)));
|
|
1564
|
-
// return this.checkoutService.getCheckout().pipe(
|
|
1565
|
-
// map((checkout) => {
|
|
1566
|
-
// const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id)
|
|
1567
|
-
// if (index >= 0) checkout.lineItems.splice(index, 1)
|
|
1568
|
-
// return checkout
|
|
1569
|
-
// }),
|
|
1570
|
-
// concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)),
|
|
1571
|
-
// map((checkout) => this.generateCartObject(checkout.lineItems)),
|
|
1572
|
-
// tap((cart) => this.cartSubject.next(cart)),
|
|
1259
|
+
})), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1573
1260
|
}
|
|
1574
1261
|
updateUserCart(user) {
|
|
1575
|
-
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => {
|
|
1576
|
-
console.log('getCheckout', checkout);
|
|
1577
|
-
return this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })));
|
|
1578
|
-
}), concatMap((checkout) => {
|
|
1579
|
-
console.log('getCheckout User', checkout);
|
|
1580
|
-
this.user = user;
|
|
1262
|
+
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => {
|
|
1581
1263
|
return this.http.post(`${this.checkoutUrl}/checkoutUpdateUserCart`, {
|
|
1582
1264
|
checkoutId: checkout.id,
|
|
1583
1265
|
});
|
|
1584
1266
|
}), concatMap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => {
|
|
1585
|
-
console.log('updatedCheckout', updatedCheckout);
|
|
1586
1267
|
return this.generateCartObject(updatedCheckout.lineItems);
|
|
1587
1268
|
}), tap((cart) => this.cartSubject.next(cart)));
|
|
1588
|
-
// return this.checkoutService.getCheckout().pipe(
|
|
1589
|
-
// concatMap((checkout) =>
|
|
1590
|
-
// this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user })),
|
|
1591
|
-
// ),
|
|
1592
|
-
// concatMap(
|
|
1593
|
-
// async (checkout) =>
|
|
1594
|
-
// await this.checkoutService
|
|
1595
|
-
// .updateCheckoutLineItems(
|
|
1596
|
-
// Checkout.toInstance({
|
|
1597
|
-
// ...checkout.toPlain(),
|
|
1598
|
-
// lineItems: checkout.lineItems?.length
|
|
1599
|
-
// ? await Promise.all(
|
|
1600
|
-
// checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem),
|
|
1601
|
-
// )
|
|
1602
|
-
// : [],
|
|
1603
|
-
// }),
|
|
1604
|
-
// )
|
|
1605
|
-
// .toPromise(),
|
|
1606
|
-
// ),
|
|
1607
|
-
// map((checkout) => this.generateCartObject(checkout.lineItems)),
|
|
1608
|
-
// tap((cart) => (this.user = user)),
|
|
1609
|
-
// tap((cart) => this.cartSubject.next(cart)),
|
|
1610
|
-
// )
|
|
1611
1269
|
}
|
|
1612
1270
|
getCart(checkout) {
|
|
1613
1271
|
this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
|
|
1614
1272
|
return this.cartSubject;
|
|
1615
1273
|
}
|
|
1616
|
-
// /**
|
|
1617
|
-
// * @deprecated The method should not be used
|
|
1618
|
-
// */
|
|
1619
|
-
// getVariantPriceDiscount(item: LineItem): Observable<number> {
|
|
1620
|
-
// return this.authService.getUser().pipe(
|
|
1621
|
-
// concatMap((user) =>
|
|
1622
|
-
// iif(
|
|
1623
|
-
// () => user.isSubscriber && !!item.price.subscriberPrice,
|
|
1624
|
-
// of(item.price.subscriberPrice),
|
|
1625
|
-
// of(item.price.price),
|
|
1626
|
-
// ),
|
|
1627
|
-
// ),
|
|
1628
|
-
// catchError(() => of(item.price.price)),
|
|
1629
|
-
// )
|
|
1630
|
-
// }
|
|
1631
1274
|
clearCart() {
|
|
1632
1275
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
1633
1276
|
this.checkoutService.clearCheckoutFromSession();
|
|
@@ -1638,30 +1281,18 @@ class CartService {
|
|
|
1638
1281
|
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
1639
1282
|
}
|
|
1640
1283
|
}
|
|
1641
|
-
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: FIREBASE_OPTIONS }, { token:
|
|
1284
|
+
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: FIREBASE_OPTIONS }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1642
1285
|
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
|
|
1643
1286
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
|
|
1644
1287
|
type: Injectable
|
|
1645
1288
|
}], ctorParameters: function () {
|
|
1646
|
-
return [{ type: AuthService }, { type: CheckoutService }, { type: i1$
|
|
1289
|
+
return [{ type: AuthService }, { type: CheckoutService }, { type: i1$3.Shops, decorators: [{
|
|
1647
1290
|
type: Inject,
|
|
1648
1291
|
args: [DEFAULT_SHOP]
|
|
1649
1292
|
}] }, { type: undefined, decorators: [{
|
|
1650
1293
|
type: Inject,
|
|
1651
1294
|
args: [FIREBASE_OPTIONS]
|
|
1652
|
-
}] }, { type:
|
|
1653
|
-
type: Inject,
|
|
1654
|
-
args: ['ProductRepository']
|
|
1655
|
-
}] }, { type: undefined, decorators: [{
|
|
1656
|
-
type: Inject,
|
|
1657
|
-
args: ['CategoryRepository']
|
|
1658
|
-
}] }, { type: undefined, decorators: [{
|
|
1659
|
-
type: Inject,
|
|
1660
|
-
args: ['VariantRepository']
|
|
1661
|
-
}] }, { type: i1$2.Buy2WinFirestoreRepository, decorators: [{
|
|
1662
|
-
type: Inject,
|
|
1663
|
-
args: ['Buy2WinRepository']
|
|
1664
|
-
}] }, { type: i2.HttpClient }];
|
|
1295
|
+
}] }, { type: i1$2.HttpClient }];
|
|
1665
1296
|
} });
|
|
1666
1297
|
|
|
1667
1298
|
class NewCategoryStructureAdapter {
|
|
@@ -2002,7 +1633,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2002
1633
|
}] }, { type: undefined, decorators: [{
|
|
2003
1634
|
type: Inject,
|
|
2004
1635
|
args: [CATEGORY_STRUCTURE]
|
|
2005
|
-
}] }, { type: i1$
|
|
1636
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
2006
1637
|
type: Inject,
|
|
2007
1638
|
args: [DEFAULT_SHOP]
|
|
2008
1639
|
}] }, { type: undefined, decorators: [{
|
|
@@ -2057,7 +1688,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2057
1688
|
}] }, { type: undefined, decorators: [{
|
|
2058
1689
|
type: Inject,
|
|
2059
1690
|
args: [CATEGORY_STRUCTURE]
|
|
2060
|
-
}] }, { type: i1$
|
|
1691
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
2061
1692
|
type: Inject,
|
|
2062
1693
|
args: [DEFAULT_SHOP]
|
|
2063
1694
|
}] }];
|
|
@@ -2302,7 +1933,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2302
1933
|
return [{ type: undefined, decorators: [{
|
|
2303
1934
|
type: Inject,
|
|
2304
1935
|
args: ['WishlistRepository']
|
|
2305
|
-
}] }, { type: i1$
|
|
1936
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
2306
1937
|
type: Inject,
|
|
2307
1938
|
args: [DEFAULT_SHOP]
|
|
2308
1939
|
}] }, { type: undefined, decorators: [{
|
|
@@ -2326,6 +1957,251 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2326
1957
|
}] }];
|
|
2327
1958
|
} });
|
|
2328
1959
|
|
|
1960
|
+
class CouponService {
|
|
1961
|
+
constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
|
|
1962
|
+
this.couponRepository = couponRepository;
|
|
1963
|
+
this.defaultShop = defaultShop;
|
|
1964
|
+
this.orderRepository = orderRepository;
|
|
1965
|
+
this.categoryRepository = categoryRepository;
|
|
1966
|
+
this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
|
|
1967
|
+
}
|
|
1968
|
+
checkCoupon(nickname, checkoutType, checkout, plan) {
|
|
1969
|
+
return from(this.couponRepository
|
|
1970
|
+
.find({
|
|
1971
|
+
filters: {
|
|
1972
|
+
nickname: { operator: Where.EQUALS, value: nickname },
|
|
1973
|
+
active: { operator: Where.EQUALS, value: true },
|
|
1974
|
+
},
|
|
1975
|
+
})
|
|
1976
|
+
.then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
|
|
1977
|
+
}
|
|
1978
|
+
couponValidation(coupon, checkoutType) {
|
|
1979
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1980
|
+
if (!coupon)
|
|
1981
|
+
throw 'Cupom inválido.';
|
|
1982
|
+
if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt.getTime()) > new Date().getTime())
|
|
1983
|
+
throw 'Cupom inválido.';
|
|
1984
|
+
if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn).getTime() < new Date().getTime())
|
|
1985
|
+
throw 'Cupom expirado.';
|
|
1986
|
+
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
1987
|
+
if (!isInShop)
|
|
1988
|
+
throw 'Cupom inválido para loja.';
|
|
1989
|
+
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
1990
|
+
if (!isCheckoutType)
|
|
1991
|
+
throw 'Cupom inválido. Erro de checkout.';
|
|
1992
|
+
return coupon;
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
couponRulesValidation(coupon, checkoutType, checkout, plan) {
|
|
1996
|
+
var _a;
|
|
1997
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1998
|
+
if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
|
|
1999
|
+
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
|
|
2000
|
+
throw 'Cupom inválido para sua assinatura.';
|
|
2001
|
+
return coupon;
|
|
2002
|
+
}
|
|
2003
|
+
const validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
|
|
2004
|
+
if (!validUser)
|
|
2005
|
+
throw 'Usuário não elegível.';
|
|
2006
|
+
const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
2007
|
+
if (couponUseLimits.firstOrder) {
|
|
2008
|
+
const ordersUser = yield this.getOrdersFromUser(checkout.user.email.toLocaleLowerCase());
|
|
2009
|
+
if (couponUseLimits.firstOrder && ordersUser.length >= 1)
|
|
2010
|
+
throw 'Limite de uso atingido';
|
|
2011
|
+
}
|
|
2012
|
+
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
2013
|
+
const ordersCoupon = yield this.getOrdersWithCoupon(coupon);
|
|
2014
|
+
if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total)
|
|
2015
|
+
throw 'Limite de uso atingido.';
|
|
2016
|
+
if (couponUseLimits.limitedPerUser) {
|
|
2017
|
+
const ordersWithUser = this.countOrdersWithUser(ordersCoupon, checkout.user.email);
|
|
2018
|
+
if (ordersWithUser > 0)
|
|
2019
|
+
throw 'Limite de uso por usuário atingido.';
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
|
|
2023
|
+
if (!hasProductCategories)
|
|
2024
|
+
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
2025
|
+
const hasMinSubTotal = yield this.hasMinSubTotal(coupon, checkout);
|
|
2026
|
+
if (!hasMinSubTotal) {
|
|
2027
|
+
if ((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2028
|
+
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido na(s) categoria(s) elegíveis para o desconto.`;
|
|
2029
|
+
}
|
|
2030
|
+
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido.`;
|
|
2031
|
+
}
|
|
2032
|
+
return coupon;
|
|
2033
|
+
});
|
|
2034
|
+
}
|
|
2035
|
+
calcDiscountSubscription(coupon, checkout) {
|
|
2036
|
+
let discount = 0;
|
|
2037
|
+
if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
|
|
2038
|
+
discount = coupon.discount.subscription.value;
|
|
2039
|
+
else
|
|
2040
|
+
discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
|
|
2041
|
+
return of(discount);
|
|
2042
|
+
}
|
|
2043
|
+
hasMinSubTotal(coupon, checkout) {
|
|
2044
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2045
|
+
if (!coupon.minSubTotalValue)
|
|
2046
|
+
return true;
|
|
2047
|
+
const lineItensDiscount = yield this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
|
|
2048
|
+
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
|
|
2049
|
+
if (coupon.minSubTotalValue <= subTotal)
|
|
2050
|
+
return true;
|
|
2051
|
+
return false;
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
hasProductCategories(coupon, checkout) {
|
|
2055
|
+
var _a, _b;
|
|
2056
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2057
|
+
if (!coupon.productsCategories || !((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
2058
|
+
return true;
|
|
2059
|
+
}
|
|
2060
|
+
const couponCategories = yield this.getCouponCategoriesId(coupon.productsCategories);
|
|
2061
|
+
const hasCategories = (_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.filter((item) => {
|
|
2062
|
+
var _a;
|
|
2063
|
+
if (item.isGift)
|
|
2064
|
+
return false;
|
|
2065
|
+
if (!item.categories || !((_a = item.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
2066
|
+
return true;
|
|
2067
|
+
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2068
|
+
});
|
|
2069
|
+
return hasCategories.length ? true : false;
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
coupomUserValidation(coupon, user) {
|
|
2073
|
+
if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
|
|
2074
|
+
return true;
|
|
2075
|
+
let userTypes = [];
|
|
2076
|
+
if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
|
|
2077
|
+
this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
|
|
2078
|
+
userTypes.push(Exclusivities.COLLABORATORS);
|
|
2079
|
+
if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) &&
|
|
2080
|
+
coupon.userExclusiveEmail.includes(user.email.toLocaleLowerCase()))
|
|
2081
|
+
userTypes.push(Exclusivities.SPECIFIC_USER);
|
|
2082
|
+
if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
2083
|
+
user.isSubscriber &&
|
|
2084
|
+
user.subscriptionPlan != '')
|
|
2085
|
+
userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
|
|
2086
|
+
if (user.isSubscriber &&
|
|
2087
|
+
user.subscriptionPlan == '' &&
|
|
2088
|
+
coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
|
|
2089
|
+
userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
|
|
2090
|
+
if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
|
|
2091
|
+
userTypes.push(Exclusivities.NON_SUBSCRIBER);
|
|
2092
|
+
return coupon.exclusivityType.some((r) => userTypes.includes(r));
|
|
2093
|
+
}
|
|
2094
|
+
getCouponCategoriesId(productsCategories) {
|
|
2095
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2096
|
+
const couponCategories = [];
|
|
2097
|
+
for (let index = 0; index < productsCategories.length; index++) {
|
|
2098
|
+
const category = yield this.categoryRepository.get({
|
|
2099
|
+
id: productsCategories[index],
|
|
2100
|
+
});
|
|
2101
|
+
if (category) {
|
|
2102
|
+
const children = yield this.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
2103
|
+
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
return [...new Set(couponCategories)];
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
2110
|
+
var _a;
|
|
2111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2112
|
+
let lineItensDiscount = [];
|
|
2113
|
+
const couponCategories = yield this.getCouponCategoriesId(productsCategories);
|
|
2114
|
+
if (productsCategories && productsCategories.length) {
|
|
2115
|
+
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((item) => {
|
|
2116
|
+
var _a;
|
|
2117
|
+
if (item.isGift)
|
|
2118
|
+
return false;
|
|
2119
|
+
if ((_a = item.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2120
|
+
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2121
|
+
}
|
|
2122
|
+
return true;
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
else {
|
|
2126
|
+
lineItensDiscount = checkout.lineItems.filter((item) => !item.isGift);
|
|
2127
|
+
}
|
|
2128
|
+
return lineItensDiscount;
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
calcCheckoutSubtotal(lineItens, user) {
|
|
2132
|
+
return ((lineItens === null || lineItens === void 0 ? void 0 : lineItens.filter((item) => !item.isGift).reduce((acc, curr) => {
|
|
2133
|
+
var _a;
|
|
2134
|
+
return (user === null || user === void 0 ? void 0 : user.isSubscriber) && curr.price.subscriberPrice
|
|
2135
|
+
? acc + ((_a = curr.price) === null || _a === void 0 ? void 0 : _a.subscriberPrice) * curr.quantity
|
|
2136
|
+
: acc + curr.pricePaid * curr.quantity;
|
|
2137
|
+
}, 0)) || 0);
|
|
2138
|
+
}
|
|
2139
|
+
getOrdersWithCoupon(coupon) {
|
|
2140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2141
|
+
return yield this.orderRepository
|
|
2142
|
+
.find({
|
|
2143
|
+
filters: {
|
|
2144
|
+
coupon: { id: coupon.id },
|
|
2145
|
+
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
2146
|
+
},
|
|
2147
|
+
})
|
|
2148
|
+
.then((result) => result.data);
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
getOrdersFromUser(email) {
|
|
2152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2153
|
+
return yield this.orderRepository
|
|
2154
|
+
.find({
|
|
2155
|
+
filters: {
|
|
2156
|
+
user: { email: { operator: Where.EQUALS, value: email } },
|
|
2157
|
+
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
2158
|
+
},
|
|
2159
|
+
})
|
|
2160
|
+
.then((result) => result.data);
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
countOrdersWithUser(orders, email) {
|
|
2164
|
+
return orders.filter((o) => o.user.email == email).length;
|
|
2165
|
+
}
|
|
2166
|
+
getCouponUseLimits(coupon, checkoutType, user) {
|
|
2167
|
+
let couponUseLimits;
|
|
2168
|
+
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
2169
|
+
if (coupon.exclusivityType.length === 1 &&
|
|
2170
|
+
(coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
|
|
2171
|
+
coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
|
|
2172
|
+
couponUseLimits = coupon.useLimits.non_subscriber;
|
|
2173
|
+
else
|
|
2174
|
+
couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
2175
|
+
}
|
|
2176
|
+
else {
|
|
2177
|
+
couponUseLimits = coupon.useLimits.subscription;
|
|
2178
|
+
}
|
|
2179
|
+
return couponUseLimits;
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2183
|
+
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
2184
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
|
|
2185
|
+
type: Injectable,
|
|
2186
|
+
args: [{
|
|
2187
|
+
providedIn: 'root',
|
|
2188
|
+
}]
|
|
2189
|
+
}], ctorParameters: function () {
|
|
2190
|
+
return [{ type: undefined, decorators: [{
|
|
2191
|
+
type: Inject,
|
|
2192
|
+
args: ['CouponRepository']
|
|
2193
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
2194
|
+
type: Inject,
|
|
2195
|
+
args: [DEFAULT_SHOP]
|
|
2196
|
+
}] }, { type: undefined, decorators: [{
|
|
2197
|
+
type: Inject,
|
|
2198
|
+
args: ['OrderRepository']
|
|
2199
|
+
}] }, { type: undefined, decorators: [{
|
|
2200
|
+
type: Inject,
|
|
2201
|
+
args: ['CategoryRepository']
|
|
2202
|
+
}] }];
|
|
2203
|
+
} });
|
|
2204
|
+
|
|
2329
2205
|
class CheckoutSubscriptionService {
|
|
2330
2206
|
constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {
|
|
2331
2207
|
this.checkoutSubscriptionRepository = checkoutSubscriptionRepository;
|
|
@@ -2502,7 +2378,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2502
2378
|
}] }, { type: undefined, decorators: [{
|
|
2503
2379
|
type: Inject,
|
|
2504
2380
|
args: ['ProductRepository']
|
|
2505
|
-
}] }, { type: i1$
|
|
2381
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
2506
2382
|
type: Inject,
|
|
2507
2383
|
args: [DEFAULT_SHOP]
|
|
2508
2384
|
}] }];
|
|
@@ -2526,7 +2402,7 @@ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version
|
|
|
2526
2402
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
|
|
2527
2403
|
type: Injectable
|
|
2528
2404
|
}], ctorParameters: function () {
|
|
2529
|
-
return [{ type: i1$1.Firestore }, { type: i1$
|
|
2405
|
+
return [{ type: i1$1.Firestore }, { type: i1$3.OrderFirestoreRepository, decorators: [{
|
|
2530
2406
|
type: Inject,
|
|
2531
2407
|
args: ['OrderRepository']
|
|
2532
2408
|
}] }];
|
|
@@ -2537,6 +2413,8 @@ class AngularConnectModule {
|
|
|
2537
2413
|
return {
|
|
2538
2414
|
ngModule: AngularConnectModule,
|
|
2539
2415
|
providers: [
|
|
2416
|
+
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig },
|
|
2417
|
+
{ provide: APP_CHECK_PROVIDER, useValue: options.appCheckProvider },
|
|
2540
2418
|
{
|
|
2541
2419
|
provide: CATEGORY_STRUCTURE,
|
|
2542
2420
|
useClass: isNil(options === null || options === void 0 ? void 0 : options.oldCategoryStructure) || (options === null || options === void 0 ? void 0 : options.oldCategoryStructure)
|
|
@@ -2546,7 +2424,6 @@ class AngularConnectModule {
|
|
|
2546
2424
|
{ provide: PERSISTENCE_PROVIDER, useClass: (options === null || options === void 0 ? void 0 : options.persistenceProvider) || CookieDataPersistence },
|
|
2547
2425
|
...(isNil(defaultShop) ? [] : [{ provide: DEFAULT_SHOP, useValue: defaultShop }]),
|
|
2548
2426
|
...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_OPTIONS, useValue: options === null || options === void 0 ? void 0 : options.firebase }]),
|
|
2549
|
-
...(isNil(options === null || options === void 0 ? void 0 : options.firebase) ? [] : [{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }]),
|
|
2550
2427
|
...(isNil(options === null || options === void 0 ? void 0 : options.elasticSearch) ? [] : [{ provide: ES_CONFIG, useValue: options.elasticSearch }]),
|
|
2551
2428
|
...(isNil(options === null || options === void 0 ? void 0 : options.vertexConfig) ? [] : [{ provide: VERTEX_CONFIG, useValue: options.vertexConfig }]),
|
|
2552
2429
|
...(isNil(options === null || options === void 0 ? void 0 : options.hasura) ? [] : [{ provide: HASURA_OPTIONS, useValue: options.hasura }]),
|
|
@@ -2557,7 +2434,7 @@ class AngularConnectModule {
|
|
|
2557
2434
|
}
|
|
2558
2435
|
}
|
|
2559
2436
|
AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
2560
|
-
AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$
|
|
2437
|
+
AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, i2.AppCheckModule, i3.StorageModule, AngularElasticSeachModule,
|
|
2561
2438
|
AngularVertexSeachModule,
|
|
2562
2439
|
AngularFirebaseAuthModule,
|
|
2563
2440
|
AngularFirestoreModule,
|
|
@@ -2592,14 +2469,34 @@ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ve
|
|
|
2592
2469
|
useExisting: ProductsVertexSearch,
|
|
2593
2470
|
},
|
|
2594
2471
|
], imports: [provideFirebaseApp((injector) => {
|
|
2595
|
-
const appName = injector.get(FIREBASE_APP_NAME)
|
|
2472
|
+
const appName = injector.get(FIREBASE_APP_NAME);
|
|
2596
2473
|
try {
|
|
2597
|
-
|
|
2474
|
+
const app = appName ? getApp(appName) : getApp();
|
|
2475
|
+
return app;
|
|
2598
2476
|
}
|
|
2599
2477
|
catch (error) {
|
|
2478
|
+
console.warn('Firebase app not found, initializing new app');
|
|
2479
|
+
if (error instanceof Error)
|
|
2480
|
+
console.error(error.message);
|
|
2600
2481
|
return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
|
|
2601
2482
|
}
|
|
2602
2483
|
}),
|
|
2484
|
+
provideAppCheck((injector) => {
|
|
2485
|
+
const app = injector.get(FirebaseApp);
|
|
2486
|
+
try {
|
|
2487
|
+
const provider = injector.get(APP_CHECK_PROVIDER);
|
|
2488
|
+
if (provider)
|
|
2489
|
+
return initializeAppCheck(app, {
|
|
2490
|
+
provider,
|
|
2491
|
+
isTokenAutoRefreshEnabled: true,
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
catch (error) {
|
|
2495
|
+
if (error instanceof Error)
|
|
2496
|
+
console.error(error.message);
|
|
2497
|
+
return;
|
|
2498
|
+
}
|
|
2499
|
+
}),
|
|
2603
2500
|
provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
|
|
2604
2501
|
AngularElasticSeachModule,
|
|
2605
2502
|
AngularVertexSeachModule,
|
|
@@ -2611,14 +2508,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2611
2508
|
args: [{
|
|
2612
2509
|
imports: [
|
|
2613
2510
|
provideFirebaseApp((injector) => {
|
|
2614
|
-
const appName = injector.get(FIREBASE_APP_NAME)
|
|
2511
|
+
const appName = injector.get(FIREBASE_APP_NAME);
|
|
2615
2512
|
try {
|
|
2616
|
-
|
|
2513
|
+
const app = appName ? getApp(appName) : getApp();
|
|
2514
|
+
return app;
|
|
2617
2515
|
}
|
|
2618
2516
|
catch (error) {
|
|
2517
|
+
console.warn('Firebase app not found, initializing new app');
|
|
2518
|
+
if (error instanceof Error)
|
|
2519
|
+
console.error(error.message);
|
|
2619
2520
|
return initializeApp(injector.get(FIREBASE_OPTIONS), appName);
|
|
2620
2521
|
}
|
|
2621
2522
|
}),
|
|
2523
|
+
provideAppCheck((injector) => {
|
|
2524
|
+
const app = injector.get(FirebaseApp);
|
|
2525
|
+
try {
|
|
2526
|
+
const provider = injector.get(APP_CHECK_PROVIDER);
|
|
2527
|
+
if (provider)
|
|
2528
|
+
return initializeAppCheck(app, {
|
|
2529
|
+
provider,
|
|
2530
|
+
isTokenAutoRefreshEnabled: true,
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
catch (error) {
|
|
2534
|
+
if (error instanceof Error)
|
|
2535
|
+
console.error(error.message);
|
|
2536
|
+
return;
|
|
2537
|
+
}
|
|
2538
|
+
}),
|
|
2622
2539
|
provideStorage((injector) => getStorage(injector.get(FirebaseApp))),
|
|
2623
2540
|
AngularElasticSeachModule,
|
|
2624
2541
|
AngularVertexSeachModule,
|