@infrab4a/connect 4.0.0-beta.50 → 4.0.0-beta.7
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/index.d.ts +0 -1
- package/domain/catalog/models/category.d.ts +22 -5
- package/domain/catalog/models/index.d.ts +0 -5
- package/domain/catalog/models/kit-product.d.ts +4 -4
- package/domain/catalog/models/product.d.ts +35 -5
- package/domain/catalog/models/types/category-filter.type.d.ts +4 -0
- package/domain/catalog/models/types/index.d.ts +1 -2
- package/domain/catalog/models/types/shop-description.type.d.ts +0 -1
- package/domain/catalog/models/variant.d.ts +2 -1
- package/domain/catalog/repositories/category.repository.d.ts +3 -6
- package/domain/catalog/repositories/index.d.ts +0 -5
- package/domain/catalog/repositories/product.repository.d.ts +1 -4
- package/domain/generic/model/base.model.d.ts +5 -9
- package/domain/generic/model/types/base-model-builder.type.d.ts +2 -4
- package/domain/generic/model/types/identifier-model.type.d.ts +5 -6
- package/domain/generic/model/types/model-base-structure.type.d.ts +3 -9
- package/domain/generic/model/types/non-function-property-name.type.d.ts +3 -12
- package/domain/generic/repository/find.repository.d.ts +1 -7
- 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 +1 -11
- 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 +3 -5
- package/domain/shop-settings/models/index.d.ts +0 -1
- package/domain/shop-settings/models/types/index.d.ts +1 -6
- package/domain/shop-settings/repositories/index.d.ts +0 -1
- package/domain/shopping/models/buy-2-win.d.ts +1 -3
- package/domain/shopping/models/checkout.d.ts +6 -5
- package/domain/shopping/models/coupons/coupon.d.ts +6 -34
- package/domain/shopping/models/index.d.ts +4 -5
- package/domain/shopping/models/order.d.ts +0 -1
- package/domain/shopping/models/shipping-method.d.ts +0 -1
- package/domain/shopping/models/subscription/checkout.d.ts +4 -3
- package/domain/shopping/repositories/index.d.ts +2 -4
- package/domain/users/models/lead.d.ts +0 -1
- package/domain/users/models/subscription/subscription.d.ts +3 -3
- package/domain/users/models/user-address.d.ts +2 -1
- package/domain/users/models/user.d.ts +3 -2
- package/esm2020/domain/catalog/index.mjs +1 -2
- package/esm2020/domain/catalog/models/category.mjs +6 -10
- package/esm2020/domain/catalog/models/index.mjs +1 -6
- package/esm2020/domain/catalog/models/kit-product.mjs +7 -7
- package/esm2020/domain/catalog/models/product.mjs +6 -8
- package/esm2020/domain/catalog/models/types/category-filter.type.mjs +2 -0
- package/esm2020/domain/catalog/models/types/index.mjs +2 -3
- package/esm2020/domain/catalog/models/types/shop-description.type.mjs +1 -1
- package/esm2020/domain/catalog/models/variant.mjs +4 -1
- package/esm2020/domain/catalog/repositories/category.repository.mjs +1 -1
- package/esm2020/domain/catalog/repositories/index.mjs +1 -6
- package/esm2020/domain/catalog/repositories/product.repository.mjs +1 -1
- package/esm2020/domain/generic/model/base.model.mjs +2 -3
- 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 +1 -2
- package/esm2020/domain/shop-settings/models/types/index.mjs +2 -7
- package/esm2020/domain/shop-settings/repositories/index.mjs +1 -2
- package/esm2020/domain/shopping/models/buy-2-win.mjs +2 -2
- package/esm2020/domain/shopping/models/checkout.mjs +7 -6
- package/esm2020/domain/shopping/models/coupons/coupon.mjs +16 -16
- package/esm2020/domain/shopping/models/index.mjs +5 -6
- 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/index.mjs +3 -5
- 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 +11 -28
- package/esm2020/infra/elasticsearch/adapters/elastic-search.adapter.mjs +1 -1
- package/esm2020/infra/elasticsearch/indexes/products-index.mjs +51 -63
- 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 +4 -8
- package/esm2020/infra/firebase/firestore/mixins/with-crud-firestore.mixin.mjs +1 -1
- package/esm2020/infra/firebase/firestore/mixins/with-delete-firestore.mixin.mjs +2 -6
- package/esm2020/infra/firebase/firestore/mixins/with-find-firestore.mixin.mjs +8 -11
- package/esm2020/infra/firebase/firestore/mixins/with-firestore.mixin.mjs +4 -27
- package/esm2020/infra/firebase/firestore/mixins/with-get-firestore.mixin.mjs +3 -6
- package/esm2020/infra/firebase/firestore/mixins/with-helpers.mixin.mjs +1 -1
- package/esm2020/infra/firebase/firestore/mixins/with-sub-collection.mixin.mjs +3 -5
- package/esm2020/infra/firebase/firestore/mixins/with-update-firestore.mixin.mjs +4 -7
- package/esm2020/infra/firebase/firestore/repositories/catalog/category-firestore.repository.mjs +8 -21
- package/esm2020/infra/firebase/firestore/repositories/catalog/product-firestore.repository.mjs +7 -15
- package/esm2020/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.mjs +8 -10
- package/esm2020/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.mjs +30 -36
- package/esm2020/infra/firebase/firestore/repositories/shop-settings/index.mjs +1 -2
- package/esm2020/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/shopping/index.mjs +4 -6
- package/esm2020/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.mjs +4 -6
- package/esm2020/infra/firebase/firestore/repositories/shopping/order-firestore.repository.mjs +9 -11
- package/esm2020/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/users/lead-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.mjs +8 -10
- package/esm2020/infra/firebase/firestore/repositories/users/subscription-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.mjs +8 -10
- package/esm2020/infra/firebase/firestore/repositories/users/user-address-firestore.repository.mjs +8 -10
- package/esm2020/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.mjs +8 -10
- package/esm2020/infra/firebase/firestore/repositories/users/user-firestore.repository.mjs +6 -8
- package/esm2020/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.mjs +8 -10
- 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 +3 -4
- 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 +5 -6
- package/esm2020/infra/hasura-graphql/mixins/helpers/filter-option.helper.mjs +1 -1
- package/esm2020/infra/hasura-graphql/mixins/helpers/graphql-field.helper.mjs +25 -36
- package/esm2020/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.mjs +4 -6
- 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 +3 -5
- package/esm2020/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.mjs +20 -126
- package/esm2020/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.mjs +3 -5
- package/esm2020/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.mjs +24 -40
- package/esm2020/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.mjs +5 -7
- 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-hasura-graphql.repository.mjs +14 -131
- package/esm2020/infra/hasura-graphql/repositories/catalog/index.mjs +1 -6
- package/esm2020/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.mjs +20 -70
- package/esm2020/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.mjs +7 -9
- 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/index.mjs +3 -6
- package/fesm2015/infrab4a-connect.mjs +422 -2001
- package/fesm2015/infrab4a-connect.mjs.map +1 -1
- package/fesm2020/infrab4a-connect.mjs +422 -1965
- package/fesm2020/infrab4a-connect.mjs.map +1 -1
- package/infra/elasticsearch/adapters/axios.adapter.d.ts +5 -7
- package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +2 -3
- package/infra/elasticsearch/indexes/products-index.d.ts +10 -8
- package/infra/elasticsearch/types/elastic-search-result.d.ts +0 -2
- package/infra/firebase/firestore/mixins/with-create-firestore.mixin.d.ts +2 -2
- package/infra/firebase/firestore/mixins/with-crud-firestore.mixin.d.ts +1 -2
- 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 +4 -13
- 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 +4 -8
- package/infra/firebase/firestore/mixins/with-update-firestore.mixin.d.ts +3 -3
- package/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +5 -8
- package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +5 -6
- package/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +4 -4
- package/infra/firebase/firestore/repositories/shop-settings/index.d.ts +0 -1
- package/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +4 -4
- package/infra/firebase/firestore/repositories/shopping/index.d.ts +3 -5
- package/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +4 -4
- package/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +4 -3
- package/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +4 -3
- 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 +4 -3
- 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 +1 -3
- package/infra/firebase/firestore/types/index.d.ts +2 -3
- package/infra/hasura-graphql/mixins/helpers/attribute-option.helper.d.ts +3 -9
- 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 +2 -4
- package/infra/hasura-graphql/mixins/helpers/graphql-field.helper.d.ts +5 -9
- package/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.d.ts +1 -2
- 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 +15 -24
- package/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.d.ts +6 -7
- package/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.d.ts +3 -15
- package/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.d.ts +2 -2
- package/infra/hasura-graphql/models/product-hasura-graphql.d.ts +0 -4
- package/infra/hasura-graphql/models/variant-hasura-graphql.d.ts +0 -1
- package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +5 -12
- package/infra/hasura-graphql/repositories/catalog/index.d.ts +0 -5
- package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +4 -6
- package/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +4 -4
- package/infra/hasura-graphql/types/graphql.repository.type.d.ts +6 -9
- package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +3 -7
- package/package.json +1 -2
- package/utils/index.d.ts +2 -5
- package/domain/catalog/helpers/index.d.ts +0 -1
- package/domain/catalog/helpers/round-product-price.helper.d.ts +0 -4
- package/domain/catalog/models/category-base.d.ts +0 -30
- package/domain/catalog/models/category-collection-children.d.ts +0 -13
- package/domain/catalog/models/category-filter.d.ts +0 -13
- package/domain/catalog/models/category-for-product.d.ts +0 -5
- package/domain/catalog/models/filter-option.d.ts +0 -9
- package/domain/catalog/models/filter.d.ts +0 -12
- package/domain/catalog/models/product-base.d.ts +0 -40
- package/domain/catalog/models/product-for-category.d.ts +0 -7
- package/domain/catalog/models/product-for-kit.d.ts +0 -7
- package/domain/catalog/models/types/category-product.d.ts +0 -4
- package/domain/catalog/models/types/product-evaluation.type.d.ts +0 -6
- package/domain/catalog/models/wishlist.d.ts +0 -6
- package/domain/catalog/repositories/category-collection-children.repository.d.ts +0 -4
- package/domain/catalog/repositories/category-filter.repository.d.ts +0 -6
- package/domain/catalog/repositories/filter-option.repository.d.ts +0 -4
- package/domain/catalog/repositories/filter.repository.d.ts +0 -4
- package/domain/catalog/repositories/wishlist.repository.d.ts +0 -6
- package/domain/shop-settings/models/shop-settings.d.ts +0 -9
- package/domain/shop-settings/models/types/shop-banner.type.d.ts +0 -12
- package/domain/shop-settings/models/types/shop-brands.type.d.ts +0 -10
- package/domain/shop-settings/models/types/shop-carousel.type.d.ts +0 -5
- package/domain/shop-settings/models/types/shop-collection.type.d.ts +0 -9
- package/domain/shop-settings/models/types/shop-section.type.d.ts +0 -9
- package/domain/shop-settings/repositories/shop-settings.repository.d.ts +0 -4
- package/domain/shopping/models/campaign-dashboard.d.ts +0 -15
- package/domain/shopping/models/campaign-hashtag.d.ts +0 -18
- package/domain/shopping/repositories/campaign-dashboard.repository.d.ts +0 -4
- package/domain/shopping/repositories/campaign-hashtag.repository.d.ts +0 -4
- package/esm2020/domain/catalog/helpers/index.mjs +0 -2
- package/esm2020/domain/catalog/helpers/round-product-price.helper.mjs +0 -15
- package/esm2020/domain/catalog/models/category-base.mjs +0 -18
- package/esm2020/domain/catalog/models/category-collection-children.mjs +0 -13
- package/esm2020/domain/catalog/models/category-filter.mjs +0 -19
- package/esm2020/domain/catalog/models/category-for-product.mjs +0 -7
- package/esm2020/domain/catalog/models/filter-option.mjs +0 -7
- package/esm2020/domain/catalog/models/filter.mjs +0 -7
- package/esm2020/domain/catalog/models/product-base.mjs +0 -25
- package/esm2020/domain/catalog/models/product-for-category.mjs +0 -14
- package/esm2020/domain/catalog/models/product-for-kit.mjs +0 -14
- package/esm2020/domain/catalog/models/types/category-product.mjs +0 -2
- package/esm2020/domain/catalog/models/types/product-evaluation.type.mjs +0 -2
- package/esm2020/domain/catalog/models/wishlist.mjs +0 -7
- package/esm2020/domain/catalog/repositories/category-collection-children.repository.mjs +0 -2
- package/esm2020/domain/catalog/repositories/category-filter.repository.mjs +0 -2
- package/esm2020/domain/catalog/repositories/filter-option.repository.mjs +0 -2
- package/esm2020/domain/catalog/repositories/filter.repository.mjs +0 -2
- package/esm2020/domain/catalog/repositories/wishlist.repository.mjs +0 -2
- package/esm2020/domain/shop-settings/models/shop-settings.mjs +0 -7
- package/esm2020/domain/shop-settings/models/types/shop-banner.type.mjs +0 -2
- package/esm2020/domain/shop-settings/models/types/shop-brands.type.mjs +0 -2
- package/esm2020/domain/shop-settings/models/types/shop-carousel.type.mjs +0 -2
- package/esm2020/domain/shop-settings/models/types/shop-collection.type.mjs +0 -2
- package/esm2020/domain/shop-settings/models/types/shop-section.type.mjs +0 -2
- package/esm2020/domain/shop-settings/repositories/shop-settings.repository.mjs +0 -2
- package/esm2020/domain/shopping/models/campaign-dashboard.mjs +0 -7
- package/esm2020/domain/shopping/models/campaign-hashtag.mjs +0 -7
- package/esm2020/domain/shopping/repositories/campaign-dashboard.repository.mjs +0 -2
- package/esm2020/domain/shopping/repositories/campaign-hashtag.repository.mjs +0 -2
- package/esm2020/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.mjs +0 -14
- package/esm2020/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.mjs +0 -14
- package/esm2020/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.mjs +0 -14
- package/esm2020/infra/firebase/firestore/types/firestore-interceptors.type.mjs +0 -2
- package/esm2020/infra/hasura-graphql/repositories/catalog/category-collection-children-hasura-graphql.repository.mjs +0 -39
- package/esm2020/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.mjs +0 -107
- package/esm2020/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.mjs +0 -105
- package/esm2020/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.mjs +0 -22
- package/esm2020/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.mjs +0 -236
- package/esm2020/utils/decorators/debug.class.decorator.mjs +0 -7
- package/esm2020/utils/decorators/index.mjs +0 -3
- package/esm2020/utils/decorators/trace.method.decorator.mjs +0 -81
- package/esm2020/utils/helpers/class-name.helper.mjs +0 -15
- package/esm2020/utils/helpers/debug-decorator.helper.mjs +0 -18
- package/esm2020/utils/helpers/debug.helper.mjs +0 -150
- package/esm2020/utils/helpers/index.mjs +0 -5
- package/esm2020/utils/helpers/reflect.helper.mjs +0 -165
- package/esm2020/utils/log.utils.mjs +0 -9
- package/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.d.ts +0 -7
- package/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +0 -8
- package/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.d.ts +0 -8
- package/infra/firebase/firestore/types/firestore-interceptors.type.d.ts +0 -14
- package/infra/hasura-graphql/repositories/catalog/category-collection-children-hasura-graphql.repository.d.ts +0 -10
- package/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.d.ts +0 -12
- package/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.d.ts +0 -18
- package/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.d.ts +0 -10
- package/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +0 -27
- package/utils/decorators/debug.class.decorator.d.ts +0 -2
- package/utils/decorators/index.d.ts +0 -2
- package/utils/decorators/trace.method.decorator.d.ts +0 -14
- package/utils/helpers/class-name.helper.d.ts +0 -3
- package/utils/helpers/debug-decorator.helper.d.ts +0 -9
- package/utils/helpers/debug.helper.d.ts +0 -60
- package/utils/helpers/index.d.ts +0 -4
- package/utils/helpers/reflect.helper.d.ts +0 -50
- package/utils/log.utils.d.ts +0 -7
|
@@ -3,21 +3,19 @@ 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
|
-
export { chunk,
|
|
8
|
-
import { Subject } from 'rxjs';
|
|
9
|
-
import { debug } from 'debug';
|
|
6
|
+
import { get as get$1, isString, isNil, isNumber, isDate, set, isObject, isEmpty, chunk, isBoolean, isInteger, isNaN as isNaN$1, omit } from 'lodash';
|
|
7
|
+
export { chunk, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set } from 'lodash';
|
|
10
8
|
import { CustomError } from 'ts-custom-error';
|
|
11
9
|
import axios from 'axios';
|
|
12
10
|
import { collection, getDoc, doc, where, orderBy, getDocs, query, startAfter, startAt, limit, addDoc, setDoc, deleteField, arrayUnion, arrayRemove, deleteDoc, Timestamp } from 'firebase/firestore';
|
|
13
11
|
import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, signInAnonymously, sendPasswordResetEmail, createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth';
|
|
14
12
|
import { mutation, query as query$1 } from 'gql-query-builder';
|
|
13
|
+
import fetch from 'node-fetch';
|
|
15
14
|
|
|
16
15
|
class BaseModel {
|
|
17
16
|
get identifier() {
|
|
18
17
|
const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
|
|
19
|
-
|
|
20
|
-
return fields.reduce((object, field) => ({ ...object, [field]: data[field] }), {});
|
|
18
|
+
return fields.reduce((object, field) => ({ ...object, [field]: this[field] }), {});
|
|
21
19
|
}
|
|
22
20
|
get identifiersFields() {
|
|
23
21
|
return this.constructor.identifiersFields;
|
|
@@ -463,437 +461,11 @@ __decorate([
|
|
|
463
461
|
__metadata("design:type", Payment)
|
|
464
462
|
], SubscriptionPayment.prototype, "payment", void 0);
|
|
465
463
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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;
|
|
633
|
-
}
|
|
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(' ');
|
|
464
|
+
class Address extends BaseModel {
|
|
465
|
+
static get identifiersFields() {
|
|
466
|
+
return ['id'];
|
|
806
467
|
}
|
|
807
468
|
}
|
|
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
|
-
};
|
|
897
469
|
|
|
898
470
|
const get = (object, path, defaultValue) => get$1(object, path, defaultValue);
|
|
899
471
|
|
|
@@ -965,28 +537,26 @@ class Coupon extends BaseModel {
|
|
|
965
537
|
static createCoupon(userId) {
|
|
966
538
|
return this.toInstance({
|
|
967
539
|
nickname: `${Date.now()}`,
|
|
540
|
+
type: CouponTypes.ABSOLUTE,
|
|
968
541
|
checkoutType: CheckoutTypes.ECOMMERCE,
|
|
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
|
-
},
|
|
542
|
+
discount: 30,
|
|
983
543
|
user: userId,
|
|
544
|
+
useLimit: 1,
|
|
545
|
+
useLimitPerUser: true,
|
|
984
546
|
createdAt: new Date(Date.now()),
|
|
985
547
|
beginAt: new Date(Date.now()),
|
|
986
548
|
expiresIn: new Date(Date.now() + COUPON_EXPIRATION),
|
|
987
549
|
});
|
|
988
550
|
}
|
|
989
551
|
}
|
|
552
|
+
__decorate([
|
|
553
|
+
Expose({ name: 'checkout_type' }),
|
|
554
|
+
__metadata("design:type", Number)
|
|
555
|
+
], Coupon.prototype, "checkoutType", void 0);
|
|
556
|
+
__decorate([
|
|
557
|
+
Expose({ name: 'exclusivity_type' }),
|
|
558
|
+
__metadata("design:type", Number)
|
|
559
|
+
], Coupon.prototype, "exclusivityType", void 0);
|
|
990
560
|
|
|
991
561
|
class SubscriptionPlan extends BaseModel {
|
|
992
562
|
static get identifiersFields() {
|
|
@@ -1026,18 +596,6 @@ __decorate([
|
|
|
1026
596
|
__metadata("design:type", BeautyProfile)
|
|
1027
597
|
], User.prototype, "beautyProfile", void 0);
|
|
1028
598
|
|
|
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
|
-
|
|
1041
599
|
class Subscription extends BaseModel {
|
|
1042
600
|
static get identifiersFields() {
|
|
1043
601
|
return ['id'];
|
|
@@ -1052,12 +610,12 @@ __decorate([
|
|
|
1052
610
|
__metadata("design:type", SubscriptionPlan)
|
|
1053
611
|
], Subscription.prototype, "subscriptionPlan", void 0);
|
|
1054
612
|
__decorate([
|
|
1055
|
-
Type(() =>
|
|
1056
|
-
__metadata("design:type",
|
|
613
|
+
Type(() => Address),
|
|
614
|
+
__metadata("design:type", Address)
|
|
1057
615
|
], Subscription.prototype, "shippingAddress", void 0);
|
|
1058
616
|
__decorate([
|
|
1059
|
-
Type(() =>
|
|
1060
|
-
__metadata("design:type",
|
|
617
|
+
Type(() => Address),
|
|
618
|
+
__metadata("design:type", Address)
|
|
1061
619
|
], Subscription.prototype, "billingAddress", void 0);
|
|
1062
620
|
__decorate([
|
|
1063
621
|
Type(() => Coupon),
|
|
@@ -1072,6 +630,12 @@ __decorate([
|
|
|
1072
630
|
__metadata("design:type", Array)
|
|
1073
631
|
], Subscription.prototype, "payment", void 0);
|
|
1074
632
|
|
|
633
|
+
class UserAddress extends Address {
|
|
634
|
+
static get identifiersFields() {
|
|
635
|
+
return ['id', 'userId'];
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
1075
639
|
class UserPaymentMethod extends BaseModel {
|
|
1076
640
|
static get identifiersFields() {
|
|
1077
641
|
return ['id', 'userId'];
|
|
@@ -1103,7 +667,7 @@ class Authentication {
|
|
|
1103
667
|
async signIn({ email, password }, signInMethod) {
|
|
1104
668
|
const method = this.getServiceByMethod(signInMethod);
|
|
1105
669
|
const userAuth = await this.authService[method]({ email, password });
|
|
1106
|
-
const user = this.userRepository.get(
|
|
670
|
+
const user = this.userRepository.get(userAuth);
|
|
1107
671
|
if (!isNil(user))
|
|
1108
672
|
return user;
|
|
1109
673
|
if (/^.+@b4a.com.br$/.test(userAuth.email))
|
|
@@ -1196,123 +760,14 @@ class RecoveryPassword {
|
|
|
1196
760
|
}
|
|
1197
761
|
}
|
|
1198
762
|
|
|
1199
|
-
class
|
|
1200
|
-
|
|
763
|
+
class Category extends BaseModel {
|
|
764
|
+
identifierFields() {
|
|
1201
765
|
return ['id'];
|
|
1202
766
|
}
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
class CategoryBase extends BaseModel {
|
|
1206
767
|
static get identifiersFields() {
|
|
1207
768
|
return ['id'];
|
|
1208
769
|
}
|
|
1209
770
|
}
|
|
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() {
|
|
1275
|
-
return ['id'];
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
__decorate([
|
|
1279
|
-
Type(() => KitProduct),
|
|
1280
|
-
__metadata("design:type", Array)
|
|
1281
|
-
], ProductForCategory.prototype, "kitProducts", void 0);
|
|
1282
|
-
|
|
1283
|
-
class Category extends CategoryBase {
|
|
1284
|
-
static get identifiersFields() {
|
|
1285
|
-
return ['id'];
|
|
1286
|
-
}
|
|
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);
|
|
1316
771
|
|
|
1317
772
|
var GenderDestination;
|
|
1318
773
|
(function (GenderDestination) {
|
|
@@ -1329,60 +784,54 @@ var Shops;
|
|
|
1329
784
|
Shops["ALL"] = "ALL";
|
|
1330
785
|
})(Shops || (Shops = {}));
|
|
1331
786
|
|
|
1332
|
-
class
|
|
1333
|
-
|
|
787
|
+
class Product extends BaseModel {
|
|
788
|
+
identifierFields() {
|
|
1334
789
|
return ['id'];
|
|
1335
790
|
}
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
class Product extends ProductBase {
|
|
1339
791
|
static get identifiersFields() {
|
|
1340
792
|
return ['id'];
|
|
1341
793
|
}
|
|
1342
794
|
}
|
|
1343
|
-
__decorate([
|
|
1344
|
-
Type(() => CategoryForProduct),
|
|
1345
|
-
__metadata("design:type", CategoryForProduct)
|
|
1346
|
-
], Product.prototype, "category", void 0);
|
|
1347
795
|
__decorate([
|
|
1348
796
|
Type(() => KitProduct),
|
|
1349
797
|
__metadata("design:type", Array)
|
|
1350
798
|
], Product.prototype, "kitProducts", void 0);
|
|
1351
799
|
|
|
1352
|
-
class
|
|
1353
|
-
static get identifiersFields() {
|
|
1354
|
-
return ['id', 'productId'];
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
class Wishlist extends Category {
|
|
1359
|
-
static get identifiersFields() {
|
|
1360
|
-
return ['id'];
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
class Buy2Win extends BaseModel {
|
|
800
|
+
class KitProduct extends BaseModel {
|
|
1365
801
|
static get identifiersFields() {
|
|
1366
|
-
return ['
|
|
802
|
+
return ['productId', 'kitProducId'];
|
|
1367
803
|
}
|
|
1368
804
|
}
|
|
1369
805
|
__decorate([
|
|
1370
|
-
Type(() =>
|
|
1371
|
-
__metadata("design:type",
|
|
1372
|
-
],
|
|
806
|
+
Type(() => Product),
|
|
807
|
+
__metadata("design:type", Product)
|
|
808
|
+
], KitProduct.prototype, "kit", void 0);
|
|
809
|
+
__decorate([
|
|
810
|
+
Type(() => Product),
|
|
811
|
+
__metadata("design:type", Product)
|
|
812
|
+
], KitProduct.prototype, "product", void 0);
|
|
1373
813
|
|
|
1374
|
-
class
|
|
1375
|
-
|
|
814
|
+
class Variant extends BaseModel {
|
|
815
|
+
identifierFields() {
|
|
1376
816
|
return ['id'];
|
|
1377
817
|
}
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
class CampaignHashtag extends BaseModel {
|
|
1381
818
|
static get identifiersFields() {
|
|
1382
|
-
return ['id'];
|
|
819
|
+
return ['id', 'productId'];
|
|
1383
820
|
}
|
|
1384
821
|
}
|
|
1385
822
|
|
|
823
|
+
var OrderStatus;
|
|
824
|
+
(function (OrderStatus) {
|
|
825
|
+
OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
|
|
826
|
+
OrderStatus["EM_PREPARO"] = "Preparando pedido";
|
|
827
|
+
OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
|
|
828
|
+
OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
|
|
829
|
+
OrderStatus["ENVIADO"] = "Enviado";
|
|
830
|
+
OrderStatus["ENTREGUE"] = "Entregue";
|
|
831
|
+
OrderStatus["CANCELADO"] = "Cancelado";
|
|
832
|
+
OrderStatus["CREDIT_CARD"] = "credit_card";
|
|
833
|
+
})(OrderStatus || (OrderStatus = {}));
|
|
834
|
+
|
|
1386
835
|
class LineItem extends Product {
|
|
1387
836
|
}
|
|
1388
837
|
|
|
@@ -1406,12 +855,12 @@ __decorate([
|
|
|
1406
855
|
__metadata("design:type", User)
|
|
1407
856
|
], Checkout.prototype, "user", void 0);
|
|
1408
857
|
__decorate([
|
|
1409
|
-
Type(() =>
|
|
1410
|
-
__metadata("design:type",
|
|
858
|
+
Type(() => Address),
|
|
859
|
+
__metadata("design:type", Address)
|
|
1411
860
|
], Checkout.prototype, "shippingAddress", void 0);
|
|
1412
861
|
__decorate([
|
|
1413
|
-
Type(() =>
|
|
1414
|
-
__metadata("design:type",
|
|
862
|
+
Type(() => Address),
|
|
863
|
+
__metadata("design:type", Address)
|
|
1415
864
|
], Checkout.prototype, "billingAddress", void 0);
|
|
1416
865
|
__decorate([
|
|
1417
866
|
Type(() => ShippingMethod),
|
|
@@ -1422,18 +871,6 @@ __decorate([
|
|
|
1422
871
|
__metadata("design:type", Coupon)
|
|
1423
872
|
], Checkout.prototype, "coupon", void 0);
|
|
1424
873
|
|
|
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
|
-
|
|
1437
874
|
class Order extends Checkout {
|
|
1438
875
|
}
|
|
1439
876
|
__decorate([
|
|
@@ -1447,12 +884,12 @@ class CheckoutSubscription extends BaseModel {
|
|
|
1447
884
|
}
|
|
1448
885
|
}
|
|
1449
886
|
__decorate([
|
|
1450
|
-
Type(() =>
|
|
1451
|
-
__metadata("design:type",
|
|
887
|
+
Type(() => Address),
|
|
888
|
+
__metadata("design:type", Address)
|
|
1452
889
|
], CheckoutSubscription.prototype, "shippingAddress", void 0);
|
|
1453
890
|
__decorate([
|
|
1454
|
-
Type(() =>
|
|
1455
|
-
__metadata("design:type",
|
|
891
|
+
Type(() => Address),
|
|
892
|
+
__metadata("design:type", Address)
|
|
1456
893
|
], CheckoutSubscription.prototype, "billingAddress", void 0);
|
|
1457
894
|
__decorate([
|
|
1458
895
|
Type(() => SubscriptionPlan),
|
|
@@ -1463,19 +900,15 @@ __decorate([
|
|
|
1463
900
|
__metadata("design:type", Coupon)
|
|
1464
901
|
], CheckoutSubscription.prototype, "coupon", void 0);
|
|
1465
902
|
|
|
1466
|
-
class
|
|
1467
|
-
static
|
|
1468
|
-
|
|
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;
|
|
903
|
+
class Buy2Win extends BaseModel {
|
|
904
|
+
static get identifiersFields() {
|
|
905
|
+
return ['id'];
|
|
1477
906
|
}
|
|
1478
907
|
}
|
|
908
|
+
__decorate([
|
|
909
|
+
Type(() => Category),
|
|
910
|
+
__metadata("design:type", Array)
|
|
911
|
+
], Buy2Win.prototype, "categories", void 0);
|
|
1479
912
|
|
|
1480
913
|
var FilterType;
|
|
1481
914
|
(function (FilterType) {
|
|
@@ -1576,12 +1009,6 @@ class ShopMenu extends BaseModel {
|
|
|
1576
1009
|
}
|
|
1577
1010
|
}
|
|
1578
1011
|
|
|
1579
|
-
class ShopSettings extends BaseModel {
|
|
1580
|
-
static get identifiersFields() {
|
|
1581
|
-
return ['id'];
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
1012
|
class InvalidArgumentError extends CustomError {
|
|
1586
1013
|
constructor(message) {
|
|
1587
1014
|
super(message);
|
|
@@ -1612,16 +1039,12 @@ class AxiosAdapter {
|
|
|
1612
1039
|
constructor(config) {
|
|
1613
1040
|
this.config = config;
|
|
1614
1041
|
}
|
|
1615
|
-
async get(index
|
|
1042
|
+
async get(index) {
|
|
1616
1043
|
try {
|
|
1617
1044
|
const { data } = await axios({
|
|
1618
|
-
url: `${this.config.url}/${index}
|
|
1045
|
+
url: `${this.config.url}/${index}`,
|
|
1619
1046
|
method: 'GET',
|
|
1620
|
-
|
|
1621
|
-
headers: {
|
|
1622
|
-
'Content-Type': 'application/json',
|
|
1623
|
-
Authorization: `ApiKey ${this.config.credential}`,
|
|
1624
|
-
},
|
|
1047
|
+
headers: { Authorization: `Basic ${this.config.credential}` },
|
|
1625
1048
|
});
|
|
1626
1049
|
return data._source;
|
|
1627
1050
|
}
|
|
@@ -1633,14 +1056,9 @@ class AxiosAdapter {
|
|
|
1633
1056
|
}
|
|
1634
1057
|
async query(index, query) {
|
|
1635
1058
|
const { data } = await axios({
|
|
1636
|
-
url: `${this.config.url}/${index}
|
|
1059
|
+
url: `${this.config.url}/${index}`,
|
|
1637
1060
|
method: 'POST',
|
|
1638
|
-
|
|
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
|
-
},
|
|
1061
|
+
headers: { Authorization: `Basic ${this.config.credential}` },
|
|
1644
1062
|
data: query,
|
|
1645
1063
|
});
|
|
1646
1064
|
return {
|
|
@@ -1650,25 +1068,17 @@ class AxiosAdapter {
|
|
|
1650
1068
|
}
|
|
1651
1069
|
async save(index, data) {
|
|
1652
1070
|
await axios({
|
|
1653
|
-
url: `${this.config.url}/${index}
|
|
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}`,
|
|
1071
|
+
url: `${this.config.url}/${index}`,
|
|
1662
1072
|
method: 'PUT',
|
|
1663
|
-
headers: { Authorization: `
|
|
1073
|
+
headers: { Authorization: `Basic ${this.config.credential}` },
|
|
1664
1074
|
data,
|
|
1665
1075
|
});
|
|
1666
1076
|
}
|
|
1667
|
-
async delete(index
|
|
1077
|
+
async delete(index) {
|
|
1668
1078
|
await axios({
|
|
1669
|
-
url: `${this.config.url}/${index}
|
|
1079
|
+
url: `${this.config.url}/${index}`,
|
|
1670
1080
|
method: 'DELETE',
|
|
1671
|
-
headers: { Authorization: `
|
|
1081
|
+
headers: { Authorization: `Basic ${this.config.credential}` },
|
|
1672
1082
|
});
|
|
1673
1083
|
}
|
|
1674
1084
|
}
|
|
@@ -1676,16 +1086,13 @@ class AxiosAdapter {
|
|
|
1676
1086
|
class ProductsIndex {
|
|
1677
1087
|
constructor(adapter) {
|
|
1678
1088
|
this.adapter = adapter;
|
|
1679
|
-
this.index = `products`;
|
|
1680
1089
|
}
|
|
1681
|
-
async
|
|
1682
|
-
const data = await this.adapter.get(
|
|
1090
|
+
async get(id) {
|
|
1091
|
+
const data = await this.adapter.get(`products/_doc/${id}`);
|
|
1683
1092
|
return Product.toInstance(data);
|
|
1684
1093
|
}
|
|
1685
|
-
async
|
|
1686
|
-
const size = total || 9;
|
|
1094
|
+
async findById(ids, options) {
|
|
1687
1095
|
const fields = [
|
|
1688
|
-
'EAN',
|
|
1689
1096
|
'brand',
|
|
1690
1097
|
'id',
|
|
1691
1098
|
'images',
|
|
@@ -1696,82 +1103,73 @@ class ProductsIndex {
|
|
|
1696
1103
|
'stock',
|
|
1697
1104
|
'slug',
|
|
1698
1105
|
'reviews',
|
|
1106
|
+
'pricePaid',
|
|
1107
|
+
'isGift',
|
|
1108
|
+
'stock',
|
|
1109
|
+
'weight',
|
|
1110
|
+
'tags',
|
|
1699
1111
|
'hasVariants',
|
|
1700
|
-
'
|
|
1112
|
+
'type',
|
|
1701
1113
|
];
|
|
1702
|
-
const
|
|
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,
|
|
1114
|
+
const { hits } = await this.adapter.query('products/_search', {
|
|
1711
1115
|
_source: fields,
|
|
1712
1116
|
query: {
|
|
1713
1117
|
bool: {
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
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,
|
|
1118
|
+
filter: [
|
|
1119
|
+
{
|
|
1120
|
+
terms: {
|
|
1121
|
+
_id: ids,
|
|
1122
|
+
},
|
|
1730
1123
|
},
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
'name.search': {
|
|
1735
|
-
query: `${searchTerm}`,
|
|
1736
|
-
slop: 10,
|
|
1124
|
+
{
|
|
1125
|
+
term: {
|
|
1126
|
+
published: true,
|
|
1737
1127
|
},
|
|
1738
1128
|
},
|
|
1739
|
-
|
|
1740
|
-
|
|
1129
|
+
...(options?.hasStock
|
|
1130
|
+
? [
|
|
1131
|
+
{
|
|
1132
|
+
range: {
|
|
1133
|
+
'stock.quantity': {
|
|
1134
|
+
gt: 0,
|
|
1135
|
+
},
|
|
1136
|
+
},
|
|
1137
|
+
},
|
|
1138
|
+
]
|
|
1139
|
+
: []),
|
|
1140
|
+
],
|
|
1741
1141
|
},
|
|
1742
1142
|
},
|
|
1143
|
+
...(options?.size ? { size: options?.size } : {}),
|
|
1743
1144
|
});
|
|
1744
|
-
|
|
1745
|
-
.filter((e) => e._source.name !== '')
|
|
1746
|
-
.map((hit) => {
|
|
1747
|
-
RoundProductPricesHelper.roundProductPrices(hit._source);
|
|
1748
|
-
return hit;
|
|
1749
|
-
});
|
|
1750
|
-
return search;
|
|
1145
|
+
return hits.map((hit) => Product.toInstance(hit._source));
|
|
1751
1146
|
}
|
|
1752
1147
|
async save(product) {
|
|
1148
|
+
delete product.createdAt;
|
|
1149
|
+
delete product.updatedAt;
|
|
1150
|
+
delete product.kitProducts;
|
|
1753
1151
|
try {
|
|
1754
|
-
|
|
1755
|
-
|
|
1152
|
+
if (!product.firestoreId)
|
|
1153
|
+
throw new Error('Is not a product from firestore');
|
|
1154
|
+
await this.get(product.firestoreId);
|
|
1155
|
+
await this.adapter.save(`products/_doc/${product.firestoreId}`, product.toPlain());
|
|
1756
1156
|
}
|
|
1757
1157
|
catch (error) {
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
try {
|
|
1763
|
-
await this.adapter.update(this.index, product.id, product);
|
|
1764
|
-
}
|
|
1765
|
-
catch (error) {
|
|
1766
|
-
console.error(error);
|
|
1158
|
+
if (!(error instanceof Error))
|
|
1159
|
+
throw error;
|
|
1160
|
+
console.error(error.message);
|
|
1161
|
+
await this.adapter.save(`products/_doc/${product.id}`, product.toPlain());
|
|
1767
1162
|
}
|
|
1768
1163
|
}
|
|
1769
|
-
async delete(
|
|
1164
|
+
async delete(product) {
|
|
1165
|
+
if (!product.firestoreId)
|
|
1166
|
+
return;
|
|
1770
1167
|
try {
|
|
1771
|
-
await this.
|
|
1168
|
+
await this.get(product.firestoreId);
|
|
1169
|
+
await this.adapter.delete(`products/_doc/${product.firestoreId}`);
|
|
1772
1170
|
}
|
|
1773
1171
|
catch (error) {
|
|
1774
|
-
|
|
1172
|
+
await this.adapter.delete(`products/_doc/${product.id}`);
|
|
1775
1173
|
}
|
|
1776
1174
|
}
|
|
1777
1175
|
}
|
|
@@ -1801,39 +1199,17 @@ const withFirestore = (MixinBase) => {
|
|
|
1801
1199
|
: bindDate(data[key], key),
|
|
1802
1200
|
}), {});
|
|
1803
1201
|
};
|
|
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
|
-
};
|
|
1815
1202
|
return class extends MixinBase {
|
|
1816
|
-
constructor(
|
|
1817
|
-
super(...
|
|
1818
|
-
this.fields = {};
|
|
1819
|
-
this.interceptors = {};
|
|
1203
|
+
constructor() {
|
|
1204
|
+
super(...arguments);
|
|
1820
1205
|
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;
|
|
1827
1206
|
}
|
|
1828
1207
|
collection(path) {
|
|
1829
1208
|
return collection(this.firestore, path || this.collectionName).withConverter(this.buildModelInstance());
|
|
1830
1209
|
}
|
|
1831
1210
|
buildModelInstance() {
|
|
1832
1211
|
return {
|
|
1833
|
-
toFirestore: (data) =>
|
|
1834
|
-
const plain = data?.toPlain ? data.toPlain() : data;
|
|
1835
|
-
return omitByRecursivelyInPlace(plain, (value) => value === undefined);
|
|
1836
|
-
},
|
|
1212
|
+
toFirestore: (data) => (data?.toPlain ? data.toPlain() : data),
|
|
1837
1213
|
fromFirestore: (snap) => {
|
|
1838
1214
|
const data = snap.data();
|
|
1839
1215
|
let bindedData = null;
|
|
@@ -1873,14 +1249,11 @@ const withHelpers = (MixinBase) => {
|
|
|
1873
1249
|
const withGetFirestore = (MixinBase) => {
|
|
1874
1250
|
return class GetFirestore extends MixinBase {
|
|
1875
1251
|
async get(identifiers) {
|
|
1876
|
-
const
|
|
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()));
|
|
1252
|
+
const docRef = await getDoc(doc(await this.collection(this.buildCollectionPathForGet(identifiers)), Object.values(identifiers).shift().toString()));
|
|
1880
1253
|
const data = docRef.data();
|
|
1881
1254
|
if (isNil(data))
|
|
1882
1255
|
throw new NotFoundError(`Document ${JSON.stringify(identifiers)} not found`);
|
|
1883
|
-
return
|
|
1256
|
+
return data;
|
|
1884
1257
|
}
|
|
1885
1258
|
buildCollectionPathForGet(identifiers) {
|
|
1886
1259
|
return this.isSubCollection(this)
|
|
@@ -1917,7 +1290,7 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1917
1290
|
], []);
|
|
1918
1291
|
this.buildWhereSentence = (fieldName, options) => {
|
|
1919
1292
|
if (this.isSubCollection(this) && fieldName === this.parentIdField)
|
|
1920
|
-
|
|
1293
|
+
[];
|
|
1921
1294
|
const value = options?.value || options;
|
|
1922
1295
|
const object = {};
|
|
1923
1296
|
set(object, fieldName, value);
|
|
@@ -1961,11 +1334,8 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1961
1334
|
return Object.keys(fieldsToOrderBy).map((fieldName) => orderBy(fieldName, fieldsToOrderBy[fieldName]));
|
|
1962
1335
|
};
|
|
1963
1336
|
}
|
|
1964
|
-
async find(
|
|
1965
|
-
const collection = this.collection(this.buildCollectionPathForFind(
|
|
1966
|
-
const enableCount = find?.options?.enableCount ?? true;
|
|
1967
|
-
const intercepted = await this.interceptors?.request?.({ find });
|
|
1968
|
-
const { filters, limits, orderBy } = intercepted.find || find;
|
|
1337
|
+
async find({ filters, limits, orderBy, } = {}) {
|
|
1338
|
+
const collection = this.collection(this.buildCollectionPathForFind(filters));
|
|
1969
1339
|
const queries = this.makeFirestoreWhere(filters || {});
|
|
1970
1340
|
const ordination = this.makeFirestoreOrderBy(filters, orderBy);
|
|
1971
1341
|
const offsets = await this.defineLimits(filters, limits);
|
|
@@ -1973,8 +1343,8 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1973
1343
|
const docs = await getDocs(query(collection, ...queryArgumments));
|
|
1974
1344
|
const data = docs.docs.map((doc) => doc.data());
|
|
1975
1345
|
return {
|
|
1976
|
-
data
|
|
1977
|
-
count:
|
|
1346
|
+
data,
|
|
1347
|
+
count: this.calculateCount(data, limits),
|
|
1978
1348
|
};
|
|
1979
1349
|
}
|
|
1980
1350
|
buildCollectionPathForFind(filters) {
|
|
@@ -1988,7 +1358,7 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1988
1358
|
const queries = [];
|
|
1989
1359
|
if (limits?.offset) {
|
|
1990
1360
|
if (this.model.isModel(limits.offset))
|
|
1991
|
-
queries.push(startAfter(await getDoc(doc(this.collection(this.buildCollectionPathForFind(filters)),
|
|
1361
|
+
queries.push(startAfter(await getDoc(doc(this.collection(this.buildCollectionPathForFind(filters)), limits.offset.identifier.shift()))));
|
|
1992
1362
|
else if (isNumber(limits.offset) || isString(limits.offset))
|
|
1993
1363
|
queries.push(startAt(limits.offset));
|
|
1994
1364
|
}
|
|
@@ -2009,16 +1379,12 @@ const withFindFirestore = (MixinBase) => {
|
|
|
2009
1379
|
const withCreateFirestore = (MixinBase) => {
|
|
2010
1380
|
return class CreateFirestore extends MixinBase {
|
|
2011
1381
|
async create(data) {
|
|
2012
|
-
const
|
|
2013
|
-
const intercepted = await this.interceptors?.request?.({ instance });
|
|
2014
|
-
const builded = intercepted?.instance || instance;
|
|
2015
|
-
const docRef = await this.save(builded);
|
|
1382
|
+
const docRef = await this.save(this.model.toInstance(data));
|
|
2016
1383
|
const doc = await getDoc(docRef);
|
|
2017
|
-
|
|
2018
|
-
return docBuilded;
|
|
1384
|
+
return doc.data();
|
|
2019
1385
|
}
|
|
2020
1386
|
async save(data) {
|
|
2021
|
-
const id =
|
|
1387
|
+
const id = data.identifier[data.identifiersFields?.shift()]?.toString();
|
|
2022
1388
|
const collectionPath = this.buildCollectionPathForAdd(data);
|
|
2023
1389
|
const collection = this.collection(collectionPath);
|
|
2024
1390
|
if (isEmpty(id))
|
|
@@ -2059,12 +1425,9 @@ const withUpdateFirestore = (MixinBase) => {
|
|
|
2059
1425
|
const model = new this.model();
|
|
2060
1426
|
const keyField = model.identifiersFields.shift();
|
|
2061
1427
|
const docRef = doc(this.collection(this.buildCollectionPathForUpdate(data)), getValueFromParams(data, keyField).toString());
|
|
2062
|
-
|
|
2063
|
-
const
|
|
2064
|
-
|
|
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;
|
|
1428
|
+
await setDoc(docRef, this.paramsToPlain(data), { merge: true });
|
|
1429
|
+
const docData = await getDoc(docRef);
|
|
1430
|
+
return docData.data();
|
|
2068
1431
|
}
|
|
2069
1432
|
buildCollectionPathForUpdate(identifiers) {
|
|
2070
1433
|
return this.isSubCollection(this)
|
|
@@ -2086,11 +1449,7 @@ const withUpdateFirestore = (MixinBase) => {
|
|
|
2086
1449
|
const withDeleteFirestore = (MixinBase) => {
|
|
2087
1450
|
return class DeleteFirestore extends MixinBase {
|
|
2088
1451
|
async delete(identifiers) {
|
|
2089
|
-
|
|
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);
|
|
1452
|
+
await deleteDoc(doc(this.collection(this.buildCollectionPathForRemove(identifiers)), Object.values(identifiers).shift().toString()));
|
|
2094
1453
|
}
|
|
2095
1454
|
buildCollectionPathForRemove(identifiers) {
|
|
2096
1455
|
return this.isSubCollection(this)
|
|
@@ -2102,10 +1461,8 @@ const withDeleteFirestore = (MixinBase) => {
|
|
|
2102
1461
|
|
|
2103
1462
|
const withSubCollection = (MixinBase, ParentModel) => {
|
|
2104
1463
|
return class SubCollectionMix extends MixinBase {
|
|
2105
|
-
constructor(...
|
|
2106
|
-
|
|
2107
|
-
super(...params);
|
|
2108
|
-
this.parentIdField = options.parentIdField;
|
|
1464
|
+
constructor(...args) {
|
|
1465
|
+
super(args);
|
|
2109
1466
|
}
|
|
2110
1467
|
collection(path) {
|
|
2111
1468
|
return super.collection(path);
|
|
@@ -2119,87 +1476,73 @@ const withCrudFirestore = (MixinBase) => {
|
|
|
2119
1476
|
};
|
|
2120
1477
|
|
|
2121
1478
|
class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2122
|
-
constructor(
|
|
2123
|
-
super(
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
interceptors,
|
|
2128
|
-
});
|
|
1479
|
+
constructor(firestore) {
|
|
1480
|
+
super();
|
|
1481
|
+
this.firestore = firestore;
|
|
1482
|
+
this.collectionName = 'leads';
|
|
1483
|
+
this.model = Lead;
|
|
2129
1484
|
}
|
|
2130
1485
|
}
|
|
2131
1486
|
|
|
2132
1487
|
class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription) {
|
|
2133
|
-
constructor(
|
|
2134
|
-
super(
|
|
2135
|
-
|
|
2136
|
-
collectionName: 'editions',
|
|
2137
|
-
parentIdField: 'subscriptionId',
|
|
2138
|
-
model: Edition,
|
|
2139
|
-
interceptors,
|
|
2140
|
-
});
|
|
1488
|
+
constructor(firestore, parentRepository) {
|
|
1489
|
+
super();
|
|
1490
|
+
this.firestore = firestore;
|
|
2141
1491
|
this.parentRepository = parentRepository;
|
|
1492
|
+
this.collectionName = 'editions';
|
|
1493
|
+
this.parentIdField = 'subscriptionId';
|
|
1494
|
+
this.model = Edition;
|
|
2142
1495
|
}
|
|
2143
1496
|
}
|
|
2144
1497
|
|
|
2145
1498
|
class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2146
|
-
constructor(
|
|
2147
|
-
super(
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
interceptors,
|
|
2152
|
-
});
|
|
1499
|
+
constructor(firestore) {
|
|
1500
|
+
super();
|
|
1501
|
+
this.firestore = firestore;
|
|
1502
|
+
this.collectionName = 'subscription';
|
|
1503
|
+
this.model = Subscription;
|
|
2153
1504
|
}
|
|
2154
1505
|
}
|
|
2155
1506
|
|
|
2156
1507
|
class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription) {
|
|
2157
|
-
constructor(
|
|
2158
|
-
super(
|
|
2159
|
-
|
|
2160
|
-
collectionName: 'payments',
|
|
2161
|
-
parentIdField: 'subscriptionId',
|
|
2162
|
-
model: SubscriptionPayment,
|
|
2163
|
-
interceptors,
|
|
2164
|
-
});
|
|
1508
|
+
constructor(firestore, parentRepository) {
|
|
1509
|
+
super();
|
|
1510
|
+
this.firestore = firestore;
|
|
2165
1511
|
this.parentRepository = parentRepository;
|
|
1512
|
+
this.collectionName = 'payments';
|
|
1513
|
+
this.parentIdField = 'subscriptionId';
|
|
1514
|
+
this.model = SubscriptionPayment;
|
|
2166
1515
|
}
|
|
2167
1516
|
}
|
|
2168
1517
|
|
|
2169
1518
|
class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
|
|
2170
|
-
constructor(
|
|
2171
|
-
super(
|
|
2172
|
-
|
|
2173
|
-
collectionName: 'address',
|
|
2174
|
-
parentIdField: 'userId',
|
|
2175
|
-
model: UserAddress,
|
|
2176
|
-
interceptors,
|
|
2177
|
-
});
|
|
1519
|
+
constructor(firestore, parentRepository) {
|
|
1520
|
+
super();
|
|
1521
|
+
this.firestore = firestore;
|
|
2178
1522
|
this.parentRepository = parentRepository;
|
|
1523
|
+
this.collectionName = 'address';
|
|
1524
|
+
this.parentIdField = 'userId';
|
|
1525
|
+
this.model = UserAddress;
|
|
2179
1526
|
}
|
|
2180
1527
|
}
|
|
2181
1528
|
|
|
2182
1529
|
class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
|
|
2183
|
-
constructor(
|
|
2184
|
-
super(
|
|
2185
|
-
|
|
2186
|
-
collectionName: 'CX',
|
|
2187
|
-
parentIdField: 'userId',
|
|
2188
|
-
model: BeautyProfile,
|
|
2189
|
-
interceptors,
|
|
2190
|
-
});
|
|
1530
|
+
constructor(firestore, parentRepository) {
|
|
1531
|
+
super();
|
|
1532
|
+
this.firestore = firestore;
|
|
2191
1533
|
this.parentRepository = parentRepository;
|
|
1534
|
+
this.collectionName = 'CX';
|
|
1535
|
+
this.parentIdField = 'userId';
|
|
1536
|
+
this.model = BeautyProfile;
|
|
2192
1537
|
}
|
|
2193
1538
|
}
|
|
2194
1539
|
|
|
2195
1540
|
class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2196
|
-
constructor(
|
|
2197
|
-
super(
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
interceptors,
|
|
2202
|
-
});
|
|
1541
|
+
constructor(firestore) {
|
|
1542
|
+
super();
|
|
1543
|
+
this.firestore = firestore;
|
|
1544
|
+
this.collectionName = 'users';
|
|
1545
|
+
this.model = User;
|
|
2203
1546
|
}
|
|
2204
1547
|
async get(identifiers) {
|
|
2205
1548
|
const user = await super.get({ id: identifiers.id });
|
|
@@ -2239,26 +1582,22 @@ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
2239
1582
|
}
|
|
2240
1583
|
|
|
2241
1584
|
class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
|
|
2242
|
-
constructor(
|
|
2243
|
-
super(
|
|
2244
|
-
|
|
2245
|
-
collectionName: 'payment_method',
|
|
2246
|
-
parentIdField: 'userId',
|
|
2247
|
-
model: UserPaymentMethod,
|
|
2248
|
-
interceptors,
|
|
2249
|
-
});
|
|
1585
|
+
constructor(firestore, parentRepository) {
|
|
1586
|
+
super();
|
|
1587
|
+
this.firestore = firestore;
|
|
2250
1588
|
this.parentRepository = parentRepository;
|
|
1589
|
+
this.collectionName = 'payment_method';
|
|
1590
|
+
this.parentIdField = 'userId';
|
|
1591
|
+
this.model = UserPaymentMethod;
|
|
2251
1592
|
}
|
|
2252
1593
|
}
|
|
2253
1594
|
|
|
2254
1595
|
class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2255
|
-
constructor(
|
|
2256
|
-
super(
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
interceptors,
|
|
2261
|
-
});
|
|
1596
|
+
constructor(firestore) {
|
|
1597
|
+
super();
|
|
1598
|
+
this.firestore = firestore;
|
|
1599
|
+
this.collectionName = 'categories';
|
|
1600
|
+
this.model = Category;
|
|
2262
1601
|
}
|
|
2263
1602
|
async getCategoryBySlug(slug, shop) {
|
|
2264
1603
|
const categoryDocs = await getDocs(query(this.collection(this.collectionName), where('slug', '==', slug), where('shop', '==', shop), where('published', '==', true)));
|
|
@@ -2268,14 +1607,14 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
2268
1607
|
throw new NotFoundError(`Document with slug ${slug} not found`);
|
|
2269
1608
|
return categoryDocs.docs[0].data();
|
|
2270
1609
|
}
|
|
2271
|
-
async getCategoriesForHome(categoryIds, limit = 4
|
|
1610
|
+
async getCategoriesForHome(categoryIds, limit = 4) {
|
|
2272
1611
|
const categorySnap = await getDocs(query(this.collection(this.collectionName), where('id', 'in', categoryIds.filter(Boolean)), where('published', '==', true)));
|
|
2273
1612
|
if (categorySnap.empty)
|
|
2274
1613
|
throw new NotFoundError('Categories not found');
|
|
2275
1614
|
const categories = categorySnap.docs.map((doc) => doc.data());
|
|
2276
1615
|
const homeSections = await Promise.all(categories.map(async (category) => ({
|
|
2277
1616
|
category,
|
|
2278
|
-
products: await this.mountCategory(category, { limit, hasStock: true
|
|
1617
|
+
products: await this.mountCategory(category, { limit, hasStock: true }),
|
|
2279
1618
|
})));
|
|
2280
1619
|
return homeSections;
|
|
2281
1620
|
}
|
|
@@ -2291,8 +1630,6 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
2291
1630
|
wheres.push(where('published', '==', true), where('id', 'in', productIds));
|
|
2292
1631
|
if (options?.hasStock)
|
|
2293
1632
|
wheres.push(where('stock.quantity', '>', 0));
|
|
2294
|
-
if (options?.gender)
|
|
2295
|
-
wheres.push(where('tags', 'array-contains', options?.gender));
|
|
2296
1633
|
if (options?.limit)
|
|
2297
1634
|
wheres.push(limit(options?.limit));
|
|
2298
1635
|
const productSnap = await getDocs(query(this.collection('productsErpVitrine'), ...wheres));
|
|
@@ -2302,26 +1639,15 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
2302
1639
|
}
|
|
2303
1640
|
return is(products);
|
|
2304
1641
|
}
|
|
2305
|
-
getCategoryByShop(shop) {
|
|
2306
|
-
return;
|
|
2307
|
-
}
|
|
2308
|
-
getChildren(parentId) {
|
|
2309
|
-
return;
|
|
2310
|
-
}
|
|
2311
|
-
isChild(id, parentId) {
|
|
2312
|
-
return;
|
|
2313
|
-
}
|
|
2314
1642
|
}
|
|
2315
1643
|
|
|
2316
1644
|
class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2317
|
-
constructor(
|
|
2318
|
-
super(
|
|
2319
|
-
|
|
2320
|
-
collectionName: 'productsErpVitrine',
|
|
2321
|
-
model: Product,
|
|
2322
|
-
interceptors,
|
|
2323
|
-
});
|
|
1645
|
+
constructor(firestore) {
|
|
1646
|
+
super();
|
|
1647
|
+
this.firestore = firestore;
|
|
2324
1648
|
this.reviews = {};
|
|
1649
|
+
this.collectionName = 'productsErpVitrine';
|
|
1650
|
+
this.model = Product;
|
|
2325
1651
|
}
|
|
2326
1652
|
async getBySlug(slug) {
|
|
2327
1653
|
const result = await this.find({
|
|
@@ -2356,101 +1682,43 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
2356
1682
|
});
|
|
2357
1683
|
return this.reviews[status];
|
|
2358
1684
|
}
|
|
2359
|
-
cleanShoppingCountFromIds() {
|
|
2360
|
-
return;
|
|
2361
|
-
}
|
|
2362
|
-
findCatalog(params) {
|
|
2363
|
-
return this.find(params);
|
|
2364
|
-
}
|
|
2365
1685
|
}
|
|
2366
1686
|
|
|
2367
1687
|
class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Product) {
|
|
2368
|
-
constructor(
|
|
2369
|
-
super(
|
|
2370
|
-
|
|
2371
|
-
collectionName: 'variants',
|
|
2372
|
-
parentIdField: 'productId',
|
|
2373
|
-
model: Variant,
|
|
2374
|
-
interceptors,
|
|
2375
|
-
});
|
|
1688
|
+
constructor(firestore, parentRepository) {
|
|
1689
|
+
super();
|
|
1690
|
+
this.firestore = firestore;
|
|
2376
1691
|
this.parentRepository = parentRepository;
|
|
1692
|
+
this.collectionName = 'variants';
|
|
1693
|
+
this.parentIdField = 'productId';
|
|
1694
|
+
this.model = Variant;
|
|
2377
1695
|
}
|
|
2378
1696
|
}
|
|
2379
1697
|
|
|
2380
1698
|
class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2381
|
-
constructor(
|
|
2382
|
-
super(
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
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
|
-
});
|
|
1699
|
+
constructor(firestore) {
|
|
1700
|
+
super();
|
|
1701
|
+
this.firestore = firestore;
|
|
1702
|
+
this.collectionName = 'subscriptionProducts';
|
|
1703
|
+
this.model = Product;
|
|
2421
1704
|
}
|
|
2422
1705
|
}
|
|
2423
1706
|
|
|
2424
1707
|
class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2425
|
-
constructor(
|
|
2426
|
-
super(
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
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
|
-
});
|
|
1708
|
+
constructor(firestore) {
|
|
1709
|
+
super();
|
|
1710
|
+
this.firestore = firestore;
|
|
1711
|
+
this.collectionName = 'checkouts';
|
|
1712
|
+
this.model = Checkout;
|
|
2443
1713
|
}
|
|
2444
1714
|
}
|
|
2445
1715
|
|
|
2446
1716
|
class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2447
|
-
constructor(
|
|
2448
|
-
super(
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
interceptors,
|
|
2453
|
-
});
|
|
1717
|
+
constructor(firestore) {
|
|
1718
|
+
super();
|
|
1719
|
+
this.firestore = firestore;
|
|
1720
|
+
this.collectionName = 'coupons';
|
|
1721
|
+
this.model = Coupon;
|
|
2454
1722
|
}
|
|
2455
1723
|
buildModelInstance() {
|
|
2456
1724
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
@@ -2472,16 +1740,9 @@ class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirest
|
|
|
2472
1740
|
}
|
|
2473
1741
|
|
|
2474
1742
|
class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2475
|
-
constructor(
|
|
2476
|
-
super(
|
|
2477
|
-
|
|
2478
|
-
collectionName: 'orders',
|
|
2479
|
-
model: Order,
|
|
2480
|
-
interceptors,
|
|
2481
|
-
fields: {
|
|
2482
|
-
status: FirestoreFieldType.String,
|
|
2483
|
-
},
|
|
2484
|
-
});
|
|
1743
|
+
constructor(firestore) {
|
|
1744
|
+
super();
|
|
1745
|
+
this.firestore = firestore;
|
|
2485
1746
|
this.orderFromFirestore = (order) => {
|
|
2486
1747
|
if (!!order?.lineItems?.length) {
|
|
2487
1748
|
order.lineItems = order.lineItems.map((lineItem) => {
|
|
@@ -2494,6 +1755,11 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
2494
1755
|
}
|
|
2495
1756
|
return order;
|
|
2496
1757
|
};
|
|
1758
|
+
this.collectionName = 'orders';
|
|
1759
|
+
this.model = Order;
|
|
1760
|
+
this.fields = {
|
|
1761
|
+
status: FirestoreFieldType.String,
|
|
1762
|
+
};
|
|
2497
1763
|
}
|
|
2498
1764
|
buildModelInstance() {
|
|
2499
1765
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
@@ -2507,58 +1773,84 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
2507
1773
|
}
|
|
2508
1774
|
}
|
|
2509
1775
|
|
|
2510
|
-
class
|
|
2511
|
-
constructor(
|
|
2512
|
-
super(
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
this.collectionName = 'legacyOrders';
|
|
1776
|
+
class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1777
|
+
constructor(firestore) {
|
|
1778
|
+
super();
|
|
1779
|
+
this.firestore = firestore;
|
|
1780
|
+
this.collectionName = 'payments';
|
|
1781
|
+
this.model = Payment;
|
|
2517
1782
|
}
|
|
2518
1783
|
}
|
|
2519
1784
|
|
|
2520
|
-
class
|
|
2521
|
-
constructor(
|
|
2522
|
-
super(
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
interceptors,
|
|
2527
|
-
});
|
|
1785
|
+
class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1786
|
+
constructor(firestore) {
|
|
1787
|
+
super();
|
|
1788
|
+
this.firestore = firestore;
|
|
1789
|
+
this.collectionName = 'checkoutsSubscription';
|
|
1790
|
+
this.model = CheckoutSubscription;
|
|
2528
1791
|
}
|
|
2529
1792
|
}
|
|
2530
1793
|
|
|
2531
1794
|
class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2532
|
-
constructor(
|
|
2533
|
-
super(
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
1795
|
+
constructor(firestore) {
|
|
1796
|
+
super();
|
|
1797
|
+
this.firestore = firestore;
|
|
1798
|
+
this.collectionName = 'subscriptionPlans';
|
|
1799
|
+
this.model = SubscriptionPlan;
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
1804
|
+
constructor(firestore) {
|
|
1805
|
+
super();
|
|
1806
|
+
this.firestore = firestore;
|
|
1807
|
+
this.collectionName = 'buy2win';
|
|
1808
|
+
this.model = Buy2Win;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
|
|
1813
|
+
constructor(firestore) {
|
|
1814
|
+
super(firestore);
|
|
1815
|
+
this.firestore = firestore;
|
|
1816
|
+
this.collectionName = 'legacyOrders';
|
|
2539
1817
|
}
|
|
2540
1818
|
}
|
|
2541
1819
|
|
|
2542
1820
|
class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2543
|
-
constructor(
|
|
2544
|
-
super(
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
1821
|
+
constructor(firestore) {
|
|
1822
|
+
super();
|
|
1823
|
+
this.firestore = firestore;
|
|
1824
|
+
this.homeToFirestore = (home) => {
|
|
1825
|
+
if (home.data?.data) {
|
|
1826
|
+
home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.homeCategoryGroupToPlain);
|
|
1827
|
+
home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.homeCategoryGroupToPlain);
|
|
1828
|
+
home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.homeCategoryGroupToPlain);
|
|
1829
|
+
}
|
|
1830
|
+
return home;
|
|
1831
|
+
};
|
|
2550
1832
|
this.homeCategoryGroupToPlain = (homeCategoryGroup) => ({
|
|
2551
|
-
category: homeCategoryGroup
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
.
|
|
2557
|
-
|
|
1833
|
+
category: homeCategoryGroup.category.toPlain(),
|
|
1834
|
+
products: homeCategoryGroup.products.map((product) => product.toPlain()),
|
|
1835
|
+
});
|
|
1836
|
+
this.homeFromFirestore = (home) => {
|
|
1837
|
+
if (home.data?.data) {
|
|
1838
|
+
home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
|
|
1839
|
+
home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
|
|
1840
|
+
home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
|
|
1841
|
+
home.data.createdAt =
|
|
1842
|
+
home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
|
|
1843
|
+
home.data.expiresAt =
|
|
1844
|
+
home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
|
|
1845
|
+
}
|
|
1846
|
+
return home;
|
|
1847
|
+
};
|
|
2558
1848
|
this.plainToHomeCategoryGroup = (homeCategoryGroup) => ({
|
|
2559
|
-
category: Category.toInstance(homeCategoryGroup
|
|
2560
|
-
products: homeCategoryGroup.products
|
|
1849
|
+
category: Category.toInstance(homeCategoryGroup.category),
|
|
1850
|
+
products: homeCategoryGroup.products.map((product) => Product.toInstance(product)),
|
|
2561
1851
|
});
|
|
1852
|
+
this.collectionName = 'dms';
|
|
1853
|
+
this.model = Home;
|
|
2562
1854
|
}
|
|
2563
1855
|
buildModelInstance() {
|
|
2564
1856
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
@@ -2573,47 +1865,14 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
2573
1865
|
},
|
|
2574
1866
|
};
|
|
2575
1867
|
}
|
|
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
|
-
}
|
|
2596
1868
|
}
|
|
2597
1869
|
|
|
2598
1870
|
class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
2599
|
-
constructor(
|
|
2600
|
-
super(
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
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
|
-
});
|
|
1871
|
+
constructor(firestore) {
|
|
1872
|
+
super();
|
|
1873
|
+
this.firestore = firestore;
|
|
1874
|
+
this.collectionName = 'shopMenus';
|
|
1875
|
+
this.model = ShopMenu;
|
|
2617
1876
|
}
|
|
2618
1877
|
}
|
|
2619
1878
|
|
|
@@ -2690,7 +1949,7 @@ class AttributeOptionHelper {
|
|
|
2690
1949
|
}
|
|
2691
1950
|
AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
2692
1951
|
if (fields.includes(attributeName))
|
|
2693
|
-
return { columnName: attributeName.toString(), attributeName
|
|
1952
|
+
return { columnName: attributeName.toString(), attributeName };
|
|
2694
1953
|
const field = fields.find((columnOption) => isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
|
|
2695
1954
|
const fieldOption = is(field)?.[attributeName];
|
|
2696
1955
|
if (isNil(fieldOption))
|
|
@@ -2699,7 +1958,7 @@ AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
|
2699
1958
|
return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
|
|
2700
1959
|
return { attributeName, columnName: attributeName.toString(), ...fieldOption };
|
|
2701
1960
|
};
|
|
2702
|
-
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue
|
|
1961
|
+
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue.columnName;
|
|
2703
1962
|
AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
2704
1963
|
if (fields.includes(columnName))
|
|
2705
1964
|
return { columnName, attributeName: columnName };
|
|
@@ -2792,26 +2051,25 @@ BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter)
|
|
|
2792
2051
|
}, {});
|
|
2793
2052
|
BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
2794
2053
|
const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
|
|
2795
|
-
|
|
2054
|
+
if (!Array.isArray(options) &&
|
|
2796
2055
|
isObject(options) &&
|
|
2797
2056
|
isNil(options?.operator) &&
|
|
2798
2057
|
isNil(options?.value) &&
|
|
2799
|
-
isNil(fieldSentenceOptions?.to)
|
|
2800
|
-
if (isNestedField)
|
|
2058
|
+
isNil(fieldSentenceOptions?.to))
|
|
2801
2059
|
return Object.keys(options).reduce((variables, key) => {
|
|
2802
2060
|
const fieldOptions = AttributeOptionHelper.FindByAttribute(key, fieldSentenceOptions?.fields || fields);
|
|
2803
2061
|
const columnName = fieldOptions.columnName;
|
|
2804
2062
|
const columnFields = fieldOptions.fields;
|
|
2805
2063
|
return {
|
|
2806
2064
|
...variables,
|
|
2807
|
-
[columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]),
|
|
2065
|
+
[columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), columnFields || []),
|
|
2808
2066
|
};
|
|
2809
2067
|
}, {});
|
|
2810
2068
|
if (!Array.isArray(options) && !isNil(fieldSentenceOptions.fields))
|
|
2811
2069
|
return {
|
|
2812
2070
|
[fieldSentenceOptions.fields[0]]: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions),
|
|
2813
2071
|
};
|
|
2814
|
-
if (
|
|
2072
|
+
if (isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
2815
2073
|
options = Object.values(options)[0];
|
|
2816
2074
|
return Array.isArray(options)
|
|
2817
2075
|
? options.reduce((whereSentence, option) => ({
|
|
@@ -2847,14 +2105,28 @@ GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
|
2847
2105
|
if (field === 'affected_rows')
|
|
2848
2106
|
return field;
|
|
2849
2107
|
const fieldName = Object.keys(field).shift();
|
|
2850
|
-
const fieldValue =
|
|
2108
|
+
const fieldValue = field[fieldName];
|
|
2851
2109
|
if (Array.isArray(fieldValue))
|
|
2852
2110
|
return { [fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue) };
|
|
2853
2111
|
if (!AttributeOptionHelper.CheckIsColumnOption(fieldValue))
|
|
2854
|
-
return;
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2112
|
+
return null;
|
|
2113
|
+
if (fieldValue.fields)
|
|
2114
|
+
return !fieldValue.filters
|
|
2115
|
+
? {
|
|
2116
|
+
[fieldValue.columnName || fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
2117
|
+
}
|
|
2118
|
+
: {
|
|
2119
|
+
operation: fieldValue.columnName || fieldName,
|
|
2120
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
2121
|
+
variables: {
|
|
2122
|
+
[`${fieldValue.columnName}_where`]: {
|
|
2123
|
+
name: 'where',
|
|
2124
|
+
type: fieldValue.filters.filterType,
|
|
2125
|
+
value: BindFilterQueryHelper.MakeGraphQLWhere(fieldValue.filters.filters, fieldValue.fields),
|
|
2126
|
+
required: true,
|
|
2127
|
+
},
|
|
2128
|
+
},
|
|
2129
|
+
};
|
|
2858
2130
|
return fieldValue.columnName;
|
|
2859
2131
|
})
|
|
2860
2132
|
.filter((field) => !!field);
|
|
@@ -2879,10 +2151,7 @@ GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).r
|
|
|
2879
2151
|
}
|
|
2880
2152
|
if (!!from)
|
|
2881
2153
|
return { ...result, [attributeName]: from(data[columnName], data) };
|
|
2882
|
-
return {
|
|
2883
|
-
...result,
|
|
2884
|
-
[attributeName]: isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName],
|
|
2885
|
-
};
|
|
2154
|
+
return { ...result, [attributeName]: parseDateTime(data[columnName]?.toString()) };
|
|
2886
2155
|
}, {});
|
|
2887
2156
|
GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
2888
2157
|
const data = instance.toPlain?.() || instance;
|
|
@@ -2898,13 +2167,10 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
|
2898
2167
|
if (!!foreignKeyColumn &&
|
|
2899
2168
|
!isEmpty(foreignKeyColumn) &&
|
|
2900
2169
|
!Object.keys(foreignKeyColumn).filter((key) => !is(data[attributeName])?.[key]).length)
|
|
2901
|
-
return Object.keys(foreignKeyColumn).reduce((object, current) => {
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
[foreignColumnName]: data[attributeName]?.[current],
|
|
2906
|
-
};
|
|
2907
|
-
}, { ...result });
|
|
2170
|
+
return Object.keys(foreignKeyColumn).reduce((object, current) => ({
|
|
2171
|
+
...object,
|
|
2172
|
+
[foreignKeyColumn[current]]: data[attributeName]?.[current],
|
|
2173
|
+
}), { ...result });
|
|
2908
2174
|
if (update &&
|
|
2909
2175
|
isObject(data[attributeName]) &&
|
|
2910
2176
|
!isNil(attributeFields) &&
|
|
@@ -2937,25 +2203,6 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
|
2937
2203
|
return { ...result, [columnName]: data[attributeName] };
|
|
2938
2204
|
}, {});
|
|
2939
2205
|
};
|
|
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
|
-
};
|
|
2959
2206
|
|
|
2960
2207
|
const withCreateHasuraGraphQL = (MixinBase) => {
|
|
2961
2208
|
return class CreateHasuraGraphQLMixin extends MixinBase {
|
|
@@ -2966,7 +2213,6 @@ const withCreateHasuraGraphQL = (MixinBase) => {
|
|
|
2966
2213
|
this.insertGraphQLObjectType = options?.insertGraphQLObjectType || `${this.tableName}_insert_input`;
|
|
2967
2214
|
}
|
|
2968
2215
|
async create(data) {
|
|
2969
|
-
this.logger = DebugHelper.from(this, 'create');
|
|
2970
2216
|
const newData = await this.save(this.model.toInstance(data));
|
|
2971
2217
|
return this.model.toInstance(newData);
|
|
2972
2218
|
}
|
|
@@ -2977,10 +2223,10 @@ const withCreateHasuraGraphQL = (MixinBase) => {
|
|
|
2977
2223
|
const columnOptions = Object.values(field).shift();
|
|
2978
2224
|
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
2979
2225
|
columnOptions.foreignKeyColumn && [
|
|
2980
|
-
...Object.values(columnOptions.foreignKeyColumn)
|
|
2226
|
+
...Object.values(columnOptions.foreignKeyColumn),
|
|
2981
2227
|
{
|
|
2982
|
-
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)
|
|
2983
|
-
|
|
2228
|
+
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)?.columnName ||
|
|
2229
|
+
foreignKeyField),
|
|
2984
2230
|
},
|
|
2985
2231
|
]);
|
|
2986
2232
|
})
|
|
@@ -3002,11 +2248,9 @@ const withDeleteHasuraGraphQL = (MixinBase) => {
|
|
|
3002
2248
|
this.deleteGraphQLOperation = options?.deleteGraphQLOperation || `delete_${this.tableName}_by_pk`;
|
|
3003
2249
|
}
|
|
3004
2250
|
async delete(identifiers) {
|
|
3005
|
-
this.logger = DebugHelper.from(this, 'delete');
|
|
3006
2251
|
const instance = this.model.toInstance(identifiers);
|
|
3007
2252
|
await this.mutation(this.deleteGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), this.model.identifiersFields.reduce((ids, identifier) => {
|
|
3008
|
-
|
|
3009
|
-
if (isNil(instance.identifier[identifierBinded]))
|
|
2253
|
+
if (isNil(instance[identifier]))
|
|
3010
2254
|
return ids;
|
|
3011
2255
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
|
|
3012
2256
|
const value = columnOption.to(identifiers[identifier], instance);
|
|
@@ -3033,19 +2277,15 @@ const withHasuraGraphQL = (MixinBase) => {
|
|
|
3033
2277
|
this.authOptions = options.authOptions;
|
|
3034
2278
|
this.model = options.model;
|
|
3035
2279
|
this.fields = options.fields || this.model.identifiersFields;
|
|
3036
|
-
this.logger = DebugHelper.from(this);
|
|
3037
2280
|
}
|
|
3038
2281
|
get headers() {
|
|
3039
2282
|
return {
|
|
3040
2283
|
'Content-Type': 'application/json',
|
|
3041
|
-
...(isNil(this.authOptions
|
|
3042
|
-
...(isNil(this.authOptions
|
|
3043
|
-
...(isNil(this.authOptions
|
|
2284
|
+
...(isNil(this.authOptions.authToken) ? {} : { Authorization: this.authOptions.authToken }),
|
|
2285
|
+
...(isNil(this.authOptions.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': this.authOptions.adminSecret }),
|
|
2286
|
+
...(isNil(this.authOptions.authRole)
|
|
3044
2287
|
? {}
|
|
3045
|
-
: {
|
|
3046
|
-
'X-Hasura-Role': this.authOptions.authRole.role,
|
|
3047
|
-
'X-Hasura-User-Id': this.authOptions?.authRole?.userId,
|
|
3048
|
-
}),
|
|
2288
|
+
: { 'X-Hasura-Role': this.authOptions.authRole.role, 'X-Hasura-User-Id': this.authOptions.authRole.userId }),
|
|
3049
2289
|
};
|
|
3050
2290
|
}
|
|
3051
2291
|
async mutation(operation, fields, variables) {
|
|
@@ -3057,28 +2297,29 @@ const withHasuraGraphQL = (MixinBase) => {
|
|
|
3057
2297
|
return this.fetch(resultQuery);
|
|
3058
2298
|
}
|
|
3059
2299
|
async query(operation, fields, variables) {
|
|
3060
|
-
const
|
|
3061
|
-
operation
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
2300
|
+
const resultQuery = GraphQLFieldHelper.CheckIsGraphQLParams(operation)
|
|
2301
|
+
? query$1(operation.map((option) => ({
|
|
2302
|
+
operation: option.operation,
|
|
2303
|
+
variables: option.variables,
|
|
2304
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(option.fields),
|
|
2305
|
+
})))
|
|
2306
|
+
: query$1({
|
|
2307
|
+
operation,
|
|
2308
|
+
variables,
|
|
2309
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
|
|
2310
|
+
});
|
|
2311
|
+
return this.fetch(resultQuery);
|
|
3069
2312
|
}
|
|
3070
2313
|
async fetch(params) {
|
|
3071
|
-
this.logger.with('params').log(params);
|
|
3072
2314
|
const headers = this.headers;
|
|
3073
|
-
const
|
|
3074
|
-
url: `${this.endpoint}`,
|
|
2315
|
+
const response = await fetch(`${this.endpoint}`, {
|
|
3075
2316
|
method: 'POST',
|
|
3076
|
-
|
|
2317
|
+
body: JSON.stringify(params),
|
|
3077
2318
|
headers,
|
|
3078
2319
|
});
|
|
2320
|
+
const result = await response.json();
|
|
3079
2321
|
if (!isNil(result.errors))
|
|
3080
2322
|
throw new Error(JSON.stringify(result.errors));
|
|
3081
|
-
this.logger.with('returns').log(result);
|
|
3082
2323
|
return result.data;
|
|
3083
2324
|
}
|
|
3084
2325
|
getAttributeGraphQLTypeOf(value) {
|
|
@@ -3104,26 +2345,13 @@ const withHasuraGraphQL = (MixinBase) => {
|
|
|
3104
2345
|
return value;
|
|
3105
2346
|
return date;
|
|
3106
2347
|
}
|
|
3107
|
-
convertDataFromHasura(data
|
|
3108
|
-
const plain = GraphQLFieldHelper.ConvertFieldValueFrom(data,
|
|
2348
|
+
convertDataFromHasura(data) {
|
|
2349
|
+
const plain = GraphQLFieldHelper.ConvertFieldValueFrom(data, this.fields);
|
|
3109
2350
|
return this.model.toInstance(plain);
|
|
3110
2351
|
}
|
|
3111
2352
|
convertDataToHasura(instance, update = false) {
|
|
3112
2353
|
return GraphQLFieldHelper.ConvertFieldValueTo(instance, this.fields, update);
|
|
3113
2354
|
}
|
|
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
|
-
}
|
|
3127
2355
|
};
|
|
3128
2356
|
};
|
|
3129
2357
|
|
|
@@ -3146,7 +2374,6 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
|
3146
2374
|
this.updateGraphQLPKType = options?.updateGraphQLPKType || `${this.tableName}_pk_columns_input`;
|
|
3147
2375
|
}
|
|
3148
2376
|
async update(data) {
|
|
3149
|
-
this.logger = DebugHelper.from(this, 'update');
|
|
3150
2377
|
const plainData = this.paramsToPlain(data);
|
|
3151
2378
|
await this.mutation(this.updateGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), {
|
|
3152
2379
|
_set: {
|
|
@@ -3172,11 +2399,10 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
|
3172
2399
|
getUpdateModelKeys(data) {
|
|
3173
2400
|
const instance = this.model.toInstance(data);
|
|
3174
2401
|
return this.model.identifiersFields.reduce((ids, identifier) => {
|
|
3175
|
-
|
|
3176
|
-
if (isNil(instance.identifier[identifierBinded]))
|
|
2402
|
+
if (isNil(instance[identifier]))
|
|
3177
2403
|
return ids;
|
|
3178
|
-
const columnOption = AttributeOptionHelper.FindByAttribute(
|
|
3179
|
-
const value = columnOption?.to?.(data[
|
|
2404
|
+
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
|
|
2405
|
+
const value = columnOption?.to?.(data[identifier], instance) || data[columnOption.attributeName];
|
|
3180
2406
|
return {
|
|
3181
2407
|
...ids,
|
|
3182
2408
|
[columnOption.columnName]: value,
|
|
@@ -3194,11 +2420,9 @@ const withGetHasuraGraphQL = (MixinBase) => {
|
|
|
3194
2420
|
this.getGraphQLOperation = options?.getGraphQLOperation || `${this.tableName}_by_pk`;
|
|
3195
2421
|
}
|
|
3196
2422
|
async get(identifiers) {
|
|
3197
|
-
this.logger = DebugHelper.from(this, 'get');
|
|
3198
2423
|
const instance = this.model.toInstance(identifiers);
|
|
3199
2424
|
const result = await this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce((ids, identifier) => {
|
|
3200
|
-
|
|
3201
|
-
if (isNil(instance[identifierBinded]))
|
|
2425
|
+
if (isNil(instance[identifier]))
|
|
3202
2426
|
return ids;
|
|
3203
2427
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
|
|
3204
2428
|
const value = columnOption?.to?.(identifiers[identifier], instance) ||
|
|
@@ -3222,150 +2446,44 @@ const withGetHasuraGraphQL = (MixinBase) => {
|
|
|
3222
2446
|
|
|
3223
2447
|
const withFindHasuraGraphQL = (MixinBase) => {
|
|
3224
2448
|
return class FindHasuraGraphQLMixin extends MixinBase {
|
|
3225
|
-
|
|
3226
|
-
|
|
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
|
-
};
|
|
2449
|
+
async find(options) {
|
|
2450
|
+
const { filters, limits, orderBy } = options || {};
|
|
3268
2451
|
const variablesCount = {
|
|
3269
|
-
...(isNil(orderBy)
|
|
2452
|
+
...(isNil(orderBy) ? {} : { order_by: { type: `${this.tableName}_order_by!`, list: true, value: orderBy } }),
|
|
2453
|
+
...(isNil(filters)
|
|
3270
2454
|
? {}
|
|
3271
2455
|
: {
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
2456
|
+
where: {
|
|
2457
|
+
value: BindFilterQueryHelper.MakeGraphQLWhere(filters, this.fields),
|
|
2458
|
+
type: `${this.tableName}_bool_exp`,
|
|
2459
|
+
required: true,
|
|
3276
2460
|
},
|
|
3277
2461
|
}),
|
|
3278
|
-
...variablesFilters,
|
|
3279
2462
|
};
|
|
3280
2463
|
const variables = {
|
|
3281
2464
|
...(isNil(limits) ? {} : limits),
|
|
3282
2465
|
...variablesCount,
|
|
3283
2466
|
};
|
|
3284
|
-
const aggregateFields = [
|
|
3285
|
-
...(enableCount ? ['count'] : []),
|
|
3286
|
-
...this.bindAggretageAttributes(params.options, this.fields),
|
|
3287
|
-
];
|
|
3288
2467
|
const result = await this.query([
|
|
3289
2468
|
{
|
|
3290
2469
|
operation: this.tableName,
|
|
3291
|
-
fields:
|
|
3292
|
-
?
|
|
2470
|
+
fields: options.fields
|
|
2471
|
+
? options.fields
|
|
3293
2472
|
.map((fieldName) => this.fields.find((fieldOption) => fieldOption === fieldName) ??
|
|
3294
2473
|
this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName))
|
|
3295
2474
|
.filter(Boolean)
|
|
3296
2475
|
: this.fields,
|
|
3297
2476
|
variables,
|
|
3298
2477
|
},
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
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
|
-
[]),
|
|
2478
|
+
{
|
|
2479
|
+
operation: `${this.tableName}_aggregate`,
|
|
2480
|
+
fields: [{ aggregate: ['count'] }],
|
|
2481
|
+
variables: variablesCount,
|
|
2482
|
+
},
|
|
3335
2483
|
]);
|
|
3336
2484
|
const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
|
|
3337
|
-
|
|
3338
|
-
|
|
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
|
-
};
|
|
2485
|
+
const count = result[`${this.tableName}_aggregate`].aggregate.count;
|
|
2486
|
+
return { count, data };
|
|
3369
2487
|
}
|
|
3370
2488
|
};
|
|
3371
2489
|
};
|
|
@@ -3404,154 +2522,13 @@ class VariantHasuraGraphQL extends Variant {
|
|
|
3404
2522
|
}
|
|
3405
2523
|
}
|
|
3406
2524
|
|
|
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
|
-
|
|
3547
2525
|
class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
3548
|
-
constructor(
|
|
2526
|
+
constructor(endpoint, authOptions, productRepository) {
|
|
3549
2527
|
super({
|
|
3550
2528
|
tableName: 'category',
|
|
3551
2529
|
model: Category,
|
|
3552
2530
|
endpoint,
|
|
3553
2531
|
authOptions,
|
|
3554
|
-
interceptors,
|
|
3555
2532
|
fields: [
|
|
3556
2533
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
3557
2534
|
{ firestoreId: { columnName: 'firestore_id' } },
|
|
@@ -3560,7 +2537,6 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
3560
2537
|
'image',
|
|
3561
2538
|
'published',
|
|
3562
2539
|
'shop',
|
|
3563
|
-
{ shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
|
|
3564
2540
|
'slug',
|
|
3565
2541
|
{ brandCategory: { columnName: 'brand_category' } },
|
|
3566
2542
|
{ brandCategoryBanner: { columnName: 'brand_banner' } },
|
|
@@ -3589,17 +2565,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
3589
2565
|
},
|
|
3590
2566
|
},
|
|
3591
2567
|
},
|
|
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
|
-
},
|
|
2568
|
+
'filters',
|
|
3603
2569
|
{ createdAt: { columnName: 'created_at' } },
|
|
3604
2570
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
3605
2571
|
{
|
|
@@ -3621,77 +2587,39 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
3621
2587
|
}),
|
|
3622
2588
|
},
|
|
3623
2589
|
},
|
|
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
|
-
},
|
|
3635
2590
|
],
|
|
3636
2591
|
});
|
|
3637
2592
|
this.productRepository = productRepository;
|
|
3638
|
-
this.categoryFilterRepository = categoryFilterRepository;
|
|
3639
2593
|
}
|
|
3640
2594
|
async create(params) {
|
|
3641
2595
|
const { metadata, ...data } = params;
|
|
3642
|
-
return super.create({ ...data,
|
|
2596
|
+
return super.create({ ...data, metadata: metadata || { description: null, title: null } });
|
|
3643
2597
|
}
|
|
3644
2598
|
async get(identifiers) {
|
|
3645
2599
|
return Number.isNaN(+identifiers.id)
|
|
3646
|
-
? (await this.find({ filters: { firestoreId: identifiers.id }
|
|
2600
|
+
? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
|
|
3647
2601
|
: super.get(identifiers);
|
|
3648
2602
|
}
|
|
3649
2603
|
async update(params) {
|
|
3650
|
-
const { products, id: checkId, metadata,
|
|
2604
|
+
const { products, id: checkId, metadata, ...data } = params;
|
|
3651
2605
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
3652
2606
|
const id = await this.getId(plainData.id);
|
|
3653
|
-
const category = await super.update({ id, ...data
|
|
2607
|
+
const category = await super.update({ id, ...data });
|
|
3654
2608
|
category.products = products && (await this.updateProducts(+id, { products }));
|
|
3655
2609
|
category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
3656
|
-
category.filters = filters && (await this.updateFilters(+id, { filters }));
|
|
3657
2610
|
return category;
|
|
3658
2611
|
}
|
|
3659
2612
|
async getCategoryBySlug(slug, shop) {
|
|
3660
2613
|
if (!slug)
|
|
3661
2614
|
return null;
|
|
3662
|
-
const { data } = await this.find({
|
|
3663
|
-
|
|
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)
|
|
3674
|
-
throw new NotFoundError(`Category with slug ${slug} not found`);
|
|
3675
|
-
if (data.length > 1)
|
|
2615
|
+
const { data, count } = await this.find({ filters: { slug, shop, published: true } });
|
|
2616
|
+
if (count > 1)
|
|
3676
2617
|
throw new DuplicatedResultsError('Query returned duplicated values');
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
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;
|
|
2618
|
+
if (!count)
|
|
2619
|
+
throw new NotFoundError(`Category with slug ${slug} not found`);
|
|
2620
|
+
return data.shift();
|
|
3693
2621
|
}
|
|
3694
|
-
async getCategoriesForHome(categoryIds, limit = 4
|
|
2622
|
+
async getCategoriesForHome(categoryIds, limit = 4) {
|
|
3695
2623
|
if (!categoryIds?.length)
|
|
3696
2624
|
return [];
|
|
3697
2625
|
const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
|
|
@@ -3709,7 +2637,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
3709
2637
|
return [];
|
|
3710
2638
|
const homeSections = await Promise.all(categories.map(async (category) => ({
|
|
3711
2639
|
category,
|
|
3712
|
-
products: await this.mountCategory(category, { limit, hasStock: true
|
|
2640
|
+
products: await this.mountCategory(category, { limit, hasStock: true }),
|
|
3713
2641
|
})));
|
|
3714
2642
|
return homeSections;
|
|
3715
2643
|
}
|
|
@@ -3722,7 +2650,6 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
3722
2650
|
id: { operator: Where.IN, value: category.products },
|
|
3723
2651
|
published: true,
|
|
3724
2652
|
...(options?.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {}),
|
|
3725
|
-
...(options?.gender ? { tags: { operator: Where.IN, value: [options?.gender] } } : {}),
|
|
3726
2653
|
},
|
|
3727
2654
|
fields: [
|
|
3728
2655
|
'id',
|
|
@@ -3748,11 +2675,8 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
3748
2675
|
'tags',
|
|
3749
2676
|
'type',
|
|
3750
2677
|
'shoppingCount',
|
|
3751
|
-
'gender',
|
|
3752
|
-
'createdAt',
|
|
3753
2678
|
],
|
|
3754
2679
|
...(options?.limit ? { limits: { limit: options?.limit } } : {}),
|
|
3755
|
-
options: { enableCount: false },
|
|
3756
2680
|
});
|
|
3757
2681
|
products.push(...productsData);
|
|
3758
2682
|
return products;
|
|
@@ -3760,7 +2684,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
3760
2684
|
async getId(id) {
|
|
3761
2685
|
if (!Number.isNaN(+id))
|
|
3762
2686
|
return id;
|
|
3763
|
-
const { data } = await this.find({ filters: { firestoreId: id }
|
|
2687
|
+
const { data } = await this.find({ filters: { firestoreId: id } });
|
|
3764
2688
|
if (data?.[0]?.id)
|
|
3765
2689
|
return data?.[0]?.id;
|
|
3766
2690
|
throw new NotFoundError(`Category with id ${id} not found`);
|
|
@@ -3813,200 +2737,15 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
3813
2737
|
});
|
|
3814
2738
|
return plainData.metadata;
|
|
3815
2739
|
}
|
|
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
|
-
}
|
|
4000
2740
|
}
|
|
4001
2741
|
|
|
4002
2742
|
class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
4003
|
-
constructor(
|
|
2743
|
+
constructor(endpoint, authOptions) {
|
|
4004
2744
|
super({
|
|
4005
2745
|
tableName: 'product',
|
|
4006
2746
|
model: ProductHasuraGraphQL,
|
|
4007
2747
|
endpoint,
|
|
4008
2748
|
authOptions,
|
|
4009
|
-
interceptors,
|
|
4010
2749
|
fields: [],
|
|
4011
2750
|
});
|
|
4012
2751
|
this.bindReviewToModel = (plain) => ({
|
|
@@ -4039,9 +2778,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4039
2778
|
whoMustUse: data.who_must_use,
|
|
4040
2779
|
howToUse: data.how_to_use,
|
|
4041
2780
|
brand: data.brand_description,
|
|
4042
|
-
ingredients: data.ingredients,
|
|
4043
2781
|
}),
|
|
4044
|
-
bindFindFilter: (
|
|
2782
|
+
bindFindFilter: (sentence) => {
|
|
2783
|
+
const filters = Object.values(sentence).shift();
|
|
4045
2784
|
return {
|
|
4046
2785
|
...(filters?.description && { description: filters.description }),
|
|
4047
2786
|
...(filters.differentials && { differentials: filters.differentials }),
|
|
@@ -4054,9 +2793,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4054
2793
|
...(filters.brand && {
|
|
4055
2794
|
brand_description: filters.brand,
|
|
4056
2795
|
}),
|
|
4057
|
-
...(filters.ingredients && {
|
|
4058
|
-
ingredients: filters.ingredients,
|
|
4059
|
-
}),
|
|
4060
2796
|
};
|
|
4061
2797
|
},
|
|
4062
2798
|
bindPersistData: (descriptionData) => ({
|
|
@@ -4067,7 +2803,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4067
2803
|
}),
|
|
4068
2804
|
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
4069
2805
|
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
4070
|
-
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
4071
2806
|
}),
|
|
4072
2807
|
},
|
|
4073
2808
|
},
|
|
@@ -4075,7 +2810,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4075
2810
|
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
4076
2811
|
{ howToUse: { columnName: 'how_to_use' } },
|
|
4077
2812
|
{ brandDescription: { columnName: 'brand_description' } },
|
|
4078
|
-
{ ingredients: { columnName: 'ingredients' } },
|
|
4079
2813
|
{ hasVariants: { columnName: 'has_variants' } },
|
|
4080
2814
|
{
|
|
4081
2815
|
images: {
|
|
@@ -4099,7 +2833,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4099
2833
|
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
4100
2834
|
subscriberPrice: data.subscriber_price,
|
|
4101
2835
|
}),
|
|
4102
|
-
bindFindFilter: (
|
|
2836
|
+
bindFindFilter: (sentence) => {
|
|
2837
|
+
const filters = Object.values(sentence).shift();
|
|
4103
2838
|
return {
|
|
4104
2839
|
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
4105
2840
|
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
@@ -4133,29 +2868,27 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4133
2868
|
to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
|
|
4134
2869
|
},
|
|
4135
2870
|
},
|
|
4136
|
-
{ hasStock: { columnName: 'has_stock' } },
|
|
4137
2871
|
'slug',
|
|
4138
2872
|
'type',
|
|
4139
2873
|
'video',
|
|
4140
2874
|
'weight',
|
|
4141
2875
|
'gender',
|
|
4142
|
-
{ intGender: { columnName: 'int_gender' } },
|
|
4143
2876
|
{ tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
4144
|
-
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
4145
2877
|
{ isKit: { columnName: 'is_kit' } },
|
|
4146
2878
|
{ createdAt: { columnName: 'created_at' } },
|
|
4147
2879
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
4148
|
-
{ rate: { columnName: 'rating' } },
|
|
4149
|
-
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
4150
|
-
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
4151
|
-
{ categoryId: { columnName: 'category_id' } },
|
|
4152
2880
|
{
|
|
4153
|
-
|
|
4154
|
-
columnName: '
|
|
4155
|
-
|
|
4156
|
-
|
|
2881
|
+
rate: {
|
|
2882
|
+
columnName: 'reviews_aggregate',
|
|
2883
|
+
filters: {
|
|
2884
|
+
filters: { status: true },
|
|
2885
|
+
filterType: 'product_review_bool_exp',
|
|
2886
|
+
},
|
|
2887
|
+
fields: [{ aggregate: [{ avg: ['rate'] }] }],
|
|
2888
|
+
from: (value) => value.aggregate.avg.rate,
|
|
4157
2889
|
},
|
|
4158
2890
|
},
|
|
2891
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
4159
2892
|
];
|
|
4160
2893
|
this.fields = [
|
|
4161
2894
|
...commonFields,
|
|
@@ -4232,7 +2965,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4232
2965
|
}
|
|
4233
2966
|
async get(identifiers) {
|
|
4234
2967
|
const product = Number.isNaN(+identifiers.id)
|
|
4235
|
-
? (await this.find({ filters: { firestoreId: identifiers.id }
|
|
2968
|
+
? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
|
|
4236
2969
|
: await super.get(identifiers);
|
|
4237
2970
|
if (product.productId)
|
|
4238
2971
|
throw new NotFoundError('Product not found, it is a variant');
|
|
@@ -4245,25 +2978,10 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4245
2978
|
this.fields
|
|
4246
2979
|
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
4247
2980
|
.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);
|
|
4254
2981
|
return super.find({
|
|
4255
2982
|
...options,
|
|
4256
2983
|
filters: { ...filters, productId: { operator: Where.ISNULL } },
|
|
4257
|
-
fields:
|
|
4258
|
-
...bindFields,
|
|
4259
|
-
...(bindFields.includes('price')
|
|
4260
|
-
? [
|
|
4261
|
-
'subscriberPrice',
|
|
4262
|
-
'subscriberDiscountPercentage',
|
|
4263
|
-
'fullPrice',
|
|
4264
|
-
]
|
|
4265
|
-
: []),
|
|
4266
|
-
],
|
|
2984
|
+
fields: bindFields,
|
|
4267
2985
|
});
|
|
4268
2986
|
}
|
|
4269
2987
|
async getBySlug(slug) {
|
|
@@ -4271,13 +2989,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4271
2989
|
filters: {
|
|
4272
2990
|
slug,
|
|
4273
2991
|
},
|
|
4274
|
-
fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
|
|
4275
|
-
options: {
|
|
4276
|
-
enableCount: false,
|
|
4277
|
-
},
|
|
4278
2992
|
});
|
|
4279
2993
|
const product = result?.data?.shift();
|
|
4280
|
-
|
|
2994
|
+
product.reviews = await this.findReviewsByProduct(+product.id);
|
|
4281
2995
|
return product;
|
|
4282
2996
|
}
|
|
4283
2997
|
async update(params) {
|
|
@@ -4314,17 +3028,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4314
3028
|
})),
|
|
4315
3029
|
], []);
|
|
4316
3030
|
}
|
|
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
|
-
}
|
|
4328
3031
|
async updateCategories(productId, { categories }) {
|
|
4329
3032
|
if ('action' in categories && categories.action === 'remove') {
|
|
4330
3033
|
await this.mutation('delete_category_product', ['affected_rows'], {
|
|
@@ -4438,7 +3141,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4438
3141
|
async getId(id) {
|
|
4439
3142
|
if (!Number.isNaN(+id))
|
|
4440
3143
|
return id;
|
|
4441
|
-
const { data } = await this.find({ filters: { firestoreId: id }
|
|
3144
|
+
const { data } = await this.find({ filters: { firestoreId: id } });
|
|
4442
3145
|
if (data?.[0]?.id)
|
|
4443
3146
|
return data?.[0]?.id;
|
|
4444
3147
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
@@ -4494,29 +3197,15 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4494
3197
|
});
|
|
4495
3198
|
return data && data[0] && this.bindReviewToModel(data[0]);
|
|
4496
3199
|
}
|
|
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
|
-
}
|
|
4510
3200
|
}
|
|
4511
3201
|
|
|
4512
3202
|
class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
4513
|
-
constructor(
|
|
3203
|
+
constructor(endpoint, authOptions) {
|
|
4514
3204
|
super({
|
|
4515
3205
|
tableName: 'product',
|
|
4516
3206
|
model: VariantHasuraGraphQL,
|
|
4517
3207
|
endpoint,
|
|
4518
3208
|
authOptions,
|
|
4519
|
-
interceptors,
|
|
4520
3209
|
fields: [
|
|
4521
3210
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
4522
3211
|
{ firestoreId: { columnName: 'firestore_id' } },
|
|
@@ -4552,12 +3241,12 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4552
3241
|
};
|
|
4553
3242
|
},
|
|
4554
3243
|
bindPersistData: (priceData) => ({
|
|
4555
|
-
...(
|
|
4556
|
-
...(
|
|
4557
|
-
...(
|
|
3244
|
+
...(priceData?.price >= 0 && { price: priceData.price }),
|
|
3245
|
+
...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
|
|
3246
|
+
...(priceData.subscriberDiscountPercentage >= 0 && {
|
|
4558
3247
|
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
4559
3248
|
}),
|
|
4560
|
-
...(
|
|
3249
|
+
...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
4561
3250
|
}),
|
|
4562
3251
|
},
|
|
4563
3252
|
},
|
|
@@ -4572,7 +3261,6 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4572
3261
|
to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
|
|
4573
3262
|
},
|
|
4574
3263
|
},
|
|
4575
|
-
{ hasStock: { columnName: 'has_stock' } },
|
|
4576
3264
|
'weight',
|
|
4577
3265
|
{ name: { to: () => '', from: () => undefined } },
|
|
4578
3266
|
{ hasVariants: { columnName: 'has_variants', to: () => false, from: () => undefined } },
|
|
@@ -4610,247 +3298,16 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
4610
3298
|
async getId(id) {
|
|
4611
3299
|
if (!Number.isNaN(+id))
|
|
4612
3300
|
return id;
|
|
4613
|
-
const { data } = await this.find({ filters: { firestoreId: id }
|
|
3301
|
+
const { data } = await this.find({ filters: { firestoreId: id } });
|
|
4614
3302
|
if (data?.[0]?.id)
|
|
4615
3303
|
return data?.[0]?.id;
|
|
4616
3304
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
4617
3305
|
}
|
|
4618
3306
|
}
|
|
4619
3307
|
|
|
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
|
-
|
|
4851
3308
|
/**
|
|
4852
3309
|
* Generated bundle index. Do not edit.
|
|
4853
3310
|
*/
|
|
4854
3311
|
|
|
4855
|
-
export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository,
|
|
3312
|
+
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, get, is, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
|
|
4856
3313
|
//# sourceMappingURL=infrab4a-connect.mjs.map
|