@infrab4a/connect 4.0.0-beta.5 → 4.0.0-beta.50
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/domain/catalog/helpers/index.d.ts +1 -0
- package/domain/catalog/helpers/round-product-price.helper.d.ts +4 -0
- package/domain/catalog/index.d.ts +1 -0
- package/domain/catalog/models/category-base.d.ts +30 -0
- package/domain/catalog/models/category-collection-children.d.ts +13 -0
- package/domain/catalog/models/category-filter.d.ts +13 -0
- package/domain/catalog/models/category-for-product.d.ts +5 -0
- package/domain/catalog/models/category.d.ts +5 -22
- package/domain/catalog/models/filter-option.d.ts +9 -0
- package/domain/catalog/models/filter.d.ts +12 -0
- package/domain/catalog/models/index.d.ts +5 -0
- package/domain/catalog/models/kit-product.d.ts +4 -4
- package/domain/catalog/models/product-base.d.ts +40 -0
- package/domain/catalog/models/product-for-category.d.ts +7 -0
- package/domain/catalog/models/product-for-kit.d.ts +7 -0
- package/domain/catalog/models/product.d.ts +5 -35
- package/domain/catalog/models/types/category-product.d.ts +4 -0
- package/domain/catalog/models/types/index.d.ts +2 -1
- package/domain/catalog/models/types/product-evaluation.type.d.ts +6 -0
- package/domain/catalog/models/types/shop-description.type.d.ts +1 -0
- package/domain/catalog/models/variant.d.ts +1 -2
- package/domain/catalog/models/wishlist.d.ts +6 -0
- package/domain/catalog/repositories/category-collection-children.repository.d.ts +4 -0
- package/domain/catalog/repositories/category-filter.repository.d.ts +6 -0
- package/domain/catalog/repositories/category.repository.d.ts +6 -3
- package/domain/catalog/repositories/filter-option.repository.d.ts +4 -0
- package/domain/catalog/repositories/filter.repository.d.ts +4 -0
- package/domain/catalog/repositories/index.d.ts +5 -0
- package/domain/catalog/repositories/product.repository.d.ts +4 -1
- package/domain/catalog/repositories/wishlist.repository.d.ts +6 -0
- package/domain/generic/model/base.model.d.ts +9 -5
- package/domain/generic/model/types/base-model-builder.type.d.ts +4 -2
- package/domain/generic/model/types/identifier-model.type.d.ts +6 -5
- package/domain/generic/model/types/model-base-structure.type.d.ts +9 -3
- package/domain/generic/model/types/non-function-property-name.type.d.ts +12 -3
- package/domain/generic/repository/find.repository.d.ts +7 -1
- package/domain/generic/repository/get.repository.d.ts +2 -2
- package/domain/generic/repository/types/repository-find-filters.type.d.ts +3 -3
- package/domain/generic/repository/types/repository-find-result.type.d.ts +11 -1
- package/domain/generic/repository/types/repository-order-by-list.type.d.ts +2 -2
- package/domain/generic/repository/types/repository-update-params.type.d.ts +2 -2
- package/domain/location/models/address.d.ts +5 -3
- package/domain/shop-settings/models/index.d.ts +1 -0
- package/domain/shop-settings/models/shop-settings.d.ts +9 -0
- package/domain/shop-settings/models/types/index.d.ts +6 -1
- package/domain/shop-settings/models/types/shop-banner.type.d.ts +12 -0
- package/domain/shop-settings/models/types/shop-brands.type.d.ts +10 -0
- package/domain/shop-settings/models/types/shop-carousel.type.d.ts +5 -0
- package/domain/shop-settings/models/types/shop-collection.type.d.ts +9 -0
- package/domain/shop-settings/models/types/shop-section.type.d.ts +9 -0
- package/domain/shop-settings/repositories/index.d.ts +1 -0
- package/domain/shop-settings/repositories/shop-settings.repository.d.ts +4 -0
- package/domain/shopping/models/buy-2-win.d.ts +3 -1
- package/domain/shopping/models/campaign-dashboard.d.ts +15 -0
- package/domain/shopping/models/campaign-hashtag.d.ts +18 -0
- package/domain/shopping/models/checkout.d.ts +5 -6
- package/domain/shopping/models/coupons/coupon.d.ts +34 -6
- package/domain/shopping/models/index.d.ts +5 -4
- package/domain/shopping/models/order.d.ts +1 -0
- package/domain/shopping/models/shipping-method.d.ts +1 -0
- package/domain/shopping/models/subscription/checkout.d.ts +3 -4
- package/domain/shopping/repositories/campaign-dashboard.repository.d.ts +4 -0
- package/domain/shopping/repositories/campaign-hashtag.repository.d.ts +4 -0
- package/domain/shopping/repositories/index.d.ts +4 -2
- package/domain/users/models/lead.d.ts +1 -0
- package/domain/users/models/subscription/subscription.d.ts +3 -3
- package/domain/users/models/user-address.d.ts +1 -2
- package/domain/users/models/user.d.ts +2 -3
- package/esm2020/domain/catalog/helpers/index.mjs +2 -0
- package/esm2020/domain/catalog/helpers/round-product-price.helper.mjs +15 -0
- package/esm2020/domain/catalog/index.mjs +2 -1
- package/esm2020/domain/catalog/models/category-base.mjs +18 -0
- package/esm2020/domain/catalog/models/category-collection-children.mjs +13 -0
- package/esm2020/domain/catalog/models/category-filter.mjs +19 -0
- package/esm2020/domain/catalog/models/category-for-product.mjs +7 -0
- package/esm2020/domain/catalog/models/category.mjs +10 -6
- package/esm2020/domain/catalog/models/filter-option.mjs +7 -0
- package/esm2020/domain/catalog/models/filter.mjs +7 -0
- package/esm2020/domain/catalog/models/index.mjs +6 -1
- package/esm2020/domain/catalog/models/kit-product.mjs +7 -7
- package/esm2020/domain/catalog/models/product-base.mjs +25 -0
- package/esm2020/domain/catalog/models/product-for-category.mjs +14 -0
- package/esm2020/domain/catalog/models/product-for-kit.mjs +14 -0
- package/esm2020/domain/catalog/models/product.mjs +8 -6
- package/esm2020/domain/catalog/models/types/category-product.mjs +2 -0
- package/esm2020/domain/catalog/models/types/index.mjs +3 -2
- package/esm2020/domain/catalog/models/types/product-evaluation.type.mjs +2 -0
- package/esm2020/domain/catalog/models/types/shop-description.type.mjs +1 -1
- package/esm2020/domain/catalog/models/variant.mjs +1 -4
- package/esm2020/domain/catalog/models/wishlist.mjs +7 -0
- package/esm2020/domain/catalog/repositories/category-collection-children.repository.mjs +2 -0
- package/esm2020/domain/catalog/repositories/category-filter.repository.mjs +2 -0
- package/esm2020/domain/catalog/repositories/category.repository.mjs +1 -1
- package/esm2020/domain/catalog/repositories/filter-option.repository.mjs +2 -0
- package/esm2020/domain/catalog/repositories/filter.repository.mjs +2 -0
- package/esm2020/domain/catalog/repositories/index.mjs +6 -1
- package/esm2020/domain/catalog/repositories/product.repository.mjs +1 -1
- package/esm2020/domain/catalog/repositories/wishlist.repository.mjs +2 -0
- package/esm2020/domain/generic/model/base.model.mjs +3 -2
- package/esm2020/domain/generic/model/types/base-model-builder.type.mjs +1 -1
- package/esm2020/domain/generic/model/types/identifier-model.type.mjs +1 -1
- package/esm2020/domain/generic/model/types/model-base-structure.type.mjs +1 -1
- package/esm2020/domain/generic/model/types/non-function-property-name.type.mjs +1 -1
- package/esm2020/domain/generic/repository/find.repository.mjs +1 -1
- package/esm2020/domain/generic/repository/get.repository.mjs +1 -1
- package/esm2020/domain/generic/repository/types/repository-find-filters.type.mjs +1 -1
- package/esm2020/domain/generic/repository/types/repository-find-result.type.mjs +1 -1
- package/esm2020/domain/generic/repository/types/repository-order-by-list.type.mjs +1 -1
- package/esm2020/domain/generic/repository/types/repository-update-params.type.mjs +1 -1
- package/esm2020/domain/location/models/address.mjs +2 -2
- package/esm2020/domain/shop-settings/models/index.mjs +2 -1
- package/esm2020/domain/shop-settings/models/shop-settings.mjs +7 -0
- package/esm2020/domain/shop-settings/models/types/index.mjs +7 -2
- package/esm2020/domain/shop-settings/models/types/shop-banner.type.mjs +2 -0
- package/esm2020/domain/shop-settings/models/types/shop-brands.type.mjs +2 -0
- package/esm2020/domain/shop-settings/models/types/shop-carousel.type.mjs +2 -0
- package/esm2020/domain/shop-settings/models/types/shop-collection.type.mjs +2 -0
- package/esm2020/domain/shop-settings/models/types/shop-section.type.mjs +2 -0
- package/esm2020/domain/shop-settings/repositories/index.mjs +2 -1
- package/esm2020/domain/shop-settings/repositories/shop-settings.repository.mjs +2 -0
- package/esm2020/domain/shopping/models/buy-2-win.mjs +2 -2
- package/esm2020/domain/shopping/models/campaign-dashboard.mjs +7 -0
- package/esm2020/domain/shopping/models/campaign-hashtag.mjs +7 -0
- package/esm2020/domain/shopping/models/checkout.mjs +6 -7
- package/esm2020/domain/shopping/models/coupons/coupon.mjs +16 -16
- package/esm2020/domain/shopping/models/index.mjs +6 -5
- package/esm2020/domain/shopping/models/order.mjs +1 -1
- package/esm2020/domain/shopping/models/shipping-method.mjs +1 -1
- package/esm2020/domain/shopping/models/subscription/checkout.mjs +6 -6
- package/esm2020/domain/shopping/repositories/campaign-dashboard.repository.mjs +2 -0
- package/esm2020/domain/shopping/repositories/campaign-hashtag.repository.mjs +2 -0
- package/esm2020/domain/shopping/repositories/index.mjs +5 -3
- package/esm2020/domain/users/models/lead.mjs +1 -1
- package/esm2020/domain/users/models/subscription/subscription.mjs +6 -6
- package/esm2020/domain/users/models/user-address.mjs +1 -1
- package/esm2020/domain/users/models/user.mjs +2 -2
- package/esm2020/domain/users/use-cases/authentication.mjs +2 -2
- package/esm2020/infra/elasticsearch/adapters/axios.adapter.mjs +28 -11
- package/esm2020/infra/elasticsearch/adapters/elastic-search.adapter.mjs +1 -1
- package/esm2020/infra/elasticsearch/indexes/products-index.mjs +63 -51
- package/esm2020/infra/elasticsearch/types/elastic-search-result.mjs +1 -1
- package/esm2020/infra/firebase/auth/authentication-firebase-auth.service.mjs +1 -1
- package/esm2020/infra/firebase/firestore/mixins/with-create-firestore.mixin.mjs +8 -4
- package/esm2020/infra/firebase/firestore/mixins/with-crud-firestore.mixin.mjs +1 -1
- package/esm2020/infra/firebase/firestore/mixins/with-delete-firestore.mixin.mjs +6 -2
- package/esm2020/infra/firebase/firestore/mixins/with-find-firestore.mixin.mjs +11 -8
- package/esm2020/infra/firebase/firestore/mixins/with-firestore.mixin.mjs +27 -4
- package/esm2020/infra/firebase/firestore/mixins/with-get-firestore.mixin.mjs +6 -3
- package/esm2020/infra/firebase/firestore/mixins/with-helpers.mixin.mjs +1 -1
- package/esm2020/infra/firebase/firestore/mixins/with-sub-collection.mixin.mjs +5 -3
- package/esm2020/infra/firebase/firestore/mixins/with-update-firestore.mixin.mjs +7 -4
- package/esm2020/infra/firebase/firestore/repositories/catalog/category-firestore.repository.mjs +21 -8
- package/esm2020/infra/firebase/firestore/repositories/catalog/product-firestore.repository.mjs +15 -7
- package/esm2020/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.mjs +10 -8
- package/esm2020/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.mjs +36 -30
- package/esm2020/infra/firebase/firestore/repositories/shop-settings/index.mjs +2 -1
- package/esm2020/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.mjs +14 -0
- package/esm2020/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.mjs +14 -0
- package/esm2020/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.mjs +14 -0
- package/esm2020/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/shopping/index.mjs +6 -4
- package/esm2020/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.mjs +6 -4
- package/esm2020/infra/firebase/firestore/repositories/shopping/order-firestore.repository.mjs +11 -9
- package/esm2020/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/users/lead-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.mjs +10 -8
- package/esm2020/infra/firebase/firestore/repositories/users/subscription-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.mjs +10 -8
- package/esm2020/infra/firebase/firestore/repositories/users/user-address-firestore.repository.mjs +10 -8
- package/esm2020/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.mjs +10 -8
- package/esm2020/infra/firebase/firestore/repositories/users/user-firestore.repository.mjs +8 -6
- package/esm2020/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.mjs +10 -8
- package/esm2020/infra/firebase/firestore/types/firestore-interceptors.type.mjs +2 -0
- package/esm2020/infra/firebase/firestore/types/firestore-sub.repository.type.mjs +1 -1
- package/esm2020/infra/firebase/firestore/types/firestore.helpers.type.mjs +1 -1
- package/esm2020/infra/firebase/firestore/types/firestore.repository.type.mjs +1 -1
- package/esm2020/infra/firebase/firestore/types/index.mjs +4 -3
- package/esm2020/infra/hasura-graphql/mixins/helpers/attribute-option.helper.mjs +3 -3
- package/esm2020/infra/hasura-graphql/mixins/helpers/bind-filter-query.helper.mjs +6 -5
- package/esm2020/infra/hasura-graphql/mixins/helpers/filter-option.helper.mjs +1 -1
- package/esm2020/infra/hasura-graphql/mixins/helpers/graphql-field.helper.mjs +36 -25
- package/esm2020/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.mjs +6 -4
- package/esm2020/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.mjs +1 -1
- package/esm2020/infra/hasura-graphql/mixins/with-delete-hasura-graphql.mixin.mjs +5 -3
- package/esm2020/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.mjs +126 -20
- package/esm2020/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.mjs +5 -3
- package/esm2020/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.mjs +40 -24
- package/esm2020/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.mjs +7 -5
- package/esm2020/infra/hasura-graphql/models/product-hasura-graphql.mjs +1 -1
- package/esm2020/infra/hasura-graphql/models/variant-hasura-graphql.mjs +1 -1
- package/esm2020/infra/hasura-graphql/repositories/catalog/category-collection-children-hasura-graphql.repository.mjs +39 -0
- package/esm2020/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.mjs +107 -0
- package/esm2020/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.mjs +131 -14
- package/esm2020/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.mjs +105 -0
- package/esm2020/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.mjs +22 -0
- package/esm2020/infra/hasura-graphql/repositories/catalog/index.mjs +6 -1
- package/esm2020/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.mjs +70 -20
- package/esm2020/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.mjs +9 -7
- package/esm2020/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.mjs +236 -0
- package/esm2020/infra/hasura-graphql/types/graphql.repository.type.mjs +1 -1
- package/esm2020/infra/hasura-graphql/types/hasura-graphql-fields.type.mjs +1 -1
- package/esm2020/utils/decorators/debug.class.decorator.mjs +7 -0
- package/esm2020/utils/decorators/index.mjs +3 -0
- package/esm2020/utils/decorators/trace.method.decorator.mjs +81 -0
- package/esm2020/utils/helpers/class-name.helper.mjs +15 -0
- package/esm2020/utils/helpers/debug-decorator.helper.mjs +18 -0
- package/esm2020/utils/helpers/debug.helper.mjs +150 -0
- package/esm2020/utils/helpers/index.mjs +5 -0
- package/esm2020/utils/helpers/reflect.helper.mjs +165 -0
- package/esm2020/utils/index.mjs +6 -4
- package/esm2020/utils/log.utils.mjs +9 -0
- package/fesm2015/infrab4a-connect.mjs +2000 -422
- package/fesm2015/infrab4a-connect.mjs.map +1 -1
- package/fesm2020/infrab4a-connect.mjs +1966 -425
- package/fesm2020/infrab4a-connect.mjs.map +1 -1
- package/infra/elasticsearch/adapters/axios.adapter.d.ts +7 -5
- package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +3 -2
- package/infra/elasticsearch/indexes/products-index.d.ts +8 -10
- package/infra/elasticsearch/types/elastic-search-result.d.ts +2 -0
- package/infra/firebase/firestore/mixins/with-create-firestore.mixin.d.ts +2 -2
- package/infra/firebase/firestore/mixins/with-crud-firestore.mixin.d.ts +2 -1
- package/infra/firebase/firestore/mixins/with-delete-firestore.mixin.d.ts +2 -2
- package/infra/firebase/firestore/mixins/with-find-firestore.mixin.d.ts +2 -2
- package/infra/firebase/firestore/mixins/with-firestore.mixin.d.ts +13 -4
- package/infra/firebase/firestore/mixins/with-get-firestore.mixin.d.ts +2 -2
- package/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +2 -2
- package/infra/firebase/firestore/mixins/with-sub-collection.mixin.d.ts +8 -4
- package/infra/firebase/firestore/mixins/with-update-firestore.mixin.d.ts +3 -3
- package/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +8 -5
- package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +6 -5
- package/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +4 -4
- package/infra/firebase/firestore/repositories/shop-settings/index.d.ts +1 -0
- package/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.d.ts +7 -0
- package/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +8 -0
- package/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.d.ts +8 -0
- package/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +4 -4
- package/infra/firebase/firestore/repositories/shopping/index.d.ts +5 -3
- package/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +4 -4
- package/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +4 -4
- package/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +3 -4
- package/infra/firebase/firestore/types/firestore-interceptors.type.d.ts +14 -0
- package/infra/firebase/firestore/types/firestore-sub.repository.type.d.ts +3 -3
- package/infra/firebase/firestore/types/firestore.helpers.type.d.ts +5 -5
- package/infra/firebase/firestore/types/firestore.repository.type.d.ts +3 -1
- package/infra/firebase/firestore/types/index.d.ts +3 -2
- package/infra/hasura-graphql/mixins/helpers/attribute-option.helper.d.ts +9 -3
- package/infra/hasura-graphql/mixins/helpers/bind-filter-query.helper.d.ts +5 -5
- package/infra/hasura-graphql/mixins/helpers/filter-option.helper.d.ts +4 -2
- package/infra/hasura-graphql/mixins/helpers/graphql-field.helper.d.ts +9 -5
- package/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.d.ts +2 -1
- package/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.d.ts +3 -3
- package/infra/hasura-graphql/mixins/with-delete-hasura-graphql.mixin.d.ts +1 -1
- package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +24 -15
- package/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.d.ts +7 -6
- package/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.d.ts +15 -3
- package/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.d.ts +2 -2
- package/infra/hasura-graphql/models/product-hasura-graphql.d.ts +4 -0
- package/infra/hasura-graphql/models/variant-hasura-graphql.d.ts +1 -0
- package/infra/hasura-graphql/repositories/catalog/category-collection-children-hasura-graphql.repository.d.ts +10 -0
- package/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.d.ts +12 -0
- package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +12 -5
- package/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.d.ts +18 -0
- package/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.d.ts +10 -0
- package/infra/hasura-graphql/repositories/catalog/index.d.ts +5 -0
- package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +6 -4
- package/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +4 -4
- package/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +27 -0
- package/infra/hasura-graphql/types/graphql.repository.type.d.ts +9 -6
- package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +7 -3
- package/package.json +2 -1
- package/utils/decorators/debug.class.decorator.d.ts +2 -0
- package/utils/decorators/index.d.ts +2 -0
- package/utils/decorators/trace.method.decorator.d.ts +14 -0
- package/utils/helpers/class-name.helper.d.ts +3 -0
- package/utils/helpers/debug-decorator.helper.d.ts +9 -0
- package/utils/helpers/debug.helper.d.ts +60 -0
- package/utils/helpers/index.d.ts +4 -0
- package/utils/helpers/reflect.helper.d.ts +50 -0
- package/utils/index.d.ts +5 -22
- package/utils/log.utils.d.ts +7 -0
- package/domain/catalog/models/types/category-filter.type.d.ts +0 -4
- package/esm2020/domain/catalog/models/types/category-filter.type.mjs +0 -2
|
@@ -3,19 +3,21 @@ import { plainToInstance, instanceToPlain, Expose, Type } from 'class-transforme
|
|
|
3
3
|
import { __decorate, __metadata } from 'tslib';
|
|
4
4
|
import { parseISO } from 'date-fns';
|
|
5
5
|
export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
|
|
6
|
-
import
|
|
7
|
-
|
|
6
|
+
import { isNil, isArray, first, last, flatten, compact, get as get$1, isString, each, unset, isObject, isNumber, isDate, set, isEmpty, chunk, isBoolean, isInteger, isNaN as isNaN$1, omit } from 'lodash';
|
|
7
|
+
export { chunk, each, get, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set, unset } from 'lodash';
|
|
8
|
+
import { Subject } from 'rxjs';
|
|
9
|
+
import { debug } from 'debug';
|
|
8
10
|
import { CustomError } from 'ts-custom-error';
|
|
9
11
|
import axios from 'axios';
|
|
10
12
|
import { collection, getDoc, doc, where, orderBy, getDocs, query, startAfter, startAt, limit, addDoc, setDoc, deleteField, arrayUnion, arrayRemove, deleteDoc, Timestamp } from 'firebase/firestore';
|
|
11
13
|
import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, signInAnonymously, sendPasswordResetEmail, createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth';
|
|
12
14
|
import { mutation, query as query$1 } from 'gql-query-builder';
|
|
13
|
-
import fetch from 'node-fetch';
|
|
14
15
|
|
|
15
16
|
class BaseModel {
|
|
16
17
|
get identifier() {
|
|
17
18
|
const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
|
|
18
|
-
|
|
19
|
+
const data = this;
|
|
20
|
+
return fields.reduce((object, field) => ({ ...object, [field]: data[field] }), {});
|
|
19
21
|
}
|
|
20
22
|
get identifiersFields() {
|
|
21
23
|
return this.constructor.identifiersFields;
|
|
@@ -461,11 +463,437 @@ __decorate([
|
|
|
461
463
|
__metadata("design:type", Payment)
|
|
462
464
|
], SubscriptionPayment.prototype, "payment", void 0);
|
|
463
465
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
466
|
+
var DebugNamespaces;
|
|
467
|
+
(function (DebugNamespaces) {
|
|
468
|
+
DebugNamespaces["ROOT"] = "connect";
|
|
469
|
+
DebugNamespaces["TRACE"] = "trace";
|
|
470
|
+
DebugNamespaces["ERROR"] = "error";
|
|
471
|
+
})(DebugNamespaces || (DebugNamespaces = {}));
|
|
472
|
+
const Logger = debug(DebugNamespaces.ROOT);
|
|
473
|
+
|
|
474
|
+
class ReflectHelper {
|
|
475
|
+
static get items() {
|
|
476
|
+
return this._items;
|
|
477
|
+
}
|
|
478
|
+
static get keys() {
|
|
479
|
+
return Object.keys(ReflectHelper.items);
|
|
480
|
+
}
|
|
481
|
+
static has(key, target, property) {
|
|
482
|
+
return (!isNil(key) &&
|
|
483
|
+
!isNil(ReflectHelper.items[key]) &&
|
|
484
|
+
(isNil(target) ||
|
|
485
|
+
(!isNil(ReflectHelper.items[key][target]) &&
|
|
486
|
+
(isNil(property) || !isNil(ReflectHelper.items[key][target][String(property)])))));
|
|
487
|
+
}
|
|
488
|
+
static get({ key, target, property, own = true }) {
|
|
489
|
+
try {
|
|
490
|
+
if (own) {
|
|
491
|
+
return Reflect.getOwnMetadata(key, target, property) || null;
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
return Reflect.getMetadata(key, target, property) || null;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
catch (_err) {
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
static first({ key, target, property, own = true }) {
|
|
502
|
+
const values = ReflectHelper.get({ key, target, property, own });
|
|
503
|
+
return isArray(values) ? first(values) : values;
|
|
504
|
+
}
|
|
505
|
+
static last({ key, target, property, own = true }) {
|
|
506
|
+
const values = ReflectHelper.get({ key, target, property, own });
|
|
507
|
+
return isArray(values) ? last(values) : values;
|
|
508
|
+
}
|
|
509
|
+
static set({ key, target, property, value, propertyDescriptor }) {
|
|
510
|
+
Reflect.defineMetadata(key, value, target, property);
|
|
511
|
+
ReflectHelper.put({ key, target, property, value, propertyDescriptor });
|
|
512
|
+
}
|
|
513
|
+
static add({ key, target, property, value, propertyDescriptor }) {
|
|
514
|
+
let values = ReflectHelper.get({ key, target, property }) || new Array();
|
|
515
|
+
if (!Array.isArray(values))
|
|
516
|
+
values = [values];
|
|
517
|
+
values.push(value);
|
|
518
|
+
ReflectHelper.set({ key, target, property, value: values, propertyDescriptor });
|
|
519
|
+
}
|
|
520
|
+
static all({ key }) {
|
|
521
|
+
const items = ReflectHelper.items[key] || {};
|
|
522
|
+
return flatten(Object.keys(items).map((item) => flatten(this.allFrom(key, items[item]))));
|
|
523
|
+
}
|
|
524
|
+
static allFrom(key, target) {
|
|
525
|
+
return Object.keys(target)
|
|
526
|
+
.filter((property) => property !== 'object')
|
|
527
|
+
.map((property) => this.allValuesFrom(key, target, property));
|
|
528
|
+
}
|
|
529
|
+
static allValuesFrom(key, target, property) {
|
|
530
|
+
const values = target[property];
|
|
531
|
+
let value = values.value;
|
|
532
|
+
const propertyDescriptor = values.propertyDescriptor;
|
|
533
|
+
if (!isArray(value))
|
|
534
|
+
value = [value];
|
|
535
|
+
return flatten(value.map((val) => {
|
|
536
|
+
return {
|
|
537
|
+
key,
|
|
538
|
+
target: target.object,
|
|
539
|
+
property,
|
|
540
|
+
value: val,
|
|
541
|
+
propertyDescriptor,
|
|
542
|
+
};
|
|
543
|
+
}));
|
|
544
|
+
}
|
|
545
|
+
static delete({ key, target, property }) {
|
|
546
|
+
Reflect.deleteMetadata(key, target, property);
|
|
547
|
+
return ReflectHelper.remove(key, target, property);
|
|
548
|
+
}
|
|
549
|
+
static clear(key) {
|
|
550
|
+
if (!key) {
|
|
551
|
+
ReflectHelper.keys.forEach((storedKey) => {
|
|
552
|
+
ReflectHelper.clear(storedKey);
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
if (ReflectHelper.keys.includes(key)) {
|
|
557
|
+
Object.values(ReflectHelper.items[key]).forEach((target) => {
|
|
558
|
+
if (ReflectHelper.has(key, target)) {
|
|
559
|
+
Object.values(ReflectHelper.items[key][target.toString()]).forEach((property) => {
|
|
560
|
+
ReflectHelper.delete({
|
|
561
|
+
key,
|
|
562
|
+
target: target.object,
|
|
563
|
+
property: String(property),
|
|
564
|
+
});
|
|
565
|
+
ReflectHelper.remove(key, target, String(property));
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
ReflectHelper.delete({ key, target: target.object });
|
|
569
|
+
ReflectHelper.remove(key, target);
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
static getType({ target, propertyKey }) {
|
|
575
|
+
return Reflect.getMetadata('design:type', target, propertyKey);
|
|
576
|
+
}
|
|
577
|
+
static getReturntype({ target, propertyKey }) {
|
|
578
|
+
return Reflect.getMetadata('design:returntype', target, propertyKey);
|
|
579
|
+
}
|
|
580
|
+
static getAllMethods(target) {
|
|
581
|
+
const props = [];
|
|
582
|
+
let obj = target;
|
|
583
|
+
do {
|
|
584
|
+
props.push(...Object.getOwnPropertyNames(obj));
|
|
585
|
+
} while ((obj = Object.getPrototypeOf(obj)));
|
|
586
|
+
return props.sort().filter((e, i, arr) => {
|
|
587
|
+
if ([
|
|
588
|
+
'__defineGetter__',
|
|
589
|
+
'__defineSetter__',
|
|
590
|
+
'__lookupGetter__',
|
|
591
|
+
'__lookupSetter__',
|
|
592
|
+
'constructor',
|
|
593
|
+
'hasOwnProperty',
|
|
594
|
+
'isPrototypeOf',
|
|
595
|
+
'propertyIsEnumerable',
|
|
596
|
+
'toLocaleString',
|
|
597
|
+
'toString',
|
|
598
|
+
'valueOf',
|
|
599
|
+
].includes(e))
|
|
600
|
+
return false;
|
|
601
|
+
if (e != arr[i + 1] && typeof target[e] === 'function')
|
|
602
|
+
return true;
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
static put({ key, target, property, value, propertyDescriptor }) {
|
|
606
|
+
const index = target.constructor.name;
|
|
607
|
+
ReflectHelper.items[key] = ReflectHelper.items[key] || {};
|
|
608
|
+
ReflectHelper.items[key][index] = ReflectHelper.items[key][index] || {};
|
|
609
|
+
ReflectHelper.items[key][index].object = target;
|
|
610
|
+
if (isNil(property)) {
|
|
611
|
+
ReflectHelper.items[key][index].value = {
|
|
612
|
+
value,
|
|
613
|
+
propertyDescriptor,
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
ReflectHelper.items[key][index][String(property)] = ReflectHelper.items[key][index][String(property)] || {};
|
|
618
|
+
ReflectHelper.items[key][index][String(property)] = {
|
|
619
|
+
value,
|
|
620
|
+
propertyDescriptor,
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
static remove(key, target, property) {
|
|
625
|
+
if (ReflectHelper.has(key, target, property))
|
|
626
|
+
return delete ReflectHelper.items[key][target][String(property)];
|
|
627
|
+
else if (ReflectHelper.has(key, target))
|
|
628
|
+
return delete ReflectHelper.items[key][target];
|
|
629
|
+
else if (ReflectHelper.has(key))
|
|
630
|
+
return delete ReflectHelper.items[key];
|
|
631
|
+
else
|
|
632
|
+
return false;
|
|
467
633
|
}
|
|
468
634
|
}
|
|
635
|
+
ReflectHelper._items = {};
|
|
636
|
+
|
|
637
|
+
class DebugDecoratorHelper {
|
|
638
|
+
static set(target, options) {
|
|
639
|
+
ReflectHelper.add({
|
|
640
|
+
key: DebugDecoratorHelper.DebugNamingMetadataKey,
|
|
641
|
+
target,
|
|
642
|
+
value: options,
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
static get(target) {
|
|
646
|
+
return ReflectHelper.first({
|
|
647
|
+
key: DebugDecoratorHelper.DebugNamingMetadataKey,
|
|
648
|
+
target,
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
DebugDecoratorHelper.DebugNamingMetadataKey = 'model:naming:decorator';
|
|
653
|
+
|
|
654
|
+
class ClassNameHelper {
|
|
655
|
+
static get(clazz) {
|
|
656
|
+
if (!clazz)
|
|
657
|
+
return null;
|
|
658
|
+
const prototype = Object.getPrototypeOf(clazz);
|
|
659
|
+
const names = compact([
|
|
660
|
+
get$1(clazz, 'constructor.name'),
|
|
661
|
+
get$1(prototype, 'constructor.name'),
|
|
662
|
+
get$1(prototype, '__proto__.constructor.name'),
|
|
663
|
+
]);
|
|
664
|
+
return names.find((name) => name !== 'class_1');
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const isDebuggable = (object) => {
|
|
669
|
+
return 'debug' in object;
|
|
670
|
+
};
|
|
671
|
+
class DebugHelper {
|
|
672
|
+
constructor(...namespace) {
|
|
673
|
+
this.namespaces = new Set();
|
|
674
|
+
this.push(...namespace);
|
|
675
|
+
}
|
|
676
|
+
static namespacesFor(target) {
|
|
677
|
+
if (isNil(target))
|
|
678
|
+
return [];
|
|
679
|
+
const decorator = DebugDecoratorHelper.get(Object.getPrototypeOf(target));
|
|
680
|
+
const namespaces = get$1(decorator, 'namespaces', []);
|
|
681
|
+
const name = get$1(decorator, 'name', ClassNameHelper.get(target));
|
|
682
|
+
return [...namespaces, name];
|
|
683
|
+
}
|
|
684
|
+
static as(...namespaces) {
|
|
685
|
+
return new DebugHelper(...namespaces);
|
|
686
|
+
}
|
|
687
|
+
static for(target, ...namespaces) {
|
|
688
|
+
const targetNamespaces = this.namespacesFor(target);
|
|
689
|
+
return new DebugHelper(...targetNamespaces, ...namespaces);
|
|
690
|
+
}
|
|
691
|
+
static from(target, ...namespaces) {
|
|
692
|
+
if (this.isDebuggable(target)) {
|
|
693
|
+
const debug = target.debug;
|
|
694
|
+
if (namespaces)
|
|
695
|
+
debug.push(...namespaces);
|
|
696
|
+
return debug;
|
|
697
|
+
}
|
|
698
|
+
return DebugHelper.for(target, ...namespaces);
|
|
699
|
+
}
|
|
700
|
+
static clonedFrom(target, ...namespaces) {
|
|
701
|
+
if (this.isDebuggable(target)) {
|
|
702
|
+
namespaces.push(...target.debug.entries);
|
|
703
|
+
}
|
|
704
|
+
else if (!isNil(target)) {
|
|
705
|
+
namespaces.push(...this.namespacesFor(target));
|
|
706
|
+
}
|
|
707
|
+
return DebugHelper.for(target, ...namespaces);
|
|
708
|
+
}
|
|
709
|
+
static clone(target, ...namespaces) {
|
|
710
|
+
let original;
|
|
711
|
+
if (this.isDebuggable(target)) {
|
|
712
|
+
original = target.debug;
|
|
713
|
+
namespaces.push(...original.entries);
|
|
714
|
+
}
|
|
715
|
+
return {
|
|
716
|
+
original,
|
|
717
|
+
debug: DebugHelper.for(target, ...namespaces),
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
static replace(target, attrs) {
|
|
721
|
+
if (this.isDebuggable(target))
|
|
722
|
+
target.debug = attrs.with;
|
|
723
|
+
}
|
|
724
|
+
static mock(target, ...namespaces) {
|
|
725
|
+
const { original, debug } = DebugHelper.clone(target, ...namespaces);
|
|
726
|
+
DebugHelper.replace(target, { with: debug });
|
|
727
|
+
return { original, debug };
|
|
728
|
+
}
|
|
729
|
+
get entries() {
|
|
730
|
+
return Array.from(get$1(this, 'namespaces', []));
|
|
731
|
+
}
|
|
732
|
+
get namespace() {
|
|
733
|
+
return compact(flatten(this.entries)).join(':');
|
|
734
|
+
}
|
|
735
|
+
log(message, ...args) {
|
|
736
|
+
this.logger(JSON.stringify(message), ...args.map((element) => JSON.stringify(element)));
|
|
737
|
+
DebugHelper.logs$.next({ namespace: this.namespace, message, args });
|
|
738
|
+
return this;
|
|
739
|
+
}
|
|
740
|
+
trace(message, ...args) {
|
|
741
|
+
this.logger.extend(DebugNamespaces.TRACE)(message, ...args);
|
|
742
|
+
DebugHelper.traces$.next({ namespace: this.namespace, message, args });
|
|
743
|
+
return this;
|
|
744
|
+
}
|
|
745
|
+
error(error, ...args) {
|
|
746
|
+
this.logger.extend(DebugNamespaces.ERROR)(JSON.stringify(error), ...args.map((element) => JSON.stringify(element)));
|
|
747
|
+
DebugHelper.errors$.next({ namespace: this.namespace, error, args });
|
|
748
|
+
return this;
|
|
749
|
+
}
|
|
750
|
+
build() {
|
|
751
|
+
this.logger = Logger;
|
|
752
|
+
this.tracer = Logger;
|
|
753
|
+
this.err = Logger;
|
|
754
|
+
this.entries.forEach((namespace) => {
|
|
755
|
+
this.logger = this.logger.extend(namespace);
|
|
756
|
+
this.tracer = this.tracer.extend(namespace);
|
|
757
|
+
this.err = this.err.extend(namespace);
|
|
758
|
+
});
|
|
759
|
+
return this;
|
|
760
|
+
}
|
|
761
|
+
with(...namespace) {
|
|
762
|
+
return new DebugHelper(...this.entries, ...namespace);
|
|
763
|
+
}
|
|
764
|
+
push(...namespace) {
|
|
765
|
+
if (namespace) {
|
|
766
|
+
namespace.filter((item) => Boolean(item)).forEach((item) => this.namespaces.add(item));
|
|
767
|
+
}
|
|
768
|
+
return this.build();
|
|
769
|
+
}
|
|
770
|
+
unshift(...namespace) {
|
|
771
|
+
if (namespace) {
|
|
772
|
+
return this.reset(...namespace, ...this.entries);
|
|
773
|
+
}
|
|
774
|
+
return this;
|
|
775
|
+
}
|
|
776
|
+
reset(...namespace) {
|
|
777
|
+
this.namespaces = new Set(flatten(compact(namespace)));
|
|
778
|
+
return this.build();
|
|
779
|
+
}
|
|
780
|
+
startWith(...namespace) {
|
|
781
|
+
const current = this.namespaces;
|
|
782
|
+
this.namespaces = new Set(flatten([compact(namespace), ...current]));
|
|
783
|
+
return this.build();
|
|
784
|
+
}
|
|
785
|
+
shift() {
|
|
786
|
+
const list = this.entries;
|
|
787
|
+
list.shift();
|
|
788
|
+
return this.reset(...list);
|
|
789
|
+
}
|
|
790
|
+
pop() {
|
|
791
|
+
const list = this.entries;
|
|
792
|
+
list.pop();
|
|
793
|
+
return this.reset(...list);
|
|
794
|
+
}
|
|
795
|
+
clear() {
|
|
796
|
+
return this.reset();
|
|
797
|
+
}
|
|
798
|
+
remove(...namespace) {
|
|
799
|
+
if (namespace) {
|
|
800
|
+
namespace.filter((item) => Boolean(item)).forEach((item) => this.namespaces.delete(item));
|
|
801
|
+
}
|
|
802
|
+
return this.build();
|
|
803
|
+
}
|
|
804
|
+
puts(...args) {
|
|
805
|
+
return [`[${this.namespace}]`, ...args].join(' ');
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
DebugHelper.logs$ = new Subject();
|
|
809
|
+
DebugHelper.traces$ = new Subject();
|
|
810
|
+
DebugHelper.errors$ = new Subject();
|
|
811
|
+
DebugHelper.isDebuggable = isDebuggable;
|
|
812
|
+
|
|
813
|
+
function Debug(opts) {
|
|
814
|
+
return function (target) {
|
|
815
|
+
DebugDecoratorHelper.set(target.prototype, opts);
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
const ASYNC_IDENTIFIER = 'async';
|
|
820
|
+
function Log(options = {}) {
|
|
821
|
+
return Trace({ level: 'log', ...options });
|
|
822
|
+
}
|
|
823
|
+
function Trace(options = {}) {
|
|
824
|
+
return function (target, propertyKey, propertyDescriptor) {
|
|
825
|
+
const method = propertyDescriptor.value;
|
|
826
|
+
const isPromise = method.toString().includes(ASYNC_IDENTIFIER);
|
|
827
|
+
const args = {
|
|
828
|
+
options,
|
|
829
|
+
method,
|
|
830
|
+
target,
|
|
831
|
+
propertyKey,
|
|
832
|
+
propertyDescriptor,
|
|
833
|
+
};
|
|
834
|
+
propertyDescriptor.value = isPromise ? promiseTracer(args) : functionTracer(args);
|
|
835
|
+
return propertyDescriptor;
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
const traceCall = function ({ target, propertyKey, propertyDescriptor, args }) {
|
|
839
|
+
if (!target.debug)
|
|
840
|
+
target.debug = DebugHelper.for(target, propertyKey);
|
|
841
|
+
return target.debug.push(propertyKey).trace('called', { target, propertyKey, propertyDescriptor, args });
|
|
842
|
+
};
|
|
843
|
+
const promiseTracer = function ({ options, method, propertyKey, propertyDescriptor }) {
|
|
844
|
+
return function (...args) {
|
|
845
|
+
return new Promise((resolve, reject) => {
|
|
846
|
+
const debug = traceCall({ target: this, propertyDescriptor, propertyKey, args });
|
|
847
|
+
if (get$1(options, 'level', '') === 'log') {
|
|
848
|
+
debug.with('params').log(args);
|
|
849
|
+
}
|
|
850
|
+
return method
|
|
851
|
+
.apply(this, args)
|
|
852
|
+
.then((result) => {
|
|
853
|
+
if (options.callbackFn) {
|
|
854
|
+
options.callbackFn({ target: this, result, args, namespace: [propertyKey] });
|
|
855
|
+
}
|
|
856
|
+
if (get$1(options, 'level', '') === 'log') {
|
|
857
|
+
debug.with('returns').log(result === undefined ? 'void' : result);
|
|
858
|
+
}
|
|
859
|
+
return resolve(result);
|
|
860
|
+
})
|
|
861
|
+
.catch((error) => {
|
|
862
|
+
debug.error(error, ...args);
|
|
863
|
+
debug.with('stack').error(error.stack).pop();
|
|
864
|
+
return reject(error);
|
|
865
|
+
})
|
|
866
|
+
.finally(() => {
|
|
867
|
+
return debug.trace('finally', { args }).pop();
|
|
868
|
+
});
|
|
869
|
+
});
|
|
870
|
+
};
|
|
871
|
+
};
|
|
872
|
+
const functionTracer = function ({ options, target, method, propertyKey, propertyDescriptor, }) {
|
|
873
|
+
return function (...args) {
|
|
874
|
+
const debug = traceCall({ target: this || target, propertyDescriptor, propertyKey, args });
|
|
875
|
+
if (get$1(options, 'level', '') === 'log') {
|
|
876
|
+
debug.with('params').log(args);
|
|
877
|
+
}
|
|
878
|
+
let result;
|
|
879
|
+
try {
|
|
880
|
+
result = method.apply(this, args);
|
|
881
|
+
if (options.callbackFn)
|
|
882
|
+
options.callbackFn({ target: this, result, args, namespace: [propertyKey] });
|
|
883
|
+
if (get$1(options, 'level', '') === 'log') {
|
|
884
|
+
debug.with('returns').log(result === undefined ? 'void' : result);
|
|
885
|
+
}
|
|
886
|
+
return result;
|
|
887
|
+
}
|
|
888
|
+
catch (error) {
|
|
889
|
+
debug.error(error, ...args).pop();
|
|
890
|
+
throw error;
|
|
891
|
+
}
|
|
892
|
+
finally {
|
|
893
|
+
debug.trace('finally', { args }).pop();
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
};
|
|
469
897
|
|
|
470
898
|
const get = (object, path, defaultValue) => get$1(object, path, defaultValue);
|
|
471
899
|
|
|
@@ -473,7 +901,7 @@ function is(value) {
|
|
|
473
901
|
return value;
|
|
474
902
|
}
|
|
475
903
|
|
|
476
|
-
const isUUID = (value) => isString
|
|
904
|
+
const isUUID = (value) => isString(value) && /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(value);
|
|
477
905
|
|
|
478
906
|
class Base {
|
|
479
907
|
constructor(...args) {
|
|
@@ -482,7 +910,7 @@ class Base {
|
|
|
482
910
|
}
|
|
483
911
|
|
|
484
912
|
const parseDateTime = (value) => {
|
|
485
|
-
if (!isString
|
|
913
|
+
if (!isString(value))
|
|
486
914
|
return value;
|
|
487
915
|
if (!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(value) &&
|
|
488
916
|
!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T\d{2}:\d{2}:\d{2}/.test(value))
|
|
@@ -493,8 +921,6 @@ const parseDateTime = (value) => {
|
|
|
493
921
|
return date;
|
|
494
922
|
};
|
|
495
923
|
|
|
496
|
-
const { chunk, isBoolean, isDate, isEmpty, isInteger, isNaN: isNaN$1, isNil, isNumber, isObject, isString, now, omit, pick, set, } = lodash;
|
|
497
|
-
|
|
498
924
|
var CheckoutTypes;
|
|
499
925
|
(function (CheckoutTypes) {
|
|
500
926
|
CheckoutTypes[CheckoutTypes["ECOMMERCE"] = 1] = "ECOMMERCE";
|
|
@@ -539,26 +965,28 @@ class Coupon extends BaseModel {
|
|
|
539
965
|
static createCoupon(userId) {
|
|
540
966
|
return this.toInstance({
|
|
541
967
|
nickname: `${Date.now()}`,
|
|
542
|
-
type: CouponTypes.ABSOLUTE,
|
|
543
968
|
checkoutType: CheckoutTypes.ECOMMERCE,
|
|
544
|
-
discount:
|
|
969
|
+
discount: {
|
|
970
|
+
subscriber: {
|
|
971
|
+
type: CouponTypes.ABSOLUTE,
|
|
972
|
+
value: 10,
|
|
973
|
+
},
|
|
974
|
+
non_subscriber: {
|
|
975
|
+
type: CouponTypes.ABSOLUTE,
|
|
976
|
+
value: 10,
|
|
977
|
+
},
|
|
978
|
+
subscription: {
|
|
979
|
+
type: CouponTypes.ABSOLUTE,
|
|
980
|
+
value: 10,
|
|
981
|
+
},
|
|
982
|
+
},
|
|
545
983
|
user: userId,
|
|
546
|
-
useLimit: 1,
|
|
547
|
-
useLimitPerUser: true,
|
|
548
984
|
createdAt: new Date(Date.now()),
|
|
549
985
|
beginAt: new Date(Date.now()),
|
|
550
986
|
expiresIn: new Date(Date.now() + COUPON_EXPIRATION),
|
|
551
987
|
});
|
|
552
988
|
}
|
|
553
989
|
}
|
|
554
|
-
__decorate([
|
|
555
|
-
Expose({ name: 'checkout_type' }),
|
|
556
|
-
__metadata("design:type", Number)
|
|
557
|
-
], Coupon.prototype, "checkoutType", void 0);
|
|
558
|
-
__decorate([
|
|
559
|
-
Expose({ name: 'exclusivity_type' }),
|
|
560
|
-
__metadata("design:type", Number)
|
|
561
|
-
], Coupon.prototype, "exclusivityType", void 0);
|
|
562
990
|
|
|
563
991
|
class SubscriptionPlan extends BaseModel {
|
|
564
992
|
static get identifiersFields() {
|
|
@@ -598,6 +1026,18 @@ __decorate([
|
|
|
598
1026
|
__metadata("design:type", BeautyProfile)
|
|
599
1027
|
], User.prototype, "beautyProfile", void 0);
|
|
600
1028
|
|
|
1029
|
+
class Address extends BaseModel {
|
|
1030
|
+
static get identifiersFields() {
|
|
1031
|
+
return ['id'];
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
class UserAddress extends Address {
|
|
1036
|
+
static get identifiersFields() {
|
|
1037
|
+
return ['id', 'userId'];
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
|
|
601
1041
|
class Subscription extends BaseModel {
|
|
602
1042
|
static get identifiersFields() {
|
|
603
1043
|
return ['id'];
|
|
@@ -612,12 +1052,12 @@ __decorate([
|
|
|
612
1052
|
__metadata("design:type", SubscriptionPlan)
|
|
613
1053
|
], Subscription.prototype, "subscriptionPlan", void 0);
|
|
614
1054
|
__decorate([
|
|
615
|
-
Type(() =>
|
|
616
|
-
__metadata("design:type",
|
|
1055
|
+
Type(() => UserAddress),
|
|
1056
|
+
__metadata("design:type", UserAddress)
|
|
617
1057
|
], Subscription.prototype, "shippingAddress", void 0);
|
|
618
1058
|
__decorate([
|
|
619
|
-
Type(() =>
|
|
620
|
-
__metadata("design:type",
|
|
1059
|
+
Type(() => UserAddress),
|
|
1060
|
+
__metadata("design:type", UserAddress)
|
|
621
1061
|
], Subscription.prototype, "billingAddress", void 0);
|
|
622
1062
|
__decorate([
|
|
623
1063
|
Type(() => Coupon),
|
|
@@ -632,12 +1072,6 @@ __decorate([
|
|
|
632
1072
|
__metadata("design:type", Array)
|
|
633
1073
|
], Subscription.prototype, "payment", void 0);
|
|
634
1074
|
|
|
635
|
-
class UserAddress extends Address {
|
|
636
|
-
static get identifiersFields() {
|
|
637
|
-
return ['id', 'userId'];
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
641
1075
|
class UserPaymentMethod extends BaseModel {
|
|
642
1076
|
static get identifiersFields() {
|
|
643
1077
|
return ['id', 'userId'];
|
|
@@ -669,7 +1103,7 @@ class Authentication {
|
|
|
669
1103
|
async signIn({ email, password }, signInMethod) {
|
|
670
1104
|
const method = this.getServiceByMethod(signInMethod);
|
|
671
1105
|
const userAuth = await this.authService[method]({ email, password });
|
|
672
|
-
const user = this.userRepository.get(userAuth);
|
|
1106
|
+
const user = this.userRepository.get({ id: userAuth.id });
|
|
673
1107
|
if (!isNil(user))
|
|
674
1108
|
return user;
|
|
675
1109
|
if (/^.+@b4a.com.br$/.test(userAuth.email))
|
|
@@ -762,14 +1196,123 @@ class RecoveryPassword {
|
|
|
762
1196
|
}
|
|
763
1197
|
}
|
|
764
1198
|
|
|
765
|
-
class
|
|
766
|
-
|
|
1199
|
+
class Filter extends BaseModel {
|
|
1200
|
+
static get identifiersFields() {
|
|
1201
|
+
return ['id'];
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
class CategoryBase extends BaseModel {
|
|
1206
|
+
static get identifiersFields() {
|
|
1207
|
+
return ['id'];
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
__decorate([
|
|
1211
|
+
Type(() => CategoryBase),
|
|
1212
|
+
__metadata("design:type", CategoryBase)
|
|
1213
|
+
], CategoryBase.prototype, "parent", void 0);
|
|
1214
|
+
__decorate([
|
|
1215
|
+
Type(() => Filter),
|
|
1216
|
+
__metadata("design:type", Array)
|
|
1217
|
+
], CategoryBase.prototype, "filters", void 0);
|
|
1218
|
+
|
|
1219
|
+
class CategoryForProduct extends CategoryBase {
|
|
1220
|
+
static get identifiersFields() {
|
|
1221
|
+
return ['id'];
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
class ProductBase extends BaseModel {
|
|
1226
|
+
get evaluation() {
|
|
1227
|
+
return {
|
|
1228
|
+
reviews: this.reviews,
|
|
1229
|
+
count: this.reviewsTotal,
|
|
1230
|
+
rating: this.rate,
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
set evaluation(evaluation) {
|
|
1234
|
+
if (!evaluation) {
|
|
1235
|
+
this.reviews = null;
|
|
1236
|
+
this.reviewsTotal = null;
|
|
1237
|
+
this.rate = null;
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
this.reviews = evaluation.reviews || this.reviews;
|
|
1241
|
+
this.reviewsTotal = evaluation.count || this.reviewsTotal;
|
|
1242
|
+
this.rate = evaluation.rating || this.rate;
|
|
1243
|
+
}
|
|
1244
|
+
static get identifiersFields() {
|
|
1245
|
+
return ['id'];
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
class ProductForKit extends ProductBase {
|
|
1250
|
+
static get identifiersFields() {
|
|
1251
|
+
return ['id'];
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
__decorate([
|
|
1255
|
+
Type(() => CategoryForProduct),
|
|
1256
|
+
__metadata("design:type", CategoryForProduct)
|
|
1257
|
+
], ProductForKit.prototype, "category", void 0);
|
|
1258
|
+
|
|
1259
|
+
class KitProduct extends BaseModel {
|
|
1260
|
+
static get identifiersFields() {
|
|
1261
|
+
return ['productId', 'kitProductId'];
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
__decorate([
|
|
1265
|
+
Type(() => ProductForKit),
|
|
1266
|
+
__metadata("design:type", ProductForKit)
|
|
1267
|
+
], KitProduct.prototype, "kit", void 0);
|
|
1268
|
+
__decorate([
|
|
1269
|
+
Type(() => ProductForKit),
|
|
1270
|
+
__metadata("design:type", ProductForKit)
|
|
1271
|
+
], KitProduct.prototype, "product", void 0);
|
|
1272
|
+
|
|
1273
|
+
class ProductForCategory extends ProductBase {
|
|
1274
|
+
static get identifiersFields() {
|
|
767
1275
|
return ['id'];
|
|
768
1276
|
}
|
|
1277
|
+
}
|
|
1278
|
+
__decorate([
|
|
1279
|
+
Type(() => KitProduct),
|
|
1280
|
+
__metadata("design:type", Array)
|
|
1281
|
+
], ProductForCategory.prototype, "kitProducts", void 0);
|
|
1282
|
+
|
|
1283
|
+
class Category extends CategoryBase {
|
|
769
1284
|
static get identifiersFields() {
|
|
770
1285
|
return ['id'];
|
|
771
1286
|
}
|
|
772
1287
|
}
|
|
1288
|
+
__decorate([
|
|
1289
|
+
Type(() => ProductForCategory),
|
|
1290
|
+
__metadata("design:type", Array)
|
|
1291
|
+
], Category.prototype, "childrenProducts", void 0);
|
|
1292
|
+
|
|
1293
|
+
class CategoryCollectionChildren extends BaseModel {
|
|
1294
|
+
static get identifiersFields() {
|
|
1295
|
+
return ['collectionId', 'categoryId'];
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
__decorate([
|
|
1299
|
+
Type(() => CategoryCollectionChildren),
|
|
1300
|
+
__metadata("design:type", CategoryCollectionChildren)
|
|
1301
|
+
], CategoryCollectionChildren.prototype, "parent", void 0);
|
|
1302
|
+
|
|
1303
|
+
class CategoryFilter extends BaseModel {
|
|
1304
|
+
static get identifiersFields() {
|
|
1305
|
+
return ['id'];
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
__decorate([
|
|
1309
|
+
Type(() => Filter),
|
|
1310
|
+
__metadata("design:type", Filter)
|
|
1311
|
+
], CategoryFilter.prototype, "filter", void 0);
|
|
1312
|
+
__decorate([
|
|
1313
|
+
Type(() => Category),
|
|
1314
|
+
__metadata("design:type", Category)
|
|
1315
|
+
], CategoryFilter.prototype, "category", void 0);
|
|
773
1316
|
|
|
774
1317
|
var GenderDestination;
|
|
775
1318
|
(function (GenderDestination) {
|
|
@@ -786,53 +1329,59 @@ var Shops;
|
|
|
786
1329
|
Shops["ALL"] = "ALL";
|
|
787
1330
|
})(Shops || (Shops = {}));
|
|
788
1331
|
|
|
789
|
-
class
|
|
790
|
-
|
|
1332
|
+
class FilterOption extends BaseModel {
|
|
1333
|
+
static get identifiersFields() {
|
|
791
1334
|
return ['id'];
|
|
792
1335
|
}
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
class Product extends ProductBase {
|
|
793
1339
|
static get identifiersFields() {
|
|
794
1340
|
return ['id'];
|
|
795
1341
|
}
|
|
796
1342
|
}
|
|
1343
|
+
__decorate([
|
|
1344
|
+
Type(() => CategoryForProduct),
|
|
1345
|
+
__metadata("design:type", CategoryForProduct)
|
|
1346
|
+
], Product.prototype, "category", void 0);
|
|
797
1347
|
__decorate([
|
|
798
1348
|
Type(() => KitProduct),
|
|
799
1349
|
__metadata("design:type", Array)
|
|
800
1350
|
], Product.prototype, "kitProducts", void 0);
|
|
801
1351
|
|
|
802
|
-
class
|
|
1352
|
+
class Variant extends BaseModel {
|
|
803
1353
|
static get identifiersFields() {
|
|
804
|
-
return ['
|
|
1354
|
+
return ['id', 'productId'];
|
|
805
1355
|
}
|
|
806
1356
|
}
|
|
807
|
-
__decorate([
|
|
808
|
-
Type(() => Product),
|
|
809
|
-
__metadata("design:type", Product)
|
|
810
|
-
], KitProduct.prototype, "kit", void 0);
|
|
811
|
-
__decorate([
|
|
812
|
-
Type(() => Product),
|
|
813
|
-
__metadata("design:type", Product)
|
|
814
|
-
], KitProduct.prototype, "product", void 0);
|
|
815
1357
|
|
|
816
|
-
class
|
|
817
|
-
|
|
1358
|
+
class Wishlist extends Category {
|
|
1359
|
+
static get identifiersFields() {
|
|
818
1360
|
return ['id'];
|
|
819
1361
|
}
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
class Buy2Win extends BaseModel {
|
|
820
1365
|
static get identifiersFields() {
|
|
821
|
-
return ['id'
|
|
1366
|
+
return ['id'];
|
|
822
1367
|
}
|
|
823
1368
|
}
|
|
1369
|
+
__decorate([
|
|
1370
|
+
Type(() => Category),
|
|
1371
|
+
__metadata("design:type", Array)
|
|
1372
|
+
], Buy2Win.prototype, "categories", void 0);
|
|
824
1373
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
}
|
|
1374
|
+
class CampaignDashboard extends BaseModel {
|
|
1375
|
+
static get identifiersFields() {
|
|
1376
|
+
return ['id'];
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
class CampaignHashtag extends BaseModel {
|
|
1381
|
+
static get identifiersFields() {
|
|
1382
|
+
return ['id'];
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
836
1385
|
|
|
837
1386
|
class LineItem extends Product {
|
|
838
1387
|
}
|
|
@@ -857,12 +1406,12 @@ __decorate([
|
|
|
857
1406
|
__metadata("design:type", User)
|
|
858
1407
|
], Checkout.prototype, "user", void 0);
|
|
859
1408
|
__decorate([
|
|
860
|
-
Type(() =>
|
|
861
|
-
__metadata("design:type",
|
|
1409
|
+
Type(() => UserAddress),
|
|
1410
|
+
__metadata("design:type", UserAddress)
|
|
862
1411
|
], Checkout.prototype, "shippingAddress", void 0);
|
|
863
1412
|
__decorate([
|
|
864
|
-
Type(() =>
|
|
865
|
-
__metadata("design:type",
|
|
1413
|
+
Type(() => UserAddress),
|
|
1414
|
+
__metadata("design:type", UserAddress)
|
|
866
1415
|
], Checkout.prototype, "billingAddress", void 0);
|
|
867
1416
|
__decorate([
|
|
868
1417
|
Type(() => ShippingMethod),
|
|
@@ -873,6 +1422,18 @@ __decorate([
|
|
|
873
1422
|
__metadata("design:type", Coupon)
|
|
874
1423
|
], Checkout.prototype, "coupon", void 0);
|
|
875
1424
|
|
|
1425
|
+
var OrderStatus;
|
|
1426
|
+
(function (OrderStatus) {
|
|
1427
|
+
OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
|
|
1428
|
+
OrderStatus["EM_PREPARO"] = "Preparando pedido";
|
|
1429
|
+
OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
|
|
1430
|
+
OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
|
|
1431
|
+
OrderStatus["ENVIADO"] = "Enviado";
|
|
1432
|
+
OrderStatus["ENTREGUE"] = "Entregue";
|
|
1433
|
+
OrderStatus["CANCELADO"] = "Cancelado";
|
|
1434
|
+
OrderStatus["CREDIT_CARD"] = "credit_card";
|
|
1435
|
+
})(OrderStatus || (OrderStatus = {}));
|
|
1436
|
+
|
|
876
1437
|
class Order extends Checkout {
|
|
877
1438
|
}
|
|
878
1439
|
__decorate([
|
|
@@ -886,12 +1447,12 @@ class CheckoutSubscription extends BaseModel {
|
|
|
886
1447
|
}
|
|
887
1448
|
}
|
|
888
1449
|
__decorate([
|
|
889
|
-
Type(() =>
|
|
890
|
-
__metadata("design:type",
|
|
1450
|
+
Type(() => UserAddress),
|
|
1451
|
+
__metadata("design:type", UserAddress)
|
|
891
1452
|
], CheckoutSubscription.prototype, "shippingAddress", void 0);
|
|
892
1453
|
__decorate([
|
|
893
|
-
Type(() =>
|
|
894
|
-
__metadata("design:type",
|
|
1454
|
+
Type(() => UserAddress),
|
|
1455
|
+
__metadata("design:type", UserAddress)
|
|
895
1456
|
], CheckoutSubscription.prototype, "billingAddress", void 0);
|
|
896
1457
|
__decorate([
|
|
897
1458
|
Type(() => SubscriptionPlan),
|
|
@@ -902,15 +1463,19 @@ __decorate([
|
|
|
902
1463
|
__metadata("design:type", Coupon)
|
|
903
1464
|
], CheckoutSubscription.prototype, "coupon", void 0);
|
|
904
1465
|
|
|
905
|
-
class
|
|
906
|
-
static
|
|
907
|
-
|
|
1466
|
+
class RoundProductPricesHelper {
|
|
1467
|
+
static roundProductPrices(product) {
|
|
1468
|
+
product.price.price = Number(product.price.price.toFixed(2));
|
|
1469
|
+
product.price.fullPrice = Number(product.price.fullPrice.toFixed(2));
|
|
1470
|
+
if (product.price.subscriberPrice) {
|
|
1471
|
+
product.price.subscriberPrice = Number(product.price.subscriberPrice.toFixed(2));
|
|
1472
|
+
}
|
|
1473
|
+
if (product instanceof LineItem && product.pricePaid) {
|
|
1474
|
+
product.pricePaid = Number(product.pricePaid.toFixed(2));
|
|
1475
|
+
}
|
|
1476
|
+
return product;
|
|
908
1477
|
}
|
|
909
1478
|
}
|
|
910
|
-
__decorate([
|
|
911
|
-
Type(() => Category),
|
|
912
|
-
__metadata("design:type", Array)
|
|
913
|
-
], Buy2Win.prototype, "categories", void 0);
|
|
914
1479
|
|
|
915
1480
|
var FilterType;
|
|
916
1481
|
(function (FilterType) {
|
|
@@ -1011,6 +1576,12 @@ class ShopMenu extends BaseModel {
|
|
|
1011
1576
|
}
|
|
1012
1577
|
}
|
|
1013
1578
|
|
|
1579
|
+
class ShopSettings extends BaseModel {
|
|
1580
|
+
static get identifiersFields() {
|
|
1581
|
+
return ['id'];
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1014
1585
|
class InvalidArgumentError extends CustomError {
|
|
1015
1586
|
constructor(message) {
|
|
1016
1587
|
super(message);
|
|
@@ -1041,12 +1612,16 @@ class AxiosAdapter {
|
|
|
1041
1612
|
constructor(config) {
|
|
1042
1613
|
this.config = config;
|
|
1043
1614
|
}
|
|
1044
|
-
async get(index) {
|
|
1615
|
+
async get(index, id) {
|
|
1045
1616
|
try {
|
|
1046
1617
|
const { data } = await axios({
|
|
1047
|
-
url: `${this.config.url}/${index}`,
|
|
1618
|
+
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
1048
1619
|
method: 'GET',
|
|
1049
|
-
|
|
1620
|
+
responseType: 'json',
|
|
1621
|
+
headers: {
|
|
1622
|
+
'Content-Type': 'application/json',
|
|
1623
|
+
Authorization: `ApiKey ${this.config.credential}`,
|
|
1624
|
+
},
|
|
1050
1625
|
});
|
|
1051
1626
|
return data._source;
|
|
1052
1627
|
}
|
|
@@ -1058,9 +1633,14 @@ class AxiosAdapter {
|
|
|
1058
1633
|
}
|
|
1059
1634
|
async query(index, query) {
|
|
1060
1635
|
const { data } = await axios({
|
|
1061
|
-
url: `${this.config.url}/${index}`,
|
|
1636
|
+
url: `${this.config.url}/${index}/_search`,
|
|
1062
1637
|
method: 'POST',
|
|
1063
|
-
|
|
1638
|
+
responseType: 'json',
|
|
1639
|
+
headers: {
|
|
1640
|
+
Accept: 'application/vnd.elasticsearch+json;compatible-with=7',
|
|
1641
|
+
'Content-Type': 'application/vnd.elasticsearch+json;compatible-with=7',
|
|
1642
|
+
Authorization: `ApiKey ${this.config.credential}`,
|
|
1643
|
+
},
|
|
1064
1644
|
data: query,
|
|
1065
1645
|
});
|
|
1066
1646
|
return {
|
|
@@ -1070,17 +1650,25 @@ class AxiosAdapter {
|
|
|
1070
1650
|
}
|
|
1071
1651
|
async save(index, data) {
|
|
1072
1652
|
await axios({
|
|
1073
|
-
url: `${this.config.url}/${index}`,
|
|
1653
|
+
url: `${this.config.url}/${index}/_doc`,
|
|
1654
|
+
method: 'POST',
|
|
1655
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1656
|
+
data,
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
async update(index, id, data) {
|
|
1660
|
+
await axios({
|
|
1661
|
+
url: `${this.config.url}/${index}/_update/${id}`,
|
|
1074
1662
|
method: 'PUT',
|
|
1075
|
-
headers: { Authorization: `
|
|
1663
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1076
1664
|
data,
|
|
1077
1665
|
});
|
|
1078
1666
|
}
|
|
1079
|
-
async delete(index) {
|
|
1667
|
+
async delete(index, id) {
|
|
1080
1668
|
await axios({
|
|
1081
|
-
url: `${this.config.url}/${index}`,
|
|
1669
|
+
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
1082
1670
|
method: 'DELETE',
|
|
1083
|
-
headers: { Authorization: `
|
|
1671
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1084
1672
|
});
|
|
1085
1673
|
}
|
|
1086
1674
|
}
|
|
@@ -1088,13 +1676,16 @@ class AxiosAdapter {
|
|
|
1088
1676
|
class ProductsIndex {
|
|
1089
1677
|
constructor(adapter) {
|
|
1090
1678
|
this.adapter = adapter;
|
|
1679
|
+
this.index = `products`;
|
|
1091
1680
|
}
|
|
1092
|
-
async
|
|
1093
|
-
const data = await this.adapter.get(
|
|
1681
|
+
async getById(id) {
|
|
1682
|
+
const data = await this.adapter.get(this.index, id);
|
|
1094
1683
|
return Product.toInstance(data);
|
|
1095
1684
|
}
|
|
1096
|
-
async
|
|
1685
|
+
async search(searchTerm, total, shop) {
|
|
1686
|
+
const size = total || 9;
|
|
1097
1687
|
const fields = [
|
|
1688
|
+
'EAN',
|
|
1098
1689
|
'brand',
|
|
1099
1690
|
'id',
|
|
1100
1691
|
'images',
|
|
@@ -1105,73 +1696,82 @@ class ProductsIndex {
|
|
|
1105
1696
|
'stock',
|
|
1106
1697
|
'slug',
|
|
1107
1698
|
'reviews',
|
|
1108
|
-
'pricePaid',
|
|
1109
|
-
'isGift',
|
|
1110
|
-
'stock',
|
|
1111
|
-
'weight',
|
|
1112
|
-
'tags',
|
|
1113
1699
|
'hasVariants',
|
|
1114
|
-
'
|
|
1700
|
+
'rate',
|
|
1115
1701
|
];
|
|
1116
|
-
const {
|
|
1702
|
+
const filter = [{ term: { published: true } }];
|
|
1703
|
+
if (size > 9) {
|
|
1704
|
+
fields.push(...['pricePaid', 'isGift', 'stock', 'weight', 'tags']);
|
|
1705
|
+
}
|
|
1706
|
+
else {
|
|
1707
|
+
filter.push({ term: { tags: shop == Shops.GLAMSHOP ? 'feminino' : 'masculino' } });
|
|
1708
|
+
}
|
|
1709
|
+
const search = await this.adapter.query(this.index, {
|
|
1710
|
+
size,
|
|
1117
1711
|
_source: fields,
|
|
1118
1712
|
query: {
|
|
1119
1713
|
bool: {
|
|
1120
|
-
|
|
1121
|
-
{
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1714
|
+
must: {
|
|
1715
|
+
multi_match: {
|
|
1716
|
+
query: `${searchTerm}`,
|
|
1717
|
+
type: 'bool_prefix',
|
|
1718
|
+
fields: [
|
|
1719
|
+
'name',
|
|
1720
|
+
'name.folded',
|
|
1721
|
+
'name.search',
|
|
1722
|
+
'description',
|
|
1723
|
+
'description.search',
|
|
1724
|
+
'description.folded',
|
|
1725
|
+
'brand',
|
|
1726
|
+
'brand.search',
|
|
1727
|
+
'brand.folded',
|
|
1728
|
+
],
|
|
1729
|
+
fuzziness: 2,
|
|
1125
1730
|
},
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1731
|
+
},
|
|
1732
|
+
should: {
|
|
1733
|
+
match_phrase_prefix: {
|
|
1734
|
+
'name.search': {
|
|
1735
|
+
query: `${searchTerm}`,
|
|
1736
|
+
slop: 10,
|
|
1129
1737
|
},
|
|
1130
1738
|
},
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
{
|
|
1134
|
-
range: {
|
|
1135
|
-
'stock.quantity': {
|
|
1136
|
-
gt: 0,
|
|
1137
|
-
},
|
|
1138
|
-
},
|
|
1139
|
-
},
|
|
1140
|
-
]
|
|
1141
|
-
: []),
|
|
1142
|
-
],
|
|
1739
|
+
},
|
|
1740
|
+
filter,
|
|
1143
1741
|
},
|
|
1144
1742
|
},
|
|
1145
|
-
...(options?.size ? { size: options?.size } : {}),
|
|
1146
1743
|
});
|
|
1147
|
-
|
|
1744
|
+
search.hits = search.hits
|
|
1745
|
+
.filter((e) => e._source.name !== '')
|
|
1746
|
+
.map((hit) => {
|
|
1747
|
+
RoundProductPricesHelper.roundProductPrices(hit._source);
|
|
1748
|
+
return hit;
|
|
1749
|
+
});
|
|
1750
|
+
return search;
|
|
1148
1751
|
}
|
|
1149
1752
|
async save(product) {
|
|
1150
|
-
delete product.createdAt;
|
|
1151
|
-
delete product.updatedAt;
|
|
1152
|
-
delete product.kitProducts;
|
|
1153
1753
|
try {
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
await this.get(product.firestoreId);
|
|
1157
|
-
await this.adapter.save(`products/_doc/${product.firestoreId}`, product.toPlain());
|
|
1754
|
+
const { createdAt, updatedAt, kitProducts, ...data } = product;
|
|
1755
|
+
this.adapter.save(this.index, data);
|
|
1158
1756
|
}
|
|
1159
1757
|
catch (error) {
|
|
1160
|
-
|
|
1161
|
-
throw error;
|
|
1162
|
-
console.error(error.message);
|
|
1163
|
-
await this.adapter.save(`products/_doc/${product.id}`, product.toPlain());
|
|
1758
|
+
console.error(error);
|
|
1164
1759
|
}
|
|
1165
1760
|
}
|
|
1166
|
-
async
|
|
1167
|
-
|
|
1168
|
-
|
|
1761
|
+
async update(product) {
|
|
1762
|
+
try {
|
|
1763
|
+
await this.adapter.update(this.index, product.id, product);
|
|
1764
|
+
}
|
|
1765
|
+
catch (error) {
|
|
1766
|
+
console.error(error);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
async delete(id) {
|
|
1169
1770
|
try {
|
|
1170
|
-
await this.
|
|
1171
|
-
await this.adapter.delete(`products/_doc/${product.firestoreId}`);
|
|
1771
|
+
await this.adapter.delete(this.index, id);
|
|
1172
1772
|
}
|
|
1173
1773
|
catch (error) {
|
|
1174
|
-
|
|
1774
|
+
console.error(error);
|
|
1175
1775
|
}
|
|
1176
1776
|
}
|
|
1177
1777
|
}
|
|
@@ -1201,17 +1801,39 @@ const withFirestore = (MixinBase) => {
|
|
|
1201
1801
|
: bindDate(data[key], key),
|
|
1202
1802
|
}), {});
|
|
1203
1803
|
};
|
|
1804
|
+
const omitByRecursivelyInPlace = (value, iteratee) => {
|
|
1805
|
+
each(value, (v, k) => {
|
|
1806
|
+
if (iteratee(v, k)) {
|
|
1807
|
+
unset(value, k);
|
|
1808
|
+
}
|
|
1809
|
+
else if (isObject(v)) {
|
|
1810
|
+
omitByRecursivelyInPlace(v, iteratee);
|
|
1811
|
+
}
|
|
1812
|
+
});
|
|
1813
|
+
return value;
|
|
1814
|
+
};
|
|
1204
1815
|
return class extends MixinBase {
|
|
1205
|
-
constructor() {
|
|
1206
|
-
super(...
|
|
1816
|
+
constructor(...params) {
|
|
1817
|
+
super(...params);
|
|
1818
|
+
this.fields = {};
|
|
1819
|
+
this.interceptors = {};
|
|
1207
1820
|
this.collectionName = '';
|
|
1821
|
+
const options = params[0];
|
|
1822
|
+
this.firestore = options.firestore;
|
|
1823
|
+
this.collectionName = options.collectionName;
|
|
1824
|
+
this.model = options.model;
|
|
1825
|
+
this.fields = options.fields;
|
|
1826
|
+
this.interceptors = options.interceptors;
|
|
1208
1827
|
}
|
|
1209
1828
|
collection(path) {
|
|
1210
1829
|
return collection(this.firestore, path || this.collectionName).withConverter(this.buildModelInstance());
|
|
1211
1830
|
}
|
|
1212
1831
|
buildModelInstance() {
|
|
1213
1832
|
return {
|
|
1214
|
-
toFirestore: (data) =>
|
|
1833
|
+
toFirestore: (data) => {
|
|
1834
|
+
const plain = data?.toPlain ? data.toPlain() : data;
|
|
1835
|
+
return omitByRecursivelyInPlace(plain, (value) => value === undefined);
|
|
1836
|
+
},
|
|
1215
1837
|
fromFirestore: (snap) => {
|
|
1216
1838
|
const data = snap.data();
|
|
1217
1839
|
let bindedData = null;
|
|
@@ -1251,11 +1873,14 @@ const withHelpers = (MixinBase) => {
|
|
|
1251
1873
|
const withGetFirestore = (MixinBase) => {
|
|
1252
1874
|
return class GetFirestore extends MixinBase {
|
|
1253
1875
|
async get(identifiers) {
|
|
1254
|
-
const
|
|
1876
|
+
const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
|
|
1877
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
1878
|
+
const builded = intercepted?.instance || instance;
|
|
1879
|
+
const docRef = await getDoc(doc(await this.collection(this.buildCollectionPathForGet(identifiers)), Object.values(builded.identifier).shift().toString()));
|
|
1255
1880
|
const data = docRef.data();
|
|
1256
1881
|
if (isNil(data))
|
|
1257
1882
|
throw new NotFoundError(`Document ${JSON.stringify(identifiers)} not found`);
|
|
1258
|
-
return data;
|
|
1883
|
+
return this.interceptors?.response?.(data, intercepted) || data;
|
|
1259
1884
|
}
|
|
1260
1885
|
buildCollectionPathForGet(identifiers) {
|
|
1261
1886
|
return this.isSubCollection(this)
|
|
@@ -1292,7 +1917,7 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1292
1917
|
], []);
|
|
1293
1918
|
this.buildWhereSentence = (fieldName, options) => {
|
|
1294
1919
|
if (this.isSubCollection(this) && fieldName === this.parentIdField)
|
|
1295
|
-
[];
|
|
1920
|
+
return [];
|
|
1296
1921
|
const value = options?.value || options;
|
|
1297
1922
|
const object = {};
|
|
1298
1923
|
set(object, fieldName, value);
|
|
@@ -1336,8 +1961,11 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1336
1961
|
return Object.keys(fieldsToOrderBy).map((fieldName) => orderBy(fieldName, fieldsToOrderBy[fieldName]));
|
|
1337
1962
|
};
|
|
1338
1963
|
}
|
|
1339
|
-
async find(
|
|
1340
|
-
const collection = this.collection(this.buildCollectionPathForFind(filters));
|
|
1964
|
+
async find(find = {}) {
|
|
1965
|
+
const collection = this.collection(this.buildCollectionPathForFind(find.filters));
|
|
1966
|
+
const enableCount = find?.options?.enableCount ?? true;
|
|
1967
|
+
const intercepted = await this.interceptors?.request?.({ find });
|
|
1968
|
+
const { filters, limits, orderBy } = intercepted.find || find;
|
|
1341
1969
|
const queries = this.makeFirestoreWhere(filters || {});
|
|
1342
1970
|
const ordination = this.makeFirestoreOrderBy(filters, orderBy);
|
|
1343
1971
|
const offsets = await this.defineLimits(filters, limits);
|
|
@@ -1345,8 +1973,8 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1345
1973
|
const docs = await getDocs(query(collection, ...queryArgumments));
|
|
1346
1974
|
const data = docs.docs.map((doc) => doc.data());
|
|
1347
1975
|
return {
|
|
1348
|
-
data,
|
|
1349
|
-
count: this.calculateCount(data, limits),
|
|
1976
|
+
data: (await this.interceptors?.response?.(data, intercepted)) || data,
|
|
1977
|
+
count: enableCount ? this.calculateCount(data, limits) : Infinity,
|
|
1350
1978
|
};
|
|
1351
1979
|
}
|
|
1352
1980
|
buildCollectionPathForFind(filters) {
|
|
@@ -1360,7 +1988,7 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1360
1988
|
const queries = [];
|
|
1361
1989
|
if (limits?.offset) {
|
|
1362
1990
|
if (this.model.isModel(limits.offset))
|
|
1363
|
-
queries.push(startAfter(await getDoc(doc(this.collection(this.buildCollectionPathForFind(filters)), limits.offset.identifier.shift()))));
|
|
1991
|
+
queries.push(startAfter(await getDoc(doc(this.collection(this.buildCollectionPathForFind(filters)), Object.values(limits.offset.identifier).shift()?.toString()))));
|
|
1364
1992
|
else if (isNumber(limits.offset) || isString(limits.offset))
|
|
1365
1993
|
queries.push(startAt(limits.offset));
|
|
1366
1994
|
}
|
|
@@ -1381,12 +2009,16 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1381
2009
|
const withCreateFirestore = (MixinBase) => {
|
|
1382
2010
|
return class CreateFirestore extends MixinBase {
|
|
1383
2011
|
async create(data) {
|
|
1384
|
-
const
|
|
2012
|
+
const instance = this.model.toInstance(data);
|
|
2013
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
2014
|
+
const builded = intercepted?.instance || instance;
|
|
2015
|
+
const docRef = await this.save(builded);
|
|
1385
2016
|
const doc = await getDoc(docRef);
|
|
1386
|
-
|
|
2017
|
+
const docBuilded = (await this.interceptors?.response?.(doc.data(), intercepted)) || doc.data();
|
|
2018
|
+
return docBuilded;
|
|
1387
2019
|
}
|
|
1388
2020
|
async save(data) {
|
|
1389
|
-
const id = data.identifier
|
|
2021
|
+
const id = Object.values(data.identifier)?.shift()?.toString();
|
|
1390
2022
|
const collectionPath = this.buildCollectionPathForAdd(data);
|
|
1391
2023
|
const collection = this.collection(collectionPath);
|
|
1392
2024
|
if (isEmpty(id))
|
|
@@ -1427,9 +2059,12 @@ const withUpdateFirestore = (MixinBase) => {
|
|
|
1427
2059
|
const model = new this.model();
|
|
1428
2060
|
const keyField = model.identifiersFields.shift();
|
|
1429
2061
|
const docRef = doc(this.collection(this.buildCollectionPathForUpdate(data)), getValueFromParams(data, keyField).toString());
|
|
1430
|
-
|
|
1431
|
-
const
|
|
1432
|
-
|
|
2062
|
+
const plainFromData = this.model.toInstance(this.paramsToPlain(data));
|
|
2063
|
+
const intercepted = await this.interceptors?.request?.({ instance: plainFromData });
|
|
2064
|
+
const builded = intercepted?.instance || plainFromData;
|
|
2065
|
+
await setDoc(docRef, builded.toPlain(), { merge: true });
|
|
2066
|
+
const docData = await getDoc(docRef).then((doc) => doc.data());
|
|
2067
|
+
return this.interceptors?.response?.(docData, intercepted) || docData;
|
|
1433
2068
|
}
|
|
1434
2069
|
buildCollectionPathForUpdate(identifiers) {
|
|
1435
2070
|
return this.isSubCollection(this)
|
|
@@ -1451,7 +2086,11 @@ const withUpdateFirestore = (MixinBase) => {
|
|
|
1451
2086
|
const withDeleteFirestore = (MixinBase) => {
|
|
1452
2087
|
return class DeleteFirestore extends MixinBase {
|
|
1453
2088
|
async delete(identifiers) {
|
|
1454
|
-
|
|
2089
|
+
const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
|
|
2090
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
2091
|
+
const builded = intercepted?.instance || instance;
|
|
2092
|
+
await deleteDoc(doc(this.collection(this.buildCollectionPathForRemove(identifiers)), Object.values(builded.identifier).shift().toString()));
|
|
2093
|
+
await this.interceptors?.response?.(instance, intercepted);
|
|
1455
2094
|
}
|
|
1456
2095
|
buildCollectionPathForRemove(identifiers) {
|
|
1457
2096
|
return this.isSubCollection(this)
|
|
@@ -1463,8 +2102,10 @@ const withDeleteFirestore = (MixinBase) => {
|
|
|
1463
2102
|
|
|
1464
2103
|
const withSubCollection = (MixinBase, ParentModel) => {
|
|
1465
2104
|
return class SubCollectionMix extends MixinBase {
|
|
1466
|
-
constructor(...
|
|
1467
|
-
|
|
2105
|
+
constructor(...params) {
|
|
2106
|
+
const options = params[0];
|
|
2107
|
+
super(...params);
|
|
2108
|
+
this.parentIdField = options.parentIdField;
|
|
1468
2109
|
}
|
|
1469
2110
|
collection(path) {
|
|
1470
2111
|
return super.collection(path);
|
|
@@ -1478,73 +2119,87 @@ const withCrudFirestore = (MixinBase) => {
|
|
|
1478
2119
|
};
|
|
1479
2120
|
|
|
1480
2121
|
class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1481
|
-
constructor(firestore) {
|
|
1482
|
-
super(
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
2122
|
+
constructor({ firestore, interceptors }) {
|
|
2123
|
+
super({
|
|
2124
|
+
firestore,
|
|
2125
|
+
collectionName: 'leads',
|
|
2126
|
+
model: Lead,
|
|
2127
|
+
interceptors,
|
|
2128
|
+
});
|
|
1486
2129
|
}
|
|
1487
2130
|
}
|
|
1488
2131
|
|
|
1489
2132
|
class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription) {
|
|
1490
|
-
constructor(firestore, parentRepository) {
|
|
1491
|
-
super(
|
|
1492
|
-
|
|
2133
|
+
constructor({ firestore, interceptors }, parentRepository) {
|
|
2134
|
+
super({
|
|
2135
|
+
firestore,
|
|
2136
|
+
collectionName: 'editions',
|
|
2137
|
+
parentIdField: 'subscriptionId',
|
|
2138
|
+
model: Edition,
|
|
2139
|
+
interceptors,
|
|
2140
|
+
});
|
|
1493
2141
|
this.parentRepository = parentRepository;
|
|
1494
|
-
this.collectionName = 'editions';
|
|
1495
|
-
this.parentIdField = 'subscriptionId';
|
|
1496
|
-
this.model = Edition;
|
|
1497
2142
|
}
|
|
1498
2143
|
}
|
|
1499
2144
|
|
|
1500
2145
|
class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1501
|
-
constructor(firestore) {
|
|
1502
|
-
super(
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
2146
|
+
constructor({ firestore, interceptors, }) {
|
|
2147
|
+
super({
|
|
2148
|
+
firestore,
|
|
2149
|
+
collectionName: 'subscription',
|
|
2150
|
+
model: Subscription,
|
|
2151
|
+
interceptors,
|
|
2152
|
+
});
|
|
1506
2153
|
}
|
|
1507
2154
|
}
|
|
1508
2155
|
|
|
1509
2156
|
class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription) {
|
|
1510
|
-
constructor(firestore, parentRepository) {
|
|
1511
|
-
super(
|
|
1512
|
-
|
|
2157
|
+
constructor({ firestore, interceptors }, parentRepository) {
|
|
2158
|
+
super({
|
|
2159
|
+
firestore,
|
|
2160
|
+
collectionName: 'payments',
|
|
2161
|
+
parentIdField: 'subscriptionId',
|
|
2162
|
+
model: SubscriptionPayment,
|
|
2163
|
+
interceptors,
|
|
2164
|
+
});
|
|
1513
2165
|
this.parentRepository = parentRepository;
|
|
1514
|
-
this.collectionName = 'payments';
|
|
1515
|
-
this.parentIdField = 'subscriptionId';
|
|
1516
|
-
this.model = SubscriptionPayment;
|
|
1517
2166
|
}
|
|
1518
2167
|
}
|
|
1519
2168
|
|
|
1520
2169
|
class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
|
|
1521
|
-
constructor(firestore, parentRepository) {
|
|
1522
|
-
super(
|
|
1523
|
-
|
|
2170
|
+
constructor({ firestore, interceptors }, parentRepository) {
|
|
2171
|
+
super({
|
|
2172
|
+
firestore,
|
|
2173
|
+
collectionName: 'address',
|
|
2174
|
+
parentIdField: 'userId',
|
|
2175
|
+
model: UserAddress,
|
|
2176
|
+
interceptors,
|
|
2177
|
+
});
|
|
1524
2178
|
this.parentRepository = parentRepository;
|
|
1525
|
-
this.collectionName = 'address';
|
|
1526
|
-
this.parentIdField = 'userId';
|
|
1527
|
-
this.model = UserAddress;
|
|
1528
2179
|
}
|
|
1529
2180
|
}
|
|
1530
2181
|
|
|
1531
2182
|
class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
|
|
1532
|
-
constructor(firestore, parentRepository) {
|
|
1533
|
-
super(
|
|
1534
|
-
|
|
2183
|
+
constructor({ firestore, interceptors }, parentRepository) {
|
|
2184
|
+
super({
|
|
2185
|
+
firestore,
|
|
2186
|
+
collectionName: 'CX',
|
|
2187
|
+
parentIdField: 'userId',
|
|
2188
|
+
model: BeautyProfile,
|
|
2189
|
+
interceptors,
|
|
2190
|
+
});
|
|
1535
2191
|
this.parentRepository = parentRepository;
|
|
1536
|
-
this.collectionName = 'CX';
|
|
1537
|
-
this.parentIdField = 'userId';
|
|
1538
|
-
this.model = BeautyProfile;
|
|
1539
2192
|
}
|
|
1540
2193
|
}
|
|
1541
2194
|
|
|
1542
2195
|
class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1543
|
-
constructor(firestore) {
|
|
1544
|
-
super(
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
2196
|
+
constructor({ firestore, interceptors }) {
|
|
2197
|
+
super({
|
|
2198
|
+
firestore,
|
|
2199
|
+
collectionName: 'users',
|
|
2200
|
+
model: User,
|
|
2201
|
+
interceptors,
|
|
2202
|
+
});
|
|
1548
2203
|
}
|
|
1549
2204
|
async get(identifiers) {
|
|
1550
2205
|
const user = await super.get({ id: identifiers.id });
|
|
@@ -1584,22 +2239,26 @@ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
1584
2239
|
}
|
|
1585
2240
|
|
|
1586
2241
|
class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
|
|
1587
|
-
constructor(firestore, parentRepository) {
|
|
1588
|
-
super(
|
|
1589
|
-
|
|
2242
|
+
constructor({ firestore, interceptors }, parentRepository) {
|
|
2243
|
+
super({
|
|
2244
|
+
firestore,
|
|
2245
|
+
collectionName: 'payment_method',
|
|
2246
|
+
parentIdField: 'userId',
|
|
2247
|
+
model: UserPaymentMethod,
|
|
2248
|
+
interceptors,
|
|
2249
|
+
});
|
|
1590
2250
|
this.parentRepository = parentRepository;
|
|
1591
|
-
this.collectionName = 'payment_method';
|
|
1592
|
-
this.parentIdField = 'userId';
|
|
1593
|
-
this.model = UserPaymentMethod;
|
|
1594
2251
|
}
|
|
1595
2252
|
}
|
|
1596
2253
|
|
|
1597
2254
|
class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1598
|
-
constructor(firestore) {
|
|
1599
|
-
super(
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
2255
|
+
constructor({ firestore, interceptors }) {
|
|
2256
|
+
super({
|
|
2257
|
+
firestore,
|
|
2258
|
+
collectionName: 'categories',
|
|
2259
|
+
model: Category,
|
|
2260
|
+
interceptors,
|
|
2261
|
+
});
|
|
1603
2262
|
}
|
|
1604
2263
|
async getCategoryBySlug(slug, shop) {
|
|
1605
2264
|
const categoryDocs = await getDocs(query(this.collection(this.collectionName), where('slug', '==', slug), where('shop', '==', shop), where('published', '==', true)));
|
|
@@ -1609,14 +2268,14 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
1609
2268
|
throw new NotFoundError(`Document with slug ${slug} not found`);
|
|
1610
2269
|
return categoryDocs.docs[0].data();
|
|
1611
2270
|
}
|
|
1612
|
-
async getCategoriesForHome(categoryIds, limit = 4) {
|
|
2271
|
+
async getCategoriesForHome(categoryIds, limit = 4, gender) {
|
|
1613
2272
|
const categorySnap = await getDocs(query(this.collection(this.collectionName), where('id', 'in', categoryIds.filter(Boolean)), where('published', '==', true)));
|
|
1614
2273
|
if (categorySnap.empty)
|
|
1615
2274
|
throw new NotFoundError('Categories not found');
|
|
1616
2275
|
const categories = categorySnap.docs.map((doc) => doc.data());
|
|
1617
2276
|
const homeSections = await Promise.all(categories.map(async (category) => ({
|
|
1618
2277
|
category,
|
|
1619
|
-
products: await this.mountCategory(category, { limit, hasStock: true }),
|
|
2278
|
+
products: await this.mountCategory(category, { limit, hasStock: true, gender }),
|
|
1620
2279
|
})));
|
|
1621
2280
|
return homeSections;
|
|
1622
2281
|
}
|
|
@@ -1632,6 +2291,8 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
1632
2291
|
wheres.push(where('published', '==', true), where('id', 'in', productIds));
|
|
1633
2292
|
if (options?.hasStock)
|
|
1634
2293
|
wheres.push(where('stock.quantity', '>', 0));
|
|
2294
|
+
if (options?.gender)
|
|
2295
|
+
wheres.push(where('tags', 'array-contains', options?.gender));
|
|
1635
2296
|
if (options?.limit)
|
|
1636
2297
|
wheres.push(limit(options?.limit));
|
|
1637
2298
|
const productSnap = await getDocs(query(this.collection('productsErpVitrine'), ...wheres));
|
|
@@ -1641,15 +2302,26 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
1641
2302
|
}
|
|
1642
2303
|
return is(products);
|
|
1643
2304
|
}
|
|
2305
|
+
getCategoryByShop(shop) {
|
|
2306
|
+
return;
|
|
2307
|
+
}
|
|
2308
|
+
getChildren(parentId) {
|
|
2309
|
+
return;
|
|
2310
|
+
}
|
|
2311
|
+
isChild(id, parentId) {
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
1644
2314
|
}
|
|
1645
2315
|
|
|
1646
2316
|
class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1647
|
-
constructor(firestore) {
|
|
1648
|
-
super(
|
|
1649
|
-
|
|
2317
|
+
constructor({ firestore, interceptors }) {
|
|
2318
|
+
super({
|
|
2319
|
+
firestore,
|
|
2320
|
+
collectionName: 'productsErpVitrine',
|
|
2321
|
+
model: Product,
|
|
2322
|
+
interceptors,
|
|
2323
|
+
});
|
|
1650
2324
|
this.reviews = {};
|
|
1651
|
-
this.collectionName = 'productsErpVitrine';
|
|
1652
|
-
this.model = Product;
|
|
1653
2325
|
}
|
|
1654
2326
|
async getBySlug(slug) {
|
|
1655
2327
|
const result = await this.find({
|
|
@@ -1684,43 +2356,101 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
1684
2356
|
});
|
|
1685
2357
|
return this.reviews[status];
|
|
1686
2358
|
}
|
|
2359
|
+
cleanShoppingCountFromIds() {
|
|
2360
|
+
return;
|
|
2361
|
+
}
|
|
2362
|
+
findCatalog(params) {
|
|
2363
|
+
return this.find(params);
|
|
2364
|
+
}
|
|
1687
2365
|
}
|
|
1688
2366
|
|
|
1689
2367
|
class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Product) {
|
|
1690
|
-
constructor(firestore, parentRepository) {
|
|
1691
|
-
super(
|
|
1692
|
-
|
|
2368
|
+
constructor({ firestore, interceptors }, parentRepository) {
|
|
2369
|
+
super({
|
|
2370
|
+
firestore,
|
|
2371
|
+
collectionName: 'variants',
|
|
2372
|
+
parentIdField: 'productId',
|
|
2373
|
+
model: Variant,
|
|
2374
|
+
interceptors,
|
|
2375
|
+
});
|
|
1693
2376
|
this.parentRepository = parentRepository;
|
|
1694
|
-
this.collectionName = 'variants';
|
|
1695
|
-
this.parentIdField = 'productId';
|
|
1696
|
-
this.model = Variant;
|
|
1697
2377
|
}
|
|
1698
2378
|
}
|
|
1699
2379
|
|
|
1700
2380
|
class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1701
|
-
constructor(firestore) {
|
|
1702
|
-
super(
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
2381
|
+
constructor({ firestore, interceptors }) {
|
|
2382
|
+
super({
|
|
2383
|
+
firestore,
|
|
2384
|
+
collectionName: 'subscriptionProducts',
|
|
2385
|
+
model: Product,
|
|
2386
|
+
interceptors,
|
|
2387
|
+
});
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2392
|
+
constructor({ firestore, interceptors }) {
|
|
2393
|
+
super({
|
|
2394
|
+
firestore,
|
|
2395
|
+
collectionName: 'buy2win',
|
|
2396
|
+
model: Buy2Win,
|
|
2397
|
+
interceptors,
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
class CampaignDashboardFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2403
|
+
constructor({ firestore, interceptors, }) {
|
|
2404
|
+
super({
|
|
2405
|
+
firestore,
|
|
2406
|
+
collectionName: 'dashboardCampaignsAuto',
|
|
2407
|
+
model: CampaignDashboard,
|
|
2408
|
+
interceptors,
|
|
2409
|
+
});
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2413
|
+
class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2414
|
+
constructor({ firestore, interceptors, }) {
|
|
2415
|
+
super({
|
|
2416
|
+
firestore,
|
|
2417
|
+
collectionName: 'hashtagCampaignsAuto',
|
|
2418
|
+
model: CampaignHashtag,
|
|
2419
|
+
interceptors,
|
|
2420
|
+
});
|
|
1706
2421
|
}
|
|
1707
2422
|
}
|
|
1708
2423
|
|
|
1709
2424
|
class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1710
|
-
constructor(firestore) {
|
|
1711
|
-
super(
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
2425
|
+
constructor({ firestore, interceptors }) {
|
|
2426
|
+
super({
|
|
2427
|
+
firestore,
|
|
2428
|
+
collectionName: 'checkouts',
|
|
2429
|
+
model: Checkout,
|
|
2430
|
+
interceptors,
|
|
2431
|
+
});
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
|
|
2435
|
+
class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2436
|
+
constructor({ firestore, interceptors, }) {
|
|
2437
|
+
super({
|
|
2438
|
+
firestore,
|
|
2439
|
+
collectionName: 'checkoutsSubscription',
|
|
2440
|
+
model: CheckoutSubscription,
|
|
2441
|
+
interceptors,
|
|
2442
|
+
});
|
|
1715
2443
|
}
|
|
1716
2444
|
}
|
|
1717
2445
|
|
|
1718
2446
|
class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1719
|
-
constructor(firestore) {
|
|
1720
|
-
super(
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
2447
|
+
constructor({ firestore, interceptors }) {
|
|
2448
|
+
super({
|
|
2449
|
+
firestore,
|
|
2450
|
+
collectionName: 'coupons',
|
|
2451
|
+
model: Coupon,
|
|
2452
|
+
interceptors,
|
|
2453
|
+
});
|
|
1724
2454
|
}
|
|
1725
2455
|
buildModelInstance() {
|
|
1726
2456
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
@@ -1742,9 +2472,16 @@ class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirest
|
|
|
1742
2472
|
}
|
|
1743
2473
|
|
|
1744
2474
|
class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1745
|
-
constructor(firestore) {
|
|
1746
|
-
super(
|
|
1747
|
-
|
|
2475
|
+
constructor({ firestore, interceptors }) {
|
|
2476
|
+
super({
|
|
2477
|
+
firestore,
|
|
2478
|
+
collectionName: 'orders',
|
|
2479
|
+
model: Order,
|
|
2480
|
+
interceptors,
|
|
2481
|
+
fields: {
|
|
2482
|
+
status: FirestoreFieldType.String,
|
|
2483
|
+
},
|
|
2484
|
+
});
|
|
1748
2485
|
this.orderFromFirestore = (order) => {
|
|
1749
2486
|
if (!!order?.lineItems?.length) {
|
|
1750
2487
|
order.lineItems = order.lineItems.map((lineItem) => {
|
|
@@ -1757,11 +2494,6 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
1757
2494
|
}
|
|
1758
2495
|
return order;
|
|
1759
2496
|
};
|
|
1760
|
-
this.collectionName = 'orders';
|
|
1761
|
-
this.model = Order;
|
|
1762
|
-
this.fields = {
|
|
1763
|
-
status: FirestoreFieldType.String,
|
|
1764
|
-
};
|
|
1765
2497
|
}
|
|
1766
2498
|
buildModelInstance() {
|
|
1767
2499
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
@@ -1775,84 +2507,58 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
1775
2507
|
}
|
|
1776
2508
|
}
|
|
1777
2509
|
|
|
1778
|
-
class
|
|
1779
|
-
constructor(firestore) {
|
|
1780
|
-
super(
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
2510
|
+
class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
|
|
2511
|
+
constructor({ firestore, interceptors }) {
|
|
2512
|
+
super({
|
|
2513
|
+
firestore,
|
|
2514
|
+
interceptors,
|
|
2515
|
+
});
|
|
2516
|
+
this.collectionName = 'legacyOrders';
|
|
1784
2517
|
}
|
|
1785
2518
|
}
|
|
1786
2519
|
|
|
1787
|
-
class
|
|
1788
|
-
constructor(firestore) {
|
|
1789
|
-
super(
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
2520
|
+
class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2521
|
+
constructor({ firestore, interceptors }) {
|
|
2522
|
+
super({
|
|
2523
|
+
firestore,
|
|
2524
|
+
collectionName: 'payments',
|
|
2525
|
+
model: Payment,
|
|
2526
|
+
interceptors,
|
|
2527
|
+
});
|
|
1793
2528
|
}
|
|
1794
2529
|
}
|
|
1795
2530
|
|
|
1796
2531
|
class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1797
|
-
constructor(firestore) {
|
|
1798
|
-
super(
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
}
|
|
1804
|
-
|
|
1805
|
-
class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1806
|
-
constructor(firestore) {
|
|
1807
|
-
super();
|
|
1808
|
-
this.firestore = firestore;
|
|
1809
|
-
this.collectionName = 'buy2win';
|
|
1810
|
-
this.model = Buy2Win;
|
|
1811
|
-
}
|
|
1812
|
-
}
|
|
1813
|
-
|
|
1814
|
-
class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
|
|
1815
|
-
constructor(firestore) {
|
|
1816
|
-
super(firestore);
|
|
1817
|
-
this.firestore = firestore;
|
|
1818
|
-
this.collectionName = 'legacyOrders';
|
|
2532
|
+
constructor({ firestore, interceptors, }) {
|
|
2533
|
+
super({
|
|
2534
|
+
firestore,
|
|
2535
|
+
collectionName: 'subscriptionPlans',
|
|
2536
|
+
model: SubscriptionPlan,
|
|
2537
|
+
interceptors,
|
|
2538
|
+
});
|
|
1819
2539
|
}
|
|
1820
2540
|
}
|
|
1821
2541
|
|
|
1822
2542
|
class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1823
|
-
constructor(firestore) {
|
|
1824
|
-
super(
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.homeCategoryGroupToPlain);
|
|
1831
|
-
}
|
|
1832
|
-
return home;
|
|
1833
|
-
};
|
|
2543
|
+
constructor({ firestore, interceptors }) {
|
|
2544
|
+
super({
|
|
2545
|
+
firestore,
|
|
2546
|
+
collectionName: 'dms',
|
|
2547
|
+
model: Home,
|
|
2548
|
+
interceptors,
|
|
2549
|
+
});
|
|
1834
2550
|
this.homeCategoryGroupToPlain = (homeCategoryGroup) => ({
|
|
1835
|
-
category: homeCategoryGroup
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
|
|
1843
|
-
home.data.createdAt =
|
|
1844
|
-
home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
|
|
1845
|
-
home.data.expiresAt =
|
|
1846
|
-
home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
|
|
1847
|
-
}
|
|
1848
|
-
return home;
|
|
1849
|
-
};
|
|
2551
|
+
category: homeCategoryGroup?.category?.toPlain
|
|
2552
|
+
? homeCategoryGroup?.category?.toPlain()
|
|
2553
|
+
: homeCategoryGroup?.category,
|
|
2554
|
+
products: homeCategoryGroup?.products
|
|
2555
|
+
?.map((product) => (product?.toPlain ? product?.toPlain() : product))
|
|
2556
|
+
.filter(Boolean) || [],
|
|
2557
|
+
});
|
|
1850
2558
|
this.plainToHomeCategoryGroup = (homeCategoryGroup) => ({
|
|
1851
|
-
category: Category.toInstance(homeCategoryGroup
|
|
1852
|
-
products: homeCategoryGroup.products
|
|
2559
|
+
category: Category.toInstance(homeCategoryGroup?.category),
|
|
2560
|
+
products: homeCategoryGroup.products?.map((product) => Product.toInstance(product)),
|
|
1853
2561
|
});
|
|
1854
|
-
this.collectionName = 'dms';
|
|
1855
|
-
this.model = Home;
|
|
1856
2562
|
}
|
|
1857
2563
|
buildModelInstance() {
|
|
1858
2564
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
@@ -1867,14 +2573,47 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
1867
2573
|
},
|
|
1868
2574
|
};
|
|
1869
2575
|
}
|
|
2576
|
+
homeToFirestore(home) {
|
|
2577
|
+
if (home.data?.data) {
|
|
2578
|
+
home.data.data.discoverProducts = home.data.data.discoverProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
2579
|
+
home.data.data.featuredProducts = home.data.data.featuredProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
2580
|
+
home.data.data.verticalProducts = home.data.data.verticalProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
2581
|
+
}
|
|
2582
|
+
return home;
|
|
2583
|
+
}
|
|
2584
|
+
homeFromFirestore(home) {
|
|
2585
|
+
if (home.data?.data) {
|
|
2586
|
+
home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
|
|
2587
|
+
home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
|
|
2588
|
+
home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
|
|
2589
|
+
home.data.createdAt =
|
|
2590
|
+
home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
|
|
2591
|
+
home.data.expiresAt =
|
|
2592
|
+
home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
|
|
2593
|
+
}
|
|
2594
|
+
return home;
|
|
2595
|
+
}
|
|
1870
2596
|
}
|
|
1871
2597
|
|
|
1872
2598
|
class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1873
|
-
constructor(firestore) {
|
|
1874
|
-
super(
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
2599
|
+
constructor({ firestore, interceptors }) {
|
|
2600
|
+
super({
|
|
2601
|
+
firestore,
|
|
2602
|
+
collectionName: 'shopMenus',
|
|
2603
|
+
model: ShopMenu,
|
|
2604
|
+
interceptors,
|
|
2605
|
+
});
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2610
|
+
constructor({ firestore, interceptors, }) {
|
|
2611
|
+
super({
|
|
2612
|
+
firestore,
|
|
2613
|
+
collectionName: 'shopSettings',
|
|
2614
|
+
model: ShopSettings,
|
|
2615
|
+
interceptors,
|
|
2616
|
+
});
|
|
1878
2617
|
}
|
|
1879
2618
|
}
|
|
1880
2619
|
|
|
@@ -1951,7 +2690,7 @@ class AttributeOptionHelper {
|
|
|
1951
2690
|
}
|
|
1952
2691
|
AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
1953
2692
|
if (fields.includes(attributeName))
|
|
1954
|
-
return { columnName: attributeName.toString(), attributeName };
|
|
2693
|
+
return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
|
|
1955
2694
|
const field = fields.find((columnOption) => isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
|
|
1956
2695
|
const fieldOption = is(field)?.[attributeName];
|
|
1957
2696
|
if (isNil(fieldOption))
|
|
@@ -1960,7 +2699,7 @@ AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
|
1960
2699
|
return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
|
|
1961
2700
|
return { attributeName, columnName: attributeName.toString(), ...fieldOption };
|
|
1962
2701
|
};
|
|
1963
|
-
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue
|
|
2702
|
+
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue?.columnName;
|
|
1964
2703
|
AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
1965
2704
|
if (fields.includes(columnName))
|
|
1966
2705
|
return { columnName, attributeName: columnName };
|
|
@@ -2053,25 +2792,26 @@ BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter)
|
|
|
2053
2792
|
}, {});
|
|
2054
2793
|
BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
2055
2794
|
const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
|
|
2056
|
-
|
|
2795
|
+
const isNestedField = !Array.isArray(options) &&
|
|
2057
2796
|
isObject(options) &&
|
|
2058
2797
|
isNil(options?.operator) &&
|
|
2059
2798
|
isNil(options?.value) &&
|
|
2060
|
-
isNil(fieldSentenceOptions?.to)
|
|
2799
|
+
isNil(fieldSentenceOptions?.to);
|
|
2800
|
+
if (isNestedField)
|
|
2061
2801
|
return Object.keys(options).reduce((variables, key) => {
|
|
2062
2802
|
const fieldOptions = AttributeOptionHelper.FindByAttribute(key, fieldSentenceOptions?.fields || fields);
|
|
2063
2803
|
const columnName = fieldOptions.columnName;
|
|
2064
2804
|
const columnFields = fieldOptions.fields;
|
|
2065
2805
|
return {
|
|
2066
2806
|
...variables,
|
|
2067
|
-
[columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), columnFields ||
|
|
2807
|
+
[columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), fieldSentenceOptions?.fields || columnFields || fields),
|
|
2068
2808
|
};
|
|
2069
2809
|
}, {});
|
|
2070
2810
|
if (!Array.isArray(options) && !isNil(fieldSentenceOptions.fields))
|
|
2071
2811
|
return {
|
|
2072
2812
|
[fieldSentenceOptions.fields[0]]: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions),
|
|
2073
2813
|
};
|
|
2074
|
-
if (isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
2814
|
+
if (!Array.isArray(options) && isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
2075
2815
|
options = Object.values(options)[0];
|
|
2076
2816
|
return Array.isArray(options)
|
|
2077
2817
|
? options.reduce((whereSentence, option) => ({
|
|
@@ -2107,28 +2847,14 @@ GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
|
2107
2847
|
if (field === 'affected_rows')
|
|
2108
2848
|
return field;
|
|
2109
2849
|
const fieldName = Object.keys(field).shift();
|
|
2110
|
-
const fieldValue = field[fieldName];
|
|
2850
|
+
const fieldValue = is(field[fieldName]);
|
|
2111
2851
|
if (Array.isArray(fieldValue))
|
|
2112
2852
|
return { [fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue) };
|
|
2113
2853
|
if (!AttributeOptionHelper.CheckIsColumnOption(fieldValue))
|
|
2114
|
-
return
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
[fieldValue.columnName || fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
2119
|
-
}
|
|
2120
|
-
: {
|
|
2121
|
-
operation: fieldValue.columnName || fieldName,
|
|
2122
|
-
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
2123
|
-
variables: {
|
|
2124
|
-
[`${fieldValue.columnName}_where`]: {
|
|
2125
|
-
name: 'where',
|
|
2126
|
-
type: fieldValue.filters.filterType,
|
|
2127
|
-
value: BindFilterQueryHelper.MakeGraphQLWhere(fieldValue.filters.filters, fieldValue.fields),
|
|
2128
|
-
required: true,
|
|
2129
|
-
},
|
|
2130
|
-
},
|
|
2131
|
-
};
|
|
2854
|
+
return;
|
|
2855
|
+
const isNestedField = !!fieldValue.fields;
|
|
2856
|
+
if (isNestedField)
|
|
2857
|
+
return GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields(fieldName, fieldValue);
|
|
2132
2858
|
return fieldValue.columnName;
|
|
2133
2859
|
})
|
|
2134
2860
|
.filter((field) => !!field);
|
|
@@ -2153,7 +2879,10 @@ GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).r
|
|
|
2153
2879
|
}
|
|
2154
2880
|
if (!!from)
|
|
2155
2881
|
return { ...result, [attributeName]: from(data[columnName], data) };
|
|
2156
|
-
return {
|
|
2882
|
+
return {
|
|
2883
|
+
...result,
|
|
2884
|
+
[attributeName]: isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName],
|
|
2885
|
+
};
|
|
2157
2886
|
}, {});
|
|
2158
2887
|
GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
2159
2888
|
const data = instance.toPlain?.() || instance;
|
|
@@ -2169,10 +2898,13 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
|
2169
2898
|
if (!!foreignKeyColumn &&
|
|
2170
2899
|
!isEmpty(foreignKeyColumn) &&
|
|
2171
2900
|
!Object.keys(foreignKeyColumn).filter((key) => !is(data[attributeName])?.[key]).length)
|
|
2172
|
-
return Object.keys(foreignKeyColumn).reduce((object, current) =>
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2901
|
+
return Object.keys(foreignKeyColumn).reduce((object, current) => {
|
|
2902
|
+
const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
|
|
2903
|
+
return {
|
|
2904
|
+
...object,
|
|
2905
|
+
[foreignColumnName]: data[attributeName]?.[current],
|
|
2906
|
+
};
|
|
2907
|
+
}, { ...result });
|
|
2176
2908
|
if (update &&
|
|
2177
2909
|
isObject(data[attributeName]) &&
|
|
2178
2910
|
!isNil(attributeFields) &&
|
|
@@ -2205,6 +2937,25 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
|
2205
2937
|
return { ...result, [columnName]: data[attributeName] };
|
|
2206
2938
|
}, {});
|
|
2207
2939
|
};
|
|
2940
|
+
GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue) => {
|
|
2941
|
+
const hasCustomFilters = !!fieldValue.filters;
|
|
2942
|
+
if (hasCustomFilters)
|
|
2943
|
+
return {
|
|
2944
|
+
operation: fieldValue.columnName || fieldName,
|
|
2945
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
2946
|
+
variables: {
|
|
2947
|
+
[`${fieldValue.columnName}_where`]: {
|
|
2948
|
+
name: 'where',
|
|
2949
|
+
type: fieldValue.filters.filterType,
|
|
2950
|
+
value: BindFilterQueryHelper.MakeGraphQLWhere(fieldValue.filters.filters, fieldValue.fields),
|
|
2951
|
+
required: true,
|
|
2952
|
+
},
|
|
2953
|
+
},
|
|
2954
|
+
};
|
|
2955
|
+
return {
|
|
2956
|
+
[fieldValue.columnName || fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
2957
|
+
};
|
|
2958
|
+
};
|
|
2208
2959
|
|
|
2209
2960
|
const withCreateHasuraGraphQL = (MixinBase) => {
|
|
2210
2961
|
return class CreateHasuraGraphQLMixin extends MixinBase {
|
|
@@ -2215,6 +2966,7 @@ const withCreateHasuraGraphQL = (MixinBase) => {
|
|
|
2215
2966
|
this.insertGraphQLObjectType = options?.insertGraphQLObjectType || `${this.tableName}_insert_input`;
|
|
2216
2967
|
}
|
|
2217
2968
|
async create(data) {
|
|
2969
|
+
this.logger = DebugHelper.from(this, 'create');
|
|
2218
2970
|
const newData = await this.save(this.model.toInstance(data));
|
|
2219
2971
|
return this.model.toInstance(newData);
|
|
2220
2972
|
}
|
|
@@ -2225,10 +2977,10 @@ const withCreateHasuraGraphQL = (MixinBase) => {
|
|
|
2225
2977
|
const columnOptions = Object.values(field).shift();
|
|
2226
2978
|
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
2227
2979
|
columnOptions.foreignKeyColumn && [
|
|
2228
|
-
...Object.values(columnOptions.foreignKeyColumn),
|
|
2980
|
+
...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => AttributeOptionHelper.FindByAttribute(foreignKeyName, this.fields)?.columnName),
|
|
2229
2981
|
{
|
|
2230
|
-
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)
|
|
2231
|
-
foreignKeyField),
|
|
2982
|
+
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)
|
|
2983
|
+
?.columnName || foreignKeyField),
|
|
2232
2984
|
},
|
|
2233
2985
|
]);
|
|
2234
2986
|
})
|
|
@@ -2250,9 +3002,11 @@ const withDeleteHasuraGraphQL = (MixinBase) => {
|
|
|
2250
3002
|
this.deleteGraphQLOperation = options?.deleteGraphQLOperation || `delete_${this.tableName}_by_pk`;
|
|
2251
3003
|
}
|
|
2252
3004
|
async delete(identifiers) {
|
|
3005
|
+
this.logger = DebugHelper.from(this, 'delete');
|
|
2253
3006
|
const instance = this.model.toInstance(identifiers);
|
|
2254
3007
|
await this.mutation(this.deleteGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), this.model.identifiersFields.reduce((ids, identifier) => {
|
|
2255
|
-
|
|
3008
|
+
const identifierBinded = identifier;
|
|
3009
|
+
if (isNil(instance.identifier[identifierBinded]))
|
|
2256
3010
|
return ids;
|
|
2257
3011
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
|
|
2258
3012
|
const value = columnOption.to(identifiers[identifier], instance);
|
|
@@ -2279,15 +3033,19 @@ const withHasuraGraphQL = (MixinBase) => {
|
|
|
2279
3033
|
this.authOptions = options.authOptions;
|
|
2280
3034
|
this.model = options.model;
|
|
2281
3035
|
this.fields = options.fields || this.model.identifiersFields;
|
|
3036
|
+
this.logger = DebugHelper.from(this);
|
|
2282
3037
|
}
|
|
2283
3038
|
get headers() {
|
|
2284
3039
|
return {
|
|
2285
3040
|
'Content-Type': 'application/json',
|
|
2286
|
-
...(isNil(this.authOptions
|
|
2287
|
-
...(isNil(this.authOptions
|
|
2288
|
-
...(isNil(this.authOptions
|
|
3041
|
+
...(isNil(this.authOptions?.authToken) ? {} : { Authorization: this.authOptions?.authToken }),
|
|
3042
|
+
...(isNil(this.authOptions?.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': this.authOptions?.adminSecret }),
|
|
3043
|
+
...(isNil(this.authOptions?.authRole)
|
|
2289
3044
|
? {}
|
|
2290
|
-
: {
|
|
3045
|
+
: {
|
|
3046
|
+
'X-Hasura-Role': this.authOptions.authRole.role,
|
|
3047
|
+
'X-Hasura-User-Id': this.authOptions?.authRole?.userId,
|
|
3048
|
+
}),
|
|
2291
3049
|
};
|
|
2292
3050
|
}
|
|
2293
3051
|
async mutation(operation, fields, variables) {
|
|
@@ -2299,29 +3057,28 @@ const withHasuraGraphQL = (MixinBase) => {
|
|
|
2299
3057
|
return this.fetch(resultQuery);
|
|
2300
3058
|
}
|
|
2301
3059
|
async query(operation, fields, variables) {
|
|
2302
|
-
const
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
|
|
2312
|
-
});
|
|
2313
|
-
return this.fetch(resultQuery);
|
|
3060
|
+
const builded = this.buildHasuraQueryFields({
|
|
3061
|
+
operation,
|
|
3062
|
+
fields: fields,
|
|
3063
|
+
variables,
|
|
3064
|
+
});
|
|
3065
|
+
const interpected = (await this.interceptors?.request?.(builded)) || builded;
|
|
3066
|
+
const resultQuery = query$1(interpected);
|
|
3067
|
+
const result = await this.fetch(resultQuery);
|
|
3068
|
+
return (await this.interceptors?.response?.(result, interpected)) || result;
|
|
2314
3069
|
}
|
|
2315
3070
|
async fetch(params) {
|
|
3071
|
+
this.logger.with('params').log(params);
|
|
2316
3072
|
const headers = this.headers;
|
|
2317
|
-
const
|
|
3073
|
+
const { data: result } = await axios({
|
|
3074
|
+
url: `${this.endpoint}`,
|
|
2318
3075
|
method: 'POST',
|
|
2319
|
-
|
|
3076
|
+
data: params,
|
|
2320
3077
|
headers,
|
|
2321
3078
|
});
|
|
2322
|
-
const result = await response.json();
|
|
2323
3079
|
if (!isNil(result.errors))
|
|
2324
3080
|
throw new Error(JSON.stringify(result.errors));
|
|
3081
|
+
this.logger.with('returns').log(result);
|
|
2325
3082
|
return result.data;
|
|
2326
3083
|
}
|
|
2327
3084
|
getAttributeGraphQLTypeOf(value) {
|
|
@@ -2347,13 +3104,26 @@ const withHasuraGraphQL = (MixinBase) => {
|
|
|
2347
3104
|
return value;
|
|
2348
3105
|
return date;
|
|
2349
3106
|
}
|
|
2350
|
-
convertDataFromHasura(data) {
|
|
2351
|
-
const plain = GraphQLFieldHelper.ConvertFieldValueFrom(data, this.fields);
|
|
3107
|
+
convertDataFromHasura(data, fields) {
|
|
3108
|
+
const plain = GraphQLFieldHelper.ConvertFieldValueFrom(data, fields || this.fields);
|
|
2352
3109
|
return this.model.toInstance(plain);
|
|
2353
3110
|
}
|
|
2354
3111
|
convertDataToHasura(instance, update = false) {
|
|
2355
3112
|
return GraphQLFieldHelper.ConvertFieldValueTo(instance, this.fields, update);
|
|
2356
3113
|
}
|
|
3114
|
+
buildHasuraQueryFields({ operation, fields, variables, }) {
|
|
3115
|
+
return GraphQLFieldHelper.CheckIsGraphQLParams(operation)
|
|
3116
|
+
? operation.map((option) => ({
|
|
3117
|
+
operation: option.operation,
|
|
3118
|
+
variables: option.variables,
|
|
3119
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(option.fields),
|
|
3120
|
+
}))
|
|
3121
|
+
: {
|
|
3122
|
+
operation,
|
|
3123
|
+
variables,
|
|
3124
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
|
|
3125
|
+
};
|
|
3126
|
+
}
|
|
2357
3127
|
};
|
|
2358
3128
|
};
|
|
2359
3129
|
|
|
@@ -2376,6 +3146,7 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
|
2376
3146
|
this.updateGraphQLPKType = options?.updateGraphQLPKType || `${this.tableName}_pk_columns_input`;
|
|
2377
3147
|
}
|
|
2378
3148
|
async update(data) {
|
|
3149
|
+
this.logger = DebugHelper.from(this, 'update');
|
|
2379
3150
|
const plainData = this.paramsToPlain(data);
|
|
2380
3151
|
await this.mutation(this.updateGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), {
|
|
2381
3152
|
_set: {
|
|
@@ -2401,10 +3172,11 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
|
2401
3172
|
getUpdateModelKeys(data) {
|
|
2402
3173
|
const instance = this.model.toInstance(data);
|
|
2403
3174
|
return this.model.identifiersFields.reduce((ids, identifier) => {
|
|
2404
|
-
|
|
3175
|
+
const identifierBinded = identifier;
|
|
3176
|
+
if (isNil(instance.identifier[identifierBinded]))
|
|
2405
3177
|
return ids;
|
|
2406
|
-
const columnOption = AttributeOptionHelper.FindByAttribute(
|
|
2407
|
-
const value = columnOption?.to?.(data[
|
|
3178
|
+
const columnOption = AttributeOptionHelper.FindByAttribute(identifierBinded, this.fields);
|
|
3179
|
+
const value = columnOption?.to?.(data[identifierBinded], instance) || data[columnOption.attributeName];
|
|
2408
3180
|
return {
|
|
2409
3181
|
...ids,
|
|
2410
3182
|
[columnOption.columnName]: value,
|
|
@@ -2422,9 +3194,11 @@ const withGetHasuraGraphQL = (MixinBase) => {
|
|
|
2422
3194
|
this.getGraphQLOperation = options?.getGraphQLOperation || `${this.tableName}_by_pk`;
|
|
2423
3195
|
}
|
|
2424
3196
|
async get(identifiers) {
|
|
3197
|
+
this.logger = DebugHelper.from(this, 'get');
|
|
2425
3198
|
const instance = this.model.toInstance(identifiers);
|
|
2426
3199
|
const result = await this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce((ids, identifier) => {
|
|
2427
|
-
|
|
3200
|
+
const identifierBinded = identifier;
|
|
3201
|
+
if (isNil(instance[identifierBinded]))
|
|
2428
3202
|
return ids;
|
|
2429
3203
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
|
|
2430
3204
|
const value = columnOption?.to?.(identifiers[identifier], instance) ||
|
|
@@ -2448,44 +3222,150 @@ const withGetHasuraGraphQL = (MixinBase) => {
|
|
|
2448
3222
|
|
|
2449
3223
|
const withFindHasuraGraphQL = (MixinBase) => {
|
|
2450
3224
|
return class FindHasuraGraphQLMixin extends MixinBase {
|
|
2451
|
-
|
|
2452
|
-
|
|
3225
|
+
constructor() {
|
|
3226
|
+
super(...arguments);
|
|
3227
|
+
this.bindOrderByAttributes = (orderBy, fields) => Object.keys(orderBy).reduce((acc, current) => [
|
|
3228
|
+
...acc,
|
|
3229
|
+
{
|
|
3230
|
+
[AttributeOptionHelper.FindByAttribute(current, fields)
|
|
3231
|
+
.columnName]: orderBy[current] === 'asc'
|
|
3232
|
+
? 'asc_nulls_last'
|
|
3233
|
+
: 'desc_nulls_last',
|
|
3234
|
+
},
|
|
3235
|
+
], []);
|
|
3236
|
+
this.bindAggretageAttributes = (aggregates, fields) => [
|
|
3237
|
+
...(aggregates?.minimal?.length
|
|
3238
|
+
? [
|
|
3239
|
+
{
|
|
3240
|
+
min: this.bindAttributesToColumns(aggregates?.minimal, fields),
|
|
3241
|
+
},
|
|
3242
|
+
]
|
|
3243
|
+
: []),
|
|
3244
|
+
...(aggregates?.maximum?.length
|
|
3245
|
+
? [
|
|
3246
|
+
{
|
|
3247
|
+
max: this.bindAttributesToColumns(aggregates?.maximum, fields),
|
|
3248
|
+
},
|
|
3249
|
+
]
|
|
3250
|
+
: []),
|
|
3251
|
+
];
|
|
3252
|
+
this.bindDistinctAttributes = (distinct, fields) => this.bindAttributesToColumns(distinct, fields);
|
|
3253
|
+
this.bindAttributesToColumns = (attributes, fields) => attributes.map((attr) => AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)?.columnName || attr);
|
|
3254
|
+
}
|
|
3255
|
+
async find(params) {
|
|
3256
|
+
this.logger = DebugHelper.from(this, 'find');
|
|
3257
|
+
const { filters, limits, orderBy, options } = params || {};
|
|
3258
|
+
const enableCount = options?.enableCount ?? true;
|
|
3259
|
+
const variablesFilters = isNil(filters)
|
|
3260
|
+
? {}
|
|
3261
|
+
: {
|
|
3262
|
+
where: {
|
|
3263
|
+
value: BindFilterQueryHelper.MakeGraphQLWhere(filters, this.fields),
|
|
3264
|
+
type: `${this.tableName}_bool_exp`,
|
|
3265
|
+
required: true,
|
|
3266
|
+
},
|
|
3267
|
+
};
|
|
2453
3268
|
const variablesCount = {
|
|
2454
|
-
...(isNil(orderBy)
|
|
2455
|
-
...(isNil(filters)
|
|
3269
|
+
...(isNil(orderBy)
|
|
2456
3270
|
? {}
|
|
2457
3271
|
: {
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
3272
|
+
order_by: {
|
|
3273
|
+
type: `${this.tableName}_order_by!`,
|
|
3274
|
+
list: true,
|
|
3275
|
+
value: this.bindOrderByAttributes(orderBy, this.fields),
|
|
2462
3276
|
},
|
|
2463
3277
|
}),
|
|
3278
|
+
...variablesFilters,
|
|
2464
3279
|
};
|
|
2465
3280
|
const variables = {
|
|
2466
3281
|
...(isNil(limits) ? {} : limits),
|
|
2467
3282
|
...variablesCount,
|
|
2468
3283
|
};
|
|
3284
|
+
const aggregateFields = [
|
|
3285
|
+
...(enableCount ? ['count'] : []),
|
|
3286
|
+
...this.bindAggretageAttributes(params.options, this.fields),
|
|
3287
|
+
];
|
|
2469
3288
|
const result = await this.query([
|
|
2470
3289
|
{
|
|
2471
3290
|
operation: this.tableName,
|
|
2472
|
-
fields:
|
|
2473
|
-
?
|
|
3291
|
+
fields: params.fields
|
|
3292
|
+
? params.fields
|
|
2474
3293
|
.map((fieldName) => this.fields.find((fieldOption) => fieldOption === fieldName) ??
|
|
2475
3294
|
this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName))
|
|
2476
3295
|
.filter(Boolean)
|
|
2477
3296
|
: this.fields,
|
|
2478
3297
|
variables,
|
|
2479
3298
|
},
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
3299
|
+
...(aggregateFields.length > 0
|
|
3300
|
+
? [
|
|
3301
|
+
{
|
|
3302
|
+
operation: `${this.tableName}_aggregate`,
|
|
3303
|
+
fields: [
|
|
3304
|
+
{
|
|
3305
|
+
aggregate: aggregateFields,
|
|
3306
|
+
},
|
|
3307
|
+
],
|
|
3308
|
+
variables: variablesCount,
|
|
3309
|
+
},
|
|
3310
|
+
]
|
|
3311
|
+
: []),
|
|
3312
|
+
...((!params.limits?.offset &&
|
|
3313
|
+
params.options?.distinct?.map((distinct) => {
|
|
3314
|
+
const distinctOption = this.fields.find((fieldOption) => fieldOption === distinct) ??
|
|
3315
|
+
this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
3316
|
+
const fieldName = Object.values(distinctOption).shift()?.columnName || distinct;
|
|
3317
|
+
return {
|
|
3318
|
+
operation: {
|
|
3319
|
+
name: `${this.tableName}`,
|
|
3320
|
+
alias: `${this.tableName}_${distinct.toString()}_distinct`,
|
|
3321
|
+
},
|
|
3322
|
+
fields: [distinctOption],
|
|
3323
|
+
variables: {
|
|
3324
|
+
...variablesFilters,
|
|
3325
|
+
[`${this.tableName}_${fieldName}_distinct`]: {
|
|
3326
|
+
type: `${this.tableName}_select_column!`,
|
|
3327
|
+
list: true,
|
|
3328
|
+
value: fieldName,
|
|
3329
|
+
name: 'distinct_on',
|
|
3330
|
+
},
|
|
3331
|
+
},
|
|
3332
|
+
};
|
|
3333
|
+
})) ||
|
|
3334
|
+
[]),
|
|
2485
3335
|
]);
|
|
2486
3336
|
const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
|
|
2487
|
-
|
|
2488
|
-
|
|
3337
|
+
return {
|
|
3338
|
+
data,
|
|
3339
|
+
count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity,
|
|
3340
|
+
...(options?.minimal?.length
|
|
3341
|
+
? {
|
|
3342
|
+
minimal: options.minimal.reduce((minimals, current) => ({
|
|
3343
|
+
...minimals,
|
|
3344
|
+
...set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)?.columnName || current]),
|
|
3345
|
+
}), {}),
|
|
3346
|
+
}
|
|
3347
|
+
: {}),
|
|
3348
|
+
...(options?.maximum?.length
|
|
3349
|
+
? {
|
|
3350
|
+
maximum: options.maximum.reduce((maximums, current) => ({
|
|
3351
|
+
...maximums,
|
|
3352
|
+
...set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)?.columnName || current]),
|
|
3353
|
+
}), {}),
|
|
3354
|
+
}
|
|
3355
|
+
: {}),
|
|
3356
|
+
...(!params.limits?.offset &&
|
|
3357
|
+
options?.distinct?.length && {
|
|
3358
|
+
distinct: options?.distinct.reduce((distinct, current) => {
|
|
3359
|
+
const distinctOption = this.fields.find((fieldOption) => fieldOption === current) ??
|
|
3360
|
+
this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
|
|
3361
|
+
const fieldName = Object.values(distinctOption).shift()?.columnName || current;
|
|
3362
|
+
return {
|
|
3363
|
+
...distinct,
|
|
3364
|
+
[current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]),
|
|
3365
|
+
};
|
|
3366
|
+
}, {}),
|
|
3367
|
+
}),
|
|
3368
|
+
};
|
|
2489
3369
|
}
|
|
2490
3370
|
};
|
|
2491
3371
|
};
|
|
@@ -2524,13 +3404,154 @@ class VariantHasuraGraphQL extends Variant {
|
|
|
2524
3404
|
}
|
|
2525
3405
|
}
|
|
2526
3406
|
|
|
3407
|
+
class CategoryCollectionChildrenHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
3408
|
+
constructor({ endpoint, authOptions, interceptors, }) {
|
|
3409
|
+
super({
|
|
3410
|
+
tableName: 'category_collection_children',
|
|
3411
|
+
model: CategoryCollectionChildren,
|
|
3412
|
+
endpoint,
|
|
3413
|
+
authOptions,
|
|
3414
|
+
interceptors,
|
|
3415
|
+
fields: [
|
|
3416
|
+
{ collectionId: { columnName: 'collection_id' } },
|
|
3417
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
3418
|
+
'name',
|
|
3419
|
+
'slug',
|
|
3420
|
+
'reference',
|
|
3421
|
+
{ parentCollectionId: { columnName: 'parent_collection_id' } },
|
|
3422
|
+
{ parentCategoryId: { columnName: 'parent_category_id' } },
|
|
3423
|
+
{
|
|
3424
|
+
parent: {
|
|
3425
|
+
columnName: 'parent',
|
|
3426
|
+
foreignKeyColumn: { collectionId: 'parentCollectionId', categoryId: 'parentCategoryId' },
|
|
3427
|
+
fields: [
|
|
3428
|
+
{ collectionId: { columnName: 'collection_id' } },
|
|
3429
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
3430
|
+
'name',
|
|
3431
|
+
'slug',
|
|
3432
|
+
'reference',
|
|
3433
|
+
{ parentCollectionId: { columnName: 'parent_collection_id' } },
|
|
3434
|
+
{ parentCategoryId: { columnName: 'parent_category_id' } },
|
|
3435
|
+
],
|
|
3436
|
+
},
|
|
3437
|
+
},
|
|
3438
|
+
],
|
|
3439
|
+
});
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
|
|
3443
|
+
class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
3444
|
+
constructor({ endpoint, authOptions, interceptors, }) {
|
|
3445
|
+
super({
|
|
3446
|
+
tableName: 'category_filter',
|
|
3447
|
+
model: CategoryFilter,
|
|
3448
|
+
endpoint,
|
|
3449
|
+
authOptions,
|
|
3450
|
+
interceptors,
|
|
3451
|
+
fields: [
|
|
3452
|
+
'id',
|
|
3453
|
+
{ filterId: { columnName: 'filter_id' } },
|
|
3454
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
3455
|
+
{
|
|
3456
|
+
filter: {
|
|
3457
|
+
columnName: 'filter',
|
|
3458
|
+
foreignKeyColumn: { id: 'filterId' },
|
|
3459
|
+
fields: [
|
|
3460
|
+
'id',
|
|
3461
|
+
'description',
|
|
3462
|
+
'slug',
|
|
3463
|
+
'enabled',
|
|
3464
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
3465
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
3466
|
+
{
|
|
3467
|
+
options: {
|
|
3468
|
+
columnName: 'options',
|
|
3469
|
+
foreignKeyColumn: { filterId: 'id' },
|
|
3470
|
+
fields: [
|
|
3471
|
+
'id',
|
|
3472
|
+
{ filterId: { columnName: 'filter_id' } },
|
|
3473
|
+
'description',
|
|
3474
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
3475
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
3476
|
+
],
|
|
3477
|
+
},
|
|
3478
|
+
},
|
|
3479
|
+
],
|
|
3480
|
+
},
|
|
3481
|
+
},
|
|
3482
|
+
{
|
|
3483
|
+
category: {
|
|
3484
|
+
columnName: 'category',
|
|
3485
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
3486
|
+
fields: [
|
|
3487
|
+
'id',
|
|
3488
|
+
'description',
|
|
3489
|
+
{
|
|
3490
|
+
products: {
|
|
3491
|
+
columnName: 'products',
|
|
3492
|
+
fields: ['product_id'],
|
|
3493
|
+
from: (value) => value.map((product) => product.product_id.toString()),
|
|
3494
|
+
to: (productIds) => productIds.map((productId) => ({
|
|
3495
|
+
product_id: +productId,
|
|
3496
|
+
})),
|
|
3497
|
+
},
|
|
3498
|
+
},
|
|
3499
|
+
{
|
|
3500
|
+
childrenProducts: {
|
|
3501
|
+
columnName: 'children_products',
|
|
3502
|
+
foreignKeyColumn: { category_id: 'id' },
|
|
3503
|
+
fields: [
|
|
3504
|
+
'id',
|
|
3505
|
+
'name',
|
|
3506
|
+
'slug',
|
|
3507
|
+
{
|
|
3508
|
+
categories: {
|
|
3509
|
+
columnName: 'categories',
|
|
3510
|
+
fields: ['category_id'],
|
|
3511
|
+
bindPersistData: (value) => ({
|
|
3512
|
+
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
3513
|
+
}),
|
|
3514
|
+
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
3515
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
3516
|
+
},
|
|
3517
|
+
},
|
|
3518
|
+
],
|
|
3519
|
+
},
|
|
3520
|
+
},
|
|
3521
|
+
],
|
|
3522
|
+
},
|
|
3523
|
+
},
|
|
3524
|
+
],
|
|
3525
|
+
});
|
|
3526
|
+
}
|
|
3527
|
+
deleteByCategory(categoryId) {
|
|
3528
|
+
return this.mutation('delete_category_filter', ['affected_rows'], {
|
|
3529
|
+
where: {
|
|
3530
|
+
type: 'category_filter_bool_exp',
|
|
3531
|
+
required: true,
|
|
3532
|
+
value: { category_id: { _eq: categoryId } },
|
|
3533
|
+
},
|
|
3534
|
+
});
|
|
3535
|
+
}
|
|
3536
|
+
deleteByCategoryAndFilter(categoryId, filterId) {
|
|
3537
|
+
return this.mutation('delete_category_filter', ['affected_rows'], {
|
|
3538
|
+
where: {
|
|
3539
|
+
type: 'category_filter_bool_exp',
|
|
3540
|
+
required: true,
|
|
3541
|
+
value: { category_id: { _eq: categoryId }, filter_id: { _eq: filterId } },
|
|
3542
|
+
},
|
|
3543
|
+
});
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
|
|
2527
3547
|
class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
2528
|
-
constructor(endpoint, authOptions, productRepository) {
|
|
3548
|
+
constructor({ endpoint, authOptions, interceptors, }, productRepository, categoryFilterRepository) {
|
|
2529
3549
|
super({
|
|
2530
3550
|
tableName: 'category',
|
|
2531
3551
|
model: Category,
|
|
2532
3552
|
endpoint,
|
|
2533
3553
|
authOptions,
|
|
3554
|
+
interceptors,
|
|
2534
3555
|
fields: [
|
|
2535
3556
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
2536
3557
|
{ firestoreId: { columnName: 'firestore_id' } },
|
|
@@ -2539,6 +3560,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2539
3560
|
'image',
|
|
2540
3561
|
'published',
|
|
2541
3562
|
'shop',
|
|
3563
|
+
{ shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
|
|
2542
3564
|
'slug',
|
|
2543
3565
|
{ brandCategory: { columnName: 'brand_category' } },
|
|
2544
3566
|
{ brandCategoryBanner: { columnName: 'brand_banner' } },
|
|
@@ -2567,7 +3589,17 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2567
3589
|
},
|
|
2568
3590
|
},
|
|
2569
3591
|
},
|
|
2570
|
-
|
|
3592
|
+
{
|
|
3593
|
+
filters: {
|
|
3594
|
+
columnName: 'filters',
|
|
3595
|
+
foreignKeyColumn: { filter_id: 'id' },
|
|
3596
|
+
fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
|
|
3597
|
+
bindPersistData: (value) => ({
|
|
3598
|
+
filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
3599
|
+
}),
|
|
3600
|
+
from: (filters) => filters?.map((filter) => filter?.filter) || [],
|
|
3601
|
+
},
|
|
3602
|
+
},
|
|
2571
3603
|
{ createdAt: { columnName: 'created_at' } },
|
|
2572
3604
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
2573
3605
|
{
|
|
@@ -2589,39 +3621,77 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2589
3621
|
}),
|
|
2590
3622
|
},
|
|
2591
3623
|
},
|
|
3624
|
+
{ isCollection: { columnName: 'is_collection' } },
|
|
3625
|
+
{ isWishlist: { columnName: 'is_wishlist' } },
|
|
3626
|
+
'reference',
|
|
3627
|
+
{ parentId: { columnName: 'parent_id' } },
|
|
3628
|
+
{
|
|
3629
|
+
parent: {
|
|
3630
|
+
columnName: 'parent',
|
|
3631
|
+
foreignKeyColumn: { id: 'parentId' },
|
|
3632
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
3633
|
+
},
|
|
3634
|
+
},
|
|
2592
3635
|
],
|
|
2593
3636
|
});
|
|
2594
3637
|
this.productRepository = productRepository;
|
|
3638
|
+
this.categoryFilterRepository = categoryFilterRepository;
|
|
2595
3639
|
}
|
|
2596
3640
|
async create(params) {
|
|
2597
3641
|
const { metadata, ...data } = params;
|
|
2598
|
-
return super.create({ ...data, metadata: metadata || { description: null, title: null } });
|
|
3642
|
+
return super.create({ ...data, isWishlist: false, metadata: metadata || { description: null, title: null } });
|
|
2599
3643
|
}
|
|
2600
3644
|
async get(identifiers) {
|
|
2601
3645
|
return Number.isNaN(+identifiers.id)
|
|
2602
|
-
? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
|
|
3646
|
+
? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })).data?.[0]
|
|
2603
3647
|
: super.get(identifiers);
|
|
2604
3648
|
}
|
|
2605
3649
|
async update(params) {
|
|
2606
|
-
const { products, id: checkId, metadata, ...data } = params;
|
|
3650
|
+
const { products, id: checkId, metadata, filters, ...data } = params;
|
|
2607
3651
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
2608
3652
|
const id = await this.getId(plainData.id);
|
|
2609
|
-
const category = await super.update({ id, ...data });
|
|
3653
|
+
const category = await super.update({ id, ...data, isWishlist: false });
|
|
2610
3654
|
category.products = products && (await this.updateProducts(+id, { products }));
|
|
2611
3655
|
category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
3656
|
+
category.filters = filters && (await this.updateFilters(+id, { filters }));
|
|
2612
3657
|
return category;
|
|
2613
3658
|
}
|
|
2614
3659
|
async getCategoryBySlug(slug, shop) {
|
|
2615
3660
|
if (!slug)
|
|
2616
3661
|
return null;
|
|
2617
|
-
const { data
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
3662
|
+
const { data } = await this.find({
|
|
3663
|
+
filters: {
|
|
3664
|
+
slug,
|
|
3665
|
+
shops: { operator: Where.IN, value: [shop] },
|
|
3666
|
+
published: { operator: Where.EQUALS, value: true },
|
|
3667
|
+
isWishlist: { operator: Where.EQUALS, value: false },
|
|
3668
|
+
},
|
|
3669
|
+
options: {
|
|
3670
|
+
enableCount: false,
|
|
3671
|
+
},
|
|
3672
|
+
});
|
|
3673
|
+
if (!data.length)
|
|
2621
3674
|
throw new NotFoundError(`Category with slug ${slug} not found`);
|
|
3675
|
+
if (data.length > 1)
|
|
3676
|
+
throw new DuplicatedResultsError('Query returned duplicated values');
|
|
2622
3677
|
return data.shift();
|
|
2623
3678
|
}
|
|
2624
|
-
async
|
|
3679
|
+
async getCategoryByShop(shop) {
|
|
3680
|
+
if (!shop)
|
|
3681
|
+
return;
|
|
3682
|
+
const { data } = await this.find({
|
|
3683
|
+
filters: {
|
|
3684
|
+
shops: { operator: Where.IN, value: [shop] },
|
|
3685
|
+
published: { operator: Where.EQUALS, value: true },
|
|
3686
|
+
isWishlist: { operator: Where.EQUALS, value: false },
|
|
3687
|
+
},
|
|
3688
|
+
options: {
|
|
3689
|
+
enableCount: false,
|
|
3690
|
+
},
|
|
3691
|
+
});
|
|
3692
|
+
return data;
|
|
3693
|
+
}
|
|
3694
|
+
async getCategoriesForHome(categoryIds, limit = 4, gender) {
|
|
2625
3695
|
if (!categoryIds?.length)
|
|
2626
3696
|
return [];
|
|
2627
3697
|
const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
|
|
@@ -2639,7 +3709,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2639
3709
|
return [];
|
|
2640
3710
|
const homeSections = await Promise.all(categories.map(async (category) => ({
|
|
2641
3711
|
category,
|
|
2642
|
-
products: await this.mountCategory(category, { limit, hasStock: true }),
|
|
3712
|
+
products: await this.mountCategory(category, { limit, hasStock: true, gender }),
|
|
2643
3713
|
})));
|
|
2644
3714
|
return homeSections;
|
|
2645
3715
|
}
|
|
@@ -2652,6 +3722,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2652
3722
|
id: { operator: Where.IN, value: category.products },
|
|
2653
3723
|
published: true,
|
|
2654
3724
|
...(options?.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {}),
|
|
3725
|
+
...(options?.gender ? { tags: { operator: Where.IN, value: [options?.gender] } } : {}),
|
|
2655
3726
|
},
|
|
2656
3727
|
fields: [
|
|
2657
3728
|
'id',
|
|
@@ -2677,8 +3748,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2677
3748
|
'tags',
|
|
2678
3749
|
'type',
|
|
2679
3750
|
'shoppingCount',
|
|
3751
|
+
'gender',
|
|
3752
|
+
'createdAt',
|
|
2680
3753
|
],
|
|
2681
3754
|
...(options?.limit ? { limits: { limit: options?.limit } } : {}),
|
|
3755
|
+
options: { enableCount: false },
|
|
2682
3756
|
});
|
|
2683
3757
|
products.push(...productsData);
|
|
2684
3758
|
return products;
|
|
@@ -2686,7 +3760,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2686
3760
|
async getId(id) {
|
|
2687
3761
|
if (!Number.isNaN(+id))
|
|
2688
3762
|
return id;
|
|
2689
|
-
const { data } = await this.find({ filters: { firestoreId: id } });
|
|
3763
|
+
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
2690
3764
|
if (data?.[0]?.id)
|
|
2691
3765
|
return data?.[0]?.id;
|
|
2692
3766
|
throw new NotFoundError(`Category with id ${id} not found`);
|
|
@@ -2739,15 +3813,200 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2739
3813
|
});
|
|
2740
3814
|
return plainData.metadata;
|
|
2741
3815
|
}
|
|
3816
|
+
async updateFilters(categoryId, { filters }) {
|
|
3817
|
+
if ('action' in filters && filters.action === 'remove' && filters.value.length) {
|
|
3818
|
+
for (let i = 0; i < filters.value.length; i++) {
|
|
3819
|
+
await this.categoryFilterRepository.deleteByCategoryAndFilter(categoryId, filters.value[i].id);
|
|
3820
|
+
}
|
|
3821
|
+
return [];
|
|
3822
|
+
}
|
|
3823
|
+
if ('action' in filters && filters.action === 'merge' && filters.value.length) {
|
|
3824
|
+
let filtersList = [];
|
|
3825
|
+
const currentFilters = await this.categoryFilterRepository
|
|
3826
|
+
.find({
|
|
3827
|
+
filters: {
|
|
3828
|
+
categoryId,
|
|
3829
|
+
},
|
|
3830
|
+
})
|
|
3831
|
+
.then((res) => res.data);
|
|
3832
|
+
const currentFiltersId = currentFilters.map((f) => f.id);
|
|
3833
|
+
const filtersUpdatedId = filters.value.map((f) => f.id);
|
|
3834
|
+
const filterToBeDeleted = currentFiltersId.filter((c) => !filtersUpdatedId.includes(c));
|
|
3835
|
+
const filterToBeInserted = filtersUpdatedId.filter((c) => !currentFiltersId.includes(c));
|
|
3836
|
+
for (const filter of filterToBeDeleted) {
|
|
3837
|
+
const index = currentFilters.findIndex((f) => f.id == filter);
|
|
3838
|
+
if (index != -1) {
|
|
3839
|
+
currentFilters.splice(index, 1);
|
|
3840
|
+
}
|
|
3841
|
+
await this.categoryFilterRepository.deleteByCategoryAndFilter(categoryId, filter);
|
|
3842
|
+
}
|
|
3843
|
+
for (const filter of filterToBeInserted) {
|
|
3844
|
+
const newCategoryFilter = await this.categoryFilterRepository.create({
|
|
3845
|
+
filterId: filter,
|
|
3846
|
+
categoryId,
|
|
3847
|
+
});
|
|
3848
|
+
filtersList.push(filter);
|
|
3849
|
+
}
|
|
3850
|
+
return filters.value;
|
|
3851
|
+
}
|
|
3852
|
+
if (Array.isArray(filters) && filters.length) {
|
|
3853
|
+
await this.categoryFilterRepository.deleteByCategory(categoryId);
|
|
3854
|
+
let filtersList = [];
|
|
3855
|
+
for (let i = 0; i < filters.length; i++) {
|
|
3856
|
+
const newCategoryFilter = await this.categoryFilterRepository.create({
|
|
3857
|
+
filterId: filters[i].id,
|
|
3858
|
+
categoryId,
|
|
3859
|
+
});
|
|
3860
|
+
filtersList.push(newCategoryFilter);
|
|
3861
|
+
}
|
|
3862
|
+
return filters;
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
3865
|
+
async getChildren(parentId) {
|
|
3866
|
+
const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id'], {
|
|
3867
|
+
args: {
|
|
3868
|
+
type: 'category_tree_args',
|
|
3869
|
+
value: { parentid: parentId },
|
|
3870
|
+
required: true,
|
|
3871
|
+
},
|
|
3872
|
+
});
|
|
3873
|
+
return category_tree.map((category) => Category.toInstance(category));
|
|
3874
|
+
}
|
|
3875
|
+
async isChild(id, parentId) {
|
|
3876
|
+
const categoryTree = await this.getChildren(parentId);
|
|
3877
|
+
return categoryTree.some((c) => c.id == id.toString());
|
|
3878
|
+
}
|
|
3879
|
+
}
|
|
3880
|
+
|
|
3881
|
+
class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
3882
|
+
constructor({ endpoint, authOptions, interceptors, }, filterOptionRepository, categoryFilterRepository) {
|
|
3883
|
+
super({
|
|
3884
|
+
tableName: 'filter',
|
|
3885
|
+
model: Filter,
|
|
3886
|
+
endpoint,
|
|
3887
|
+
authOptions,
|
|
3888
|
+
interceptors,
|
|
3889
|
+
fields: [
|
|
3890
|
+
'id',
|
|
3891
|
+
'description',
|
|
3892
|
+
'slug',
|
|
3893
|
+
'enabled',
|
|
3894
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
3895
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
3896
|
+
{
|
|
3897
|
+
options: {
|
|
3898
|
+
columnName: 'options',
|
|
3899
|
+
foreignKeyColumn: { filterId: 'id' },
|
|
3900
|
+
fields: [
|
|
3901
|
+
'id',
|
|
3902
|
+
{ filterId: { columnName: 'filter_id' } },
|
|
3903
|
+
'description',
|
|
3904
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
3905
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
3906
|
+
],
|
|
3907
|
+
},
|
|
3908
|
+
},
|
|
3909
|
+
],
|
|
3910
|
+
});
|
|
3911
|
+
this.filterOptionRepository = filterOptionRepository;
|
|
3912
|
+
this.categoryFilterRepository = categoryFilterRepository;
|
|
3913
|
+
}
|
|
3914
|
+
async update(params) {
|
|
3915
|
+
const { options, ...data } = params;
|
|
3916
|
+
const filter = await super.update(data);
|
|
3917
|
+
filter.options = await this.updateOptions(+data.id, { options });
|
|
3918
|
+
return filter;
|
|
3919
|
+
}
|
|
3920
|
+
async updateOptions(filterId, { options }) {
|
|
3921
|
+
if (!options)
|
|
3922
|
+
return [];
|
|
3923
|
+
if ('action' in options && options.action === 'remove' && options.value.length) {
|
|
3924
|
+
for (let i = 0; i < options.value.length; i++) {
|
|
3925
|
+
await this.filterOptionRepository.delete({ id: options.value[i].id });
|
|
3926
|
+
}
|
|
3927
|
+
return [];
|
|
3928
|
+
}
|
|
3929
|
+
if ('action' in options && options.action === 'merge' && options.value.length) {
|
|
3930
|
+
let filterOptions = [];
|
|
3931
|
+
for (let i = 0; i < options.value.length; i++) {
|
|
3932
|
+
try {
|
|
3933
|
+
const hasFilter = await this.filterOptionRepository.get({ id: options.value[i].id });
|
|
3934
|
+
if (hasFilter)
|
|
3935
|
+
filterOptions.push(hasFilter);
|
|
3936
|
+
}
|
|
3937
|
+
catch (error) {
|
|
3938
|
+
const newOption = await this.filterOptionRepository.create({ ...options.value[i], filterId });
|
|
3939
|
+
filterOptions.push(newOption);
|
|
3940
|
+
}
|
|
3941
|
+
}
|
|
3942
|
+
return filterOptions;
|
|
3943
|
+
}
|
|
3944
|
+
if (Array.isArray(options) && options.length) {
|
|
3945
|
+
let filterOptions = [];
|
|
3946
|
+
for (let i = 0; i < options.length; i++) {
|
|
3947
|
+
try {
|
|
3948
|
+
const hasFilter = await this.filterOptionRepository.get({ id: options[i].id });
|
|
3949
|
+
if (hasFilter)
|
|
3950
|
+
filterOptions.push(hasFilter);
|
|
3951
|
+
}
|
|
3952
|
+
catch (error) {
|
|
3953
|
+
const newOption = await this.filterOptionRepository.create({ ...options[i], filterId });
|
|
3954
|
+
filterOptions.push(newOption);
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
3957
|
+
}
|
|
3958
|
+
return [];
|
|
3959
|
+
}
|
|
3960
|
+
async delete(params) {
|
|
3961
|
+
const { data: categoryFilters } = await this.categoryFilterRepository.find({
|
|
3962
|
+
filters: {
|
|
3963
|
+
filterId: params.id,
|
|
3964
|
+
},
|
|
3965
|
+
});
|
|
3966
|
+
if (categoryFilters.length)
|
|
3967
|
+
throw new Error('Erro: o filtro está associado a uma ou mais categoria(s)');
|
|
3968
|
+
await this.deleteOptions(+params.id);
|
|
3969
|
+
await super.delete({ id: +params.id });
|
|
3970
|
+
return;
|
|
3971
|
+
}
|
|
3972
|
+
async deleteOptions(filterId) {
|
|
3973
|
+
await this.mutation('delete_filter_option', ['affected_rows'], {
|
|
3974
|
+
where: {
|
|
3975
|
+
type: 'filter_option_bool_exp',
|
|
3976
|
+
required: true,
|
|
3977
|
+
value: { filter_id: { _eq: filterId } },
|
|
3978
|
+
},
|
|
3979
|
+
});
|
|
3980
|
+
}
|
|
3981
|
+
}
|
|
3982
|
+
|
|
3983
|
+
class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
3984
|
+
constructor({ endpoint, authOptions, interceptors, }) {
|
|
3985
|
+
super({
|
|
3986
|
+
tableName: 'filter_option',
|
|
3987
|
+
model: FilterOption,
|
|
3988
|
+
endpoint,
|
|
3989
|
+
authOptions,
|
|
3990
|
+
interceptors,
|
|
3991
|
+
fields: [
|
|
3992
|
+
'id',
|
|
3993
|
+
'description',
|
|
3994
|
+
{ filterId: { columnName: 'filter_id' } },
|
|
3995
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
3996
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
3997
|
+
],
|
|
3998
|
+
});
|
|
3999
|
+
}
|
|
2742
4000
|
}
|
|
2743
4001
|
|
|
2744
4002
|
class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
2745
|
-
constructor(endpoint, authOptions) {
|
|
4003
|
+
constructor({ endpoint, authOptions, interceptors, }) {
|
|
2746
4004
|
super({
|
|
2747
4005
|
tableName: 'product',
|
|
2748
4006
|
model: ProductHasuraGraphQL,
|
|
2749
4007
|
endpoint,
|
|
2750
4008
|
authOptions,
|
|
4009
|
+
interceptors,
|
|
2751
4010
|
fields: [],
|
|
2752
4011
|
});
|
|
2753
4012
|
this.bindReviewToModel = (plain) => ({
|
|
@@ -2780,9 +4039,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2780
4039
|
whoMustUse: data.who_must_use,
|
|
2781
4040
|
howToUse: data.how_to_use,
|
|
2782
4041
|
brand: data.brand_description,
|
|
4042
|
+
ingredients: data.ingredients,
|
|
2783
4043
|
}),
|
|
2784
|
-
bindFindFilter: (
|
|
2785
|
-
const filters = Object.values(sentence).shift();
|
|
4044
|
+
bindFindFilter: (filters) => {
|
|
2786
4045
|
return {
|
|
2787
4046
|
...(filters?.description && { description: filters.description }),
|
|
2788
4047
|
...(filters.differentials && { differentials: filters.differentials }),
|
|
@@ -2795,6 +4054,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2795
4054
|
...(filters.brand && {
|
|
2796
4055
|
brand_description: filters.brand,
|
|
2797
4056
|
}),
|
|
4057
|
+
...(filters.ingredients && {
|
|
4058
|
+
ingredients: filters.ingredients,
|
|
4059
|
+
}),
|
|
2798
4060
|
};
|
|
2799
4061
|
},
|
|
2800
4062
|
bindPersistData: (descriptionData) => ({
|
|
@@ -2805,6 +4067,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2805
4067
|
}),
|
|
2806
4068
|
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
2807
4069
|
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
4070
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
2808
4071
|
}),
|
|
2809
4072
|
},
|
|
2810
4073
|
},
|
|
@@ -2812,6 +4075,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2812
4075
|
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
2813
4076
|
{ howToUse: { columnName: 'how_to_use' } },
|
|
2814
4077
|
{ brandDescription: { columnName: 'brand_description' } },
|
|
4078
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
2815
4079
|
{ hasVariants: { columnName: 'has_variants' } },
|
|
2816
4080
|
{
|
|
2817
4081
|
images: {
|
|
@@ -2835,8 +4099,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2835
4099
|
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
2836
4100
|
subscriberPrice: data.subscriber_price,
|
|
2837
4101
|
}),
|
|
2838
|
-
bindFindFilter: (
|
|
2839
|
-
const filters = Object.values(sentence).shift();
|
|
4102
|
+
bindFindFilter: (filters) => {
|
|
2840
4103
|
return {
|
|
2841
4104
|
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
2842
4105
|
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
@@ -2870,27 +4133,29 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2870
4133
|
to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
|
|
2871
4134
|
},
|
|
2872
4135
|
},
|
|
4136
|
+
{ hasStock: { columnName: 'has_stock' } },
|
|
2873
4137
|
'slug',
|
|
2874
4138
|
'type',
|
|
2875
4139
|
'video',
|
|
2876
4140
|
'weight',
|
|
2877
4141
|
'gender',
|
|
4142
|
+
{ intGender: { columnName: 'int_gender' } },
|
|
2878
4143
|
{ tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
4144
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
2879
4145
|
{ isKit: { columnName: 'is_kit' } },
|
|
2880
4146
|
{ createdAt: { columnName: 'created_at' } },
|
|
2881
4147
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
4148
|
+
{ rate: { columnName: 'rating' } },
|
|
4149
|
+
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
4150
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
4151
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
2882
4152
|
{
|
|
2883
|
-
|
|
2884
|
-
columnName: '
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
filterType: 'product_review_bool_exp',
|
|
2888
|
-
},
|
|
2889
|
-
fields: [{ aggregate: [{ avg: ['rate'] }] }],
|
|
2890
|
-
from: (value) => value.aggregate.avg.rate,
|
|
4153
|
+
category: {
|
|
4154
|
+
columnName: 'category',
|
|
4155
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
4156
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
2891
4157
|
},
|
|
2892
4158
|
},
|
|
2893
|
-
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
2894
4159
|
];
|
|
2895
4160
|
this.fields = [
|
|
2896
4161
|
...commonFields,
|
|
@@ -2967,7 +4232,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2967
4232
|
}
|
|
2968
4233
|
async get(identifiers) {
|
|
2969
4234
|
const product = Number.isNaN(+identifiers.id)
|
|
2970
|
-
? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
|
|
4235
|
+
? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })).data?.[0]
|
|
2971
4236
|
: await super.get(identifiers);
|
|
2972
4237
|
if (product.productId)
|
|
2973
4238
|
throw new NotFoundError('Product not found, it is a variant');
|
|
@@ -2980,10 +4245,25 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2980
4245
|
this.fields
|
|
2981
4246
|
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
2982
4247
|
.filter((field) => field !== 'reviews');
|
|
4248
|
+
if (options.options?.minimal?.includes('price'))
|
|
4249
|
+
options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
4250
|
+
if (options.options?.maximum?.includes('price'))
|
|
4251
|
+
options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
4252
|
+
options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
|
|
4253
|
+
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
2983
4254
|
return super.find({
|
|
2984
4255
|
...options,
|
|
2985
4256
|
filters: { ...filters, productId: { operator: Where.ISNULL } },
|
|
2986
|
-
fields:
|
|
4257
|
+
fields: [
|
|
4258
|
+
...bindFields,
|
|
4259
|
+
...(bindFields.includes('price')
|
|
4260
|
+
? [
|
|
4261
|
+
'subscriberPrice',
|
|
4262
|
+
'subscriberDiscountPercentage',
|
|
4263
|
+
'fullPrice',
|
|
4264
|
+
]
|
|
4265
|
+
: []),
|
|
4266
|
+
],
|
|
2987
4267
|
});
|
|
2988
4268
|
}
|
|
2989
4269
|
async getBySlug(slug) {
|
|
@@ -2991,9 +4271,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2991
4271
|
filters: {
|
|
2992
4272
|
slug,
|
|
2993
4273
|
},
|
|
4274
|
+
fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
|
|
4275
|
+
options: {
|
|
4276
|
+
enableCount: false,
|
|
4277
|
+
},
|
|
2994
4278
|
});
|
|
2995
4279
|
const product = result?.data?.shift();
|
|
2996
|
-
|
|
4280
|
+
RoundProductPricesHelper.roundProductPrices(product);
|
|
2997
4281
|
return product;
|
|
2998
4282
|
}
|
|
2999
4283
|
async update(params) {
|
|
@@ -3030,6 +4314,17 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
3030
4314
|
})),
|
|
3031
4315
|
], []);
|
|
3032
4316
|
}
|
|
4317
|
+
async findCatalog(params, mainGender) {
|
|
4318
|
+
return this.find({
|
|
4319
|
+
...params,
|
|
4320
|
+
filters: { ...params.filters, published: true },
|
|
4321
|
+
orderBy: {
|
|
4322
|
+
hasStock: 'desc',
|
|
4323
|
+
...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
|
|
4324
|
+
...omit(params.orderBy, ['hasStock', 'intGender']),
|
|
4325
|
+
},
|
|
4326
|
+
});
|
|
4327
|
+
}
|
|
3033
4328
|
async updateCategories(productId, { categories }) {
|
|
3034
4329
|
if ('action' in categories && categories.action === 'remove') {
|
|
3035
4330
|
await this.mutation('delete_category_product', ['affected_rows'], {
|
|
@@ -3143,7 +4438,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
3143
4438
|
async getId(id) {
|
|
3144
4439
|
if (!Number.isNaN(+id))
|
|
3145
4440
|
return id;
|
|
3146
|
-
const { data } = await this.find({ filters: { firestoreId: id } });
|
|
4441
|
+
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
3147
4442
|
if (data?.[0]?.id)
|
|
3148
4443
|
return data?.[0]?.id;
|
|
3149
4444
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
@@ -3199,15 +4494,29 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
3199
4494
|
});
|
|
3200
4495
|
return data && data[0] && this.bindReviewToModel(data[0]);
|
|
3201
4496
|
}
|
|
4497
|
+
async cleanShoppingCountFromIds(ids) {
|
|
4498
|
+
return await this.mutation('update_product', ['affected_rows'], {
|
|
4499
|
+
where: {
|
|
4500
|
+
value: { id: { _nin: ids } },
|
|
4501
|
+
type: 'product_bool_exp',
|
|
4502
|
+
required: true,
|
|
4503
|
+
},
|
|
4504
|
+
_set: {
|
|
4505
|
+
value: { shopping_count: 0 },
|
|
4506
|
+
type: 'product_set_input',
|
|
4507
|
+
},
|
|
4508
|
+
});
|
|
4509
|
+
}
|
|
3202
4510
|
}
|
|
3203
4511
|
|
|
3204
4512
|
class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
3205
|
-
constructor(endpoint, authOptions) {
|
|
4513
|
+
constructor({ endpoint, authOptions, interceptors, }) {
|
|
3206
4514
|
super({
|
|
3207
4515
|
tableName: 'product',
|
|
3208
4516
|
model: VariantHasuraGraphQL,
|
|
3209
4517
|
endpoint,
|
|
3210
4518
|
authOptions,
|
|
4519
|
+
interceptors,
|
|
3211
4520
|
fields: [
|
|
3212
4521
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
3213
4522
|
{ firestoreId: { columnName: 'firestore_id' } },
|
|
@@ -3243,12 +4552,12 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
3243
4552
|
};
|
|
3244
4553
|
},
|
|
3245
4554
|
bindPersistData: (priceData) => ({
|
|
3246
|
-
...(priceData?.price >= 0 && { price: priceData.price }),
|
|
3247
|
-
...(priceData
|
|
3248
|
-
...(priceData
|
|
4555
|
+
...((priceData?.price || 0) >= 0 && { price: priceData.price }),
|
|
4556
|
+
...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
|
|
4557
|
+
...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
|
|
3249
4558
|
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
3250
4559
|
}),
|
|
3251
|
-
...(priceData
|
|
4560
|
+
...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
3252
4561
|
}),
|
|
3253
4562
|
},
|
|
3254
4563
|
},
|
|
@@ -3263,6 +4572,7 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
3263
4572
|
to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
|
|
3264
4573
|
},
|
|
3265
4574
|
},
|
|
4575
|
+
{ hasStock: { columnName: 'has_stock' } },
|
|
3266
4576
|
'weight',
|
|
3267
4577
|
{ name: { to: () => '', from: () => undefined } },
|
|
3268
4578
|
{ hasVariants: { columnName: 'has_variants', to: () => false, from: () => undefined } },
|
|
@@ -3300,16 +4610,247 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
3300
4610
|
async getId(id) {
|
|
3301
4611
|
if (!Number.isNaN(+id))
|
|
3302
4612
|
return id;
|
|
3303
|
-
const { data } = await this.find({ filters: { firestoreId: id } });
|
|
4613
|
+
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
3304
4614
|
if (data?.[0]?.id)
|
|
3305
4615
|
return data?.[0]?.id;
|
|
3306
4616
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
3307
4617
|
}
|
|
3308
4618
|
}
|
|
3309
4619
|
|
|
4620
|
+
class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
4621
|
+
constructor({ endpoint, authOptions, interceptors, }, categoryFilterRepository) {
|
|
4622
|
+
super({
|
|
4623
|
+
tableName: 'category',
|
|
4624
|
+
model: Wishlist,
|
|
4625
|
+
endpoint,
|
|
4626
|
+
authOptions,
|
|
4627
|
+
interceptors,
|
|
4628
|
+
fields: [
|
|
4629
|
+
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
4630
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
4631
|
+
'name',
|
|
4632
|
+
'description',
|
|
4633
|
+
'image',
|
|
4634
|
+
'published',
|
|
4635
|
+
'shop',
|
|
4636
|
+
{ shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
|
|
4637
|
+
'slug',
|
|
4638
|
+
{ brandCategory: { columnName: 'brand_category' } },
|
|
4639
|
+
{ brandCategoryBanner: { columnName: 'brand_banner' } },
|
|
4640
|
+
{ brandCategoryBannerMobile: { columnName: 'brand_banner_mobile' } },
|
|
4641
|
+
{ brandLogo: { columnName: 'brand_logo' } },
|
|
4642
|
+
{ brandCondition: { columnName: 'brand_condition' } },
|
|
4643
|
+
{
|
|
4644
|
+
conditions: {
|
|
4645
|
+
columnName: 'tag_condition',
|
|
4646
|
+
type: HasuraGraphQLColumnType.Jsonb,
|
|
4647
|
+
from: (tags, row) => ({ brand: row.brand_condition, tags: Array.isArray(tags) ? tags : [] }),
|
|
4648
|
+
bindPersistData: (value) => {
|
|
4649
|
+
return {
|
|
4650
|
+
brand_condition: value.brand,
|
|
4651
|
+
tag_condition: value?.tags || [],
|
|
4652
|
+
};
|
|
4653
|
+
},
|
|
4654
|
+
bindFindFilter: (sentence) => {
|
|
4655
|
+
return {
|
|
4656
|
+
...(sentence.brand ? { brand_condition: sentence.brand } : {}),
|
|
4657
|
+
...(sentence.tags ? { tag_condition: sentence.tags } : {}),
|
|
4658
|
+
};
|
|
4659
|
+
},
|
|
4660
|
+
},
|
|
4661
|
+
},
|
|
4662
|
+
{
|
|
4663
|
+
filters: {
|
|
4664
|
+
columnName: 'filters',
|
|
4665
|
+
foreignKeyColumn: { filter_id: 'id' },
|
|
4666
|
+
fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
|
|
4667
|
+
bindPersistData: (value) => ({
|
|
4668
|
+
filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
4669
|
+
}),
|
|
4670
|
+
from: (filters) => filters?.map((filter) => filter?.filter) || [],
|
|
4671
|
+
},
|
|
4672
|
+
},
|
|
4673
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
4674
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
4675
|
+
{
|
|
4676
|
+
products: {
|
|
4677
|
+
columnName: 'products',
|
|
4678
|
+
fields: ['product_id'],
|
|
4679
|
+
from: (value) => value.map((product) => product.product_id.toString()),
|
|
4680
|
+
to: (productIds) => productIds.map((productId) => ({
|
|
4681
|
+
product_id: +productId,
|
|
4682
|
+
})),
|
|
4683
|
+
},
|
|
4684
|
+
},
|
|
4685
|
+
{
|
|
4686
|
+
metadata: {
|
|
4687
|
+
columnName: 'metadata',
|
|
4688
|
+
fields: ['title', 'description'],
|
|
4689
|
+
bindPersistData: (value) => ({
|
|
4690
|
+
metadata: { data: value },
|
|
4691
|
+
}),
|
|
4692
|
+
},
|
|
4693
|
+
},
|
|
4694
|
+
{ isCollection: { columnName: 'is_collection' } },
|
|
4695
|
+
{ isWishlist: { columnName: 'is_wishlist' } },
|
|
4696
|
+
'reference',
|
|
4697
|
+
{ parentId: { columnName: 'parent_id' } },
|
|
4698
|
+
{
|
|
4699
|
+
parent: {
|
|
4700
|
+
columnName: 'parent',
|
|
4701
|
+
foreignKeyColumn: { id: 'parentId' },
|
|
4702
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
4703
|
+
},
|
|
4704
|
+
},
|
|
4705
|
+
{ personId: { columnName: 'person_id' } },
|
|
4706
|
+
],
|
|
4707
|
+
});
|
|
4708
|
+
this.categoryFilterRepository = categoryFilterRepository;
|
|
4709
|
+
}
|
|
4710
|
+
async create(params) {
|
|
4711
|
+
const { metadata, ...data } = params;
|
|
4712
|
+
return super.create({
|
|
4713
|
+
...data,
|
|
4714
|
+
isWishlist: true,
|
|
4715
|
+
isCollection: true,
|
|
4716
|
+
brandCategory: false,
|
|
4717
|
+
metadata: metadata || { description: data.description, title: data.name },
|
|
4718
|
+
});
|
|
4719
|
+
}
|
|
4720
|
+
async get(identifiers) {
|
|
4721
|
+
const data = await super.get(identifiers);
|
|
4722
|
+
if (!data.isWishlist)
|
|
4723
|
+
throw new NotFoundError(`Category with id ${identifiers.id} is not a wishlist`);
|
|
4724
|
+
return data;
|
|
4725
|
+
}
|
|
4726
|
+
async update(params) {
|
|
4727
|
+
const { products, id: checkId, metadata, filters, ...data } = params;
|
|
4728
|
+
const plainData = this.paramsToPlain({ id: checkId });
|
|
4729
|
+
const id = plainData.id;
|
|
4730
|
+
const category = await super.update({ id, ...data, isWishlist: true, isCollection: true, brandCategory: false });
|
|
4731
|
+
category.products = products && (await this.updateProducts(+id, { products }));
|
|
4732
|
+
category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
4733
|
+
return category;
|
|
4734
|
+
}
|
|
4735
|
+
async getWishlistBySlug(slug) {
|
|
4736
|
+
if (!slug)
|
|
4737
|
+
return;
|
|
4738
|
+
const { data } = await this.find({
|
|
4739
|
+
filters: {
|
|
4740
|
+
slug,
|
|
4741
|
+
isWishlist: { operator: Where.EQUALS, value: true },
|
|
4742
|
+
},
|
|
4743
|
+
options: {
|
|
4744
|
+
enableCount: false,
|
|
4745
|
+
},
|
|
4746
|
+
});
|
|
4747
|
+
if (!data.length)
|
|
4748
|
+
throw new NotFoundError(`Wishlist with slug ${slug} not found`);
|
|
4749
|
+
if (data.length > 1)
|
|
4750
|
+
throw new DuplicatedResultsError('Query returned duplicated values');
|
|
4751
|
+
return data.shift();
|
|
4752
|
+
}
|
|
4753
|
+
async getWishlistByPerson(personId) {
|
|
4754
|
+
if (!personId)
|
|
4755
|
+
return;
|
|
4756
|
+
const { data } = await this.find({
|
|
4757
|
+
filters: {
|
|
4758
|
+
personId: { operator: Where.EQUALS, value: personId },
|
|
4759
|
+
isWishlist: { operator: Where.EQUALS, value: true },
|
|
4760
|
+
},
|
|
4761
|
+
options: {
|
|
4762
|
+
enableCount: false,
|
|
4763
|
+
},
|
|
4764
|
+
});
|
|
4765
|
+
if (!data.length)
|
|
4766
|
+
throw new NotFoundError(`Wishlists from person ${personId} not found`);
|
|
4767
|
+
return data;
|
|
4768
|
+
}
|
|
4769
|
+
async updateProducts(categoryId, { products }) {
|
|
4770
|
+
if ('action' in products && products.action === 'remove') {
|
|
4771
|
+
await this.mutation('delete_category_product', ['affected_rows'], {
|
|
4772
|
+
where: {
|
|
4773
|
+
type: 'category_product_bool_exp',
|
|
4774
|
+
required: true,
|
|
4775
|
+
value: { category_id: { _eq: categoryId } },
|
|
4776
|
+
},
|
|
4777
|
+
});
|
|
4778
|
+
await this.categoryFilterRepository.deleteByCategory(categoryId);
|
|
4779
|
+
return [];
|
|
4780
|
+
}
|
|
4781
|
+
const plainData = this.paramsToPlain({ products });
|
|
4782
|
+
if (!plainData.products || plainData.products.length <= 0)
|
|
4783
|
+
return [];
|
|
4784
|
+
await this.mutation('delete_category_product', ['affected_rows'], {
|
|
4785
|
+
where: {
|
|
4786
|
+
type: 'category_product_bool_exp',
|
|
4787
|
+
required: true,
|
|
4788
|
+
value: { category_id: { _eq: categoryId } },
|
|
4789
|
+
},
|
|
4790
|
+
});
|
|
4791
|
+
await this.categoryFilterRepository.deleteByCategory(categoryId);
|
|
4792
|
+
await this.mutation('insert_category_product', ['affected_rows'], {
|
|
4793
|
+
objects: {
|
|
4794
|
+
type: '[category_product_insert_input!]',
|
|
4795
|
+
required: true,
|
|
4796
|
+
value: plainData.products.map((productId) => ({ category_id: categoryId, product_id: productId })),
|
|
4797
|
+
},
|
|
4798
|
+
});
|
|
4799
|
+
return plainData.products;
|
|
4800
|
+
}
|
|
4801
|
+
async updateMetadata(categoryId, { metadata }) {
|
|
4802
|
+
const plainData = this.paramsToPlain({ metadata });
|
|
4803
|
+
if (!plainData.metadata)
|
|
4804
|
+
return;
|
|
4805
|
+
await this.mutation('update_category_metadata_by_pk', ['category_id'], {
|
|
4806
|
+
pk_columns: {
|
|
4807
|
+
value: { category_id: categoryId },
|
|
4808
|
+
type: 'category_metadata_pk_columns_input',
|
|
4809
|
+
required: true,
|
|
4810
|
+
},
|
|
4811
|
+
_set: {
|
|
4812
|
+
value: omit(metadata, ['category_id']),
|
|
4813
|
+
type: 'category_metadata_set_input',
|
|
4814
|
+
required: true,
|
|
4815
|
+
},
|
|
4816
|
+
});
|
|
4817
|
+
return plainData.metadata;
|
|
4818
|
+
}
|
|
4819
|
+
getCategoryBySlug(slug, _shop) {
|
|
4820
|
+
return this.getWishlistBySlug(slug);
|
|
4821
|
+
}
|
|
4822
|
+
async getCategoryByShop(shop) {
|
|
4823
|
+
if (!shop)
|
|
4824
|
+
return;
|
|
4825
|
+
const { data } = await this.find({
|
|
4826
|
+
filters: {
|
|
4827
|
+
shops: { operator: Where.IN, value: [shop] },
|
|
4828
|
+
published: { operator: Where.EQUALS, value: true },
|
|
4829
|
+
isWishlist: { operator: Where.EQUALS, value: true },
|
|
4830
|
+
},
|
|
4831
|
+
options: {
|
|
4832
|
+
enableCount: false,
|
|
4833
|
+
},
|
|
4834
|
+
});
|
|
4835
|
+
return data;
|
|
4836
|
+
}
|
|
4837
|
+
getCategoriesForHome(categoryIds, limit, gender) {
|
|
4838
|
+
return;
|
|
4839
|
+
}
|
|
4840
|
+
mountCategory(category, options) {
|
|
4841
|
+
return;
|
|
4842
|
+
}
|
|
4843
|
+
getChildren(parentId) {
|
|
4844
|
+
return;
|
|
4845
|
+
}
|
|
4846
|
+
isChild(id, parentId) {
|
|
4847
|
+
return;
|
|
4848
|
+
}
|
|
4849
|
+
}
|
|
4850
|
+
|
|
3310
4851
|
/**
|
|
3311
4852
|
* Generated bundle index. Do not edit.
|
|
3312
4853
|
*/
|
|
3313
4854
|
|
|
3314
|
-
export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Category, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where,
|
|
4855
|
+
export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
|
|
3315
4856
|
//# sourceMappingURL=infrab4a-connect.mjs.map
|