@medusajs/medusa 1.3.2 → 1.3.3
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/CHANGELOG.md +43 -0
- package/dist/api/index.d.ts +15 -14
- package/dist/api/index.js +15 -14
- package/dist/api/index.js.map +1 -1
- package/dist/api/middlewares/authenticate-customer.d.ts +2 -1
- package/dist/api/middlewares/authenticate-customer.js +1 -2
- package/dist/api/middlewares/authenticate-customer.js.map +1 -1
- package/dist/api/middlewares/authenticate.d.ts +2 -1
- package/dist/api/middlewares/authenticate.js.map +1 -1
- package/dist/api/middlewares/await-middleware.d.ts +3 -1
- package/dist/api/middlewares/await-middleware.js +2 -31
- package/dist/api/middlewares/await-middleware.js.map +1 -1
- package/dist/api/middlewares/error-handler.d.ts +3 -1
- package/dist/api/middlewares/error-handler.js.map +1 -1
- package/dist/api/middlewares/feature-flag-enabled.d.ts +2 -0
- package/dist/api/middlewares/feature-flag-enabled.js +57 -0
- package/dist/api/middlewares/feature-flag-enabled.js.map +1 -0
- package/dist/api/middlewares/index.d.ts +10 -10
- package/dist/api/middlewares/index.js +5 -1
- package/dist/api/middlewares/index.js.map +1 -1
- package/dist/api/middlewares/normalized-query.d.ts +6 -1
- package/dist/api/middlewares/normalized-query.js +5 -2
- package/dist/api/middlewares/normalized-query.js.map +1 -1
- package/dist/api/middlewares/transform-body.d.ts +4 -0
- package/dist/api/middlewares/transform-body.js +66 -0
- package/dist/api/middlewares/transform-body.js.map +1 -0
- package/dist/api/middlewares/transform-query.d.ts +6 -0
- package/dist/api/middlewares/transform-query.js +86 -0
- package/dist/api/middlewares/transform-query.js.map +1 -0
- package/dist/api/routes/admin/batch/cancel-batch-job.d.ts +22 -0
- package/dist/api/routes/admin/batch/cancel-batch-job.js +74 -0
- package/dist/api/routes/admin/batch/cancel-batch-job.js.map +1 -0
- package/dist/api/routes/admin/batch/confirm-batch-job.d.ts +22 -0
- package/dist/api/routes/admin/batch/confirm-batch-job.js +74 -0
- package/dist/api/routes/admin/batch/confirm-batch-job.js.map +1 -0
- package/dist/api/routes/admin/batch/create-batch-job.d.ts +30 -0
- package/dist/api/routes/admin/batch/create-batch-job.js +125 -0
- package/dist/api/routes/admin/batch/create-batch-job.js.map +1 -0
- package/dist/api/routes/admin/batch/get-batch-job.d.ts +22 -0
- package/dist/api/routes/admin/batch/get-batch-job.js +67 -0
- package/dist/api/routes/admin/batch/get-batch-job.js.map +1 -0
- package/dist/api/routes/admin/batch/index.d.ts +4 -0
- package/dist/api/routes/admin/batch/index.js +36 -7
- package/dist/api/routes/admin/batch/index.js.map +1 -1
- package/dist/api/routes/admin/batch/list-batch-jobs.d.ts +15 -7
- package/dist/api/routes/admin/batch/list-batch-jobs.js +61 -46
- package/dist/api/routes/admin/batch/list-batch-jobs.js.map +1 -1
- package/dist/api/routes/admin/collections/add-products.d.ts +2 -1
- package/dist/api/routes/admin/collections/add-products.js +4 -7
- package/dist/api/routes/admin/collections/add-products.js.map +1 -1
- package/dist/api/routes/admin/collections/create-collection.d.ts +2 -1
- package/dist/api/routes/admin/collections/create-collection.js +6 -8
- package/dist/api/routes/admin/collections/create-collection.js.map +1 -1
- package/dist/api/routes/admin/collections/delete-collection.d.ts +2 -1
- package/dist/api/routes/admin/collections/delete-collection.js.map +1 -1
- package/dist/api/routes/admin/collections/get-collection.d.ts +2 -1
- package/dist/api/routes/admin/collections/get-collection.js +4 -5
- package/dist/api/routes/admin/collections/get-collection.js.map +1 -1
- package/dist/api/routes/admin/collections/index.js +32 -12
- package/dist/api/routes/admin/collections/index.js.map +1 -1
- package/dist/api/routes/admin/collections/list-collections.d.ts +2 -1
- package/dist/api/routes/admin/collections/list-collections.js +9 -19
- package/dist/api/routes/admin/collections/list-collections.js.map +1 -1
- package/dist/api/routes/admin/collections/remove-products.d.ts +2 -1
- package/dist/api/routes/admin/collections/remove-products.js +5 -8
- package/dist/api/routes/admin/collections/remove-products.js.map +1 -1
- package/dist/api/routes/admin/collections/update-collection.d.ts +2 -1
- package/dist/api/routes/admin/collections/update-collection.js +5 -8
- package/dist/api/routes/admin/collections/update-collection.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/add-customers-batch.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/add-customers-batch.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/create-customer-group.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/create-customer-group.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/delete-customer-group.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/delete-customer-group.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/delete-customers-batch.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/delete-customers-batch.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/get-customer-group-customers.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/get-customer-group-customers.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/get-customer-group.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/get-customer-group.js +3 -17
- package/dist/api/routes/admin/customer-groups/get-customer-group.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/index.js +29 -11
- package/dist/api/routes/admin/customer-groups/index.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/list-customer-groups.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/list-customer-groups.js +10 -45
- package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/update-customer-group.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/update-customer-group.js.map +1 -1
- package/dist/api/routes/admin/customers/create-customer.d.ts +1 -1
- package/dist/api/routes/admin/customers/create-customer.js.map +1 -1
- package/dist/api/routes/admin/customers/update-customer.d.ts +1 -1
- package/dist/api/routes/admin/customers/update-customer.js.map +1 -1
- package/dist/api/routes/admin/discounts/add-valid-product.d.ts +23 -0
- package/dist/api/routes/admin/discounts/add-valid-product.js +82 -0
- package/dist/api/routes/admin/discounts/add-valid-product.js.map +1 -0
- package/dist/api/routes/admin/discounts/remove-valid-product.d.ts +23 -0
- package/dist/api/routes/admin/discounts/remove-valid-product.js +82 -0
- package/dist/api/routes/admin/discounts/remove-valid-product.js.map +1 -0
- package/dist/api/routes/admin/draft-orders/index.d.ts +1 -1
- package/dist/api/routes/admin/draft-orders/index.js +1 -0
- package/dist/api/routes/admin/draft-orders/index.js.map +1 -1
- package/dist/api/routes/admin/draft-orders/list-draft-orders.js +7 -6
- package/dist/api/routes/admin/draft-orders/list-draft-orders.js.map +1 -1
- package/dist/api/routes/admin/gift-cards/create-gift-card.d.ts +2 -2
- package/dist/api/routes/admin/gift-cards/create-gift-card.js +0 -1
- package/dist/api/routes/admin/gift-cards/create-gift-card.js.map +1 -1
- package/dist/api/routes/admin/gift-cards/index.d.ts +1 -1
- package/dist/api/routes/admin/gift-cards/index.js +19 -5
- package/dist/api/routes/admin/gift-cards/index.js.map +1 -1
- package/dist/api/routes/admin/gift-cards/list-gift-cards.js +24 -18
- package/dist/api/routes/admin/gift-cards/list-gift-cards.js.map +1 -1
- package/dist/api/routes/admin/gift-cards/update-gift-card.d.ts +1 -1
- package/dist/api/routes/admin/gift-cards/update-gift-card.js.map +1 -1
- package/dist/api/routes/admin/orders/create-claim.d.ts +4 -14
- package/dist/api/routes/admin/orders/create-claim.js +3 -14
- package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
- package/dist/api/routes/admin/orders/fulfill-claim.d.ts +1 -1
- package/dist/api/routes/admin/orders/fulfill-claim.js.map +1 -1
- package/dist/api/routes/admin/orders/update-claim.d.ts +1 -1
- package/dist/api/routes/admin/orders/update-claim.js.map +1 -1
- package/dist/api/routes/admin/price-lists/create-price-list.d.ts +2 -1
- package/dist/api/routes/admin/price-lists/create-price-list.js +4 -7
- package/dist/api/routes/admin/price-lists/create-price-list.js.map +1 -1
- package/dist/api/routes/admin/price-lists/index.js +26 -7
- package/dist/api/routes/admin/price-lists/index.js.map +1 -1
- package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +3 -7
- package/dist/api/routes/admin/price-lists/list-price-list-products.js +21 -59
- package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -1
- package/dist/api/routes/admin/price-lists/list-price-lists.d.ts +2 -1
- package/dist/api/routes/admin/price-lists/list-price-lists.js +8 -40
- package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -1
- package/dist/api/routes/admin/products/add-option.js +26 -6
- package/dist/api/routes/admin/products/add-option.js.map +1 -1
- package/dist/api/routes/admin/products/create-product.d.ts +3 -3
- package/dist/api/routes/admin/products/create-product.js +13 -9
- package/dist/api/routes/admin/products/create-product.js.map +1 -1
- package/dist/api/routes/admin/products/delete-variant.js +26 -6
- package/dist/api/routes/admin/products/delete-variant.js.map +1 -1
- package/dist/api/routes/admin/products/get-product.js +24 -4
- package/dist/api/routes/admin/products/get-product.js.map +1 -1
- package/dist/api/routes/admin/products/get-variants.d.ts +24 -0
- package/dist/api/routes/admin/products/get-variants.js +76 -0
- package/dist/api/routes/admin/products/get-variants.js.map +1 -0
- package/dist/api/routes/admin/products/index.d.ts +3 -2
- package/dist/api/routes/admin/products/index.js +1 -4
- package/dist/api/routes/admin/products/index.js.map +1 -1
- package/dist/api/routes/admin/products/list-products.d.ts +1 -6
- package/dist/api/routes/admin/products/list-products.js +3 -9
- package/dist/api/routes/admin/products/list-products.js.map +1 -1
- package/dist/api/routes/admin/products/update-product.d.ts +3 -3
- package/dist/api/routes/admin/products/update-product.js +28 -7
- package/dist/api/routes/admin/products/update-product.js.map +1 -1
- package/dist/api/routes/admin/products/update-variant.js +27 -10
- package/dist/api/routes/admin/products/update-variant.js.map +1 -1
- package/dist/api/routes/admin/shipping-options/list-shipping-options.js +6 -2
- package/dist/api/routes/admin/shipping-options/list-shipping-options.js.map +1 -1
- package/dist/api/routes/admin/store/get-store.js +4 -2
- package/dist/api/routes/admin/store/get-store.js.map +1 -1
- package/dist/api/routes/admin/store/update-store.d.ts +1 -0
- package/dist/api/routes/admin/store/update-store.js +5 -0
- package/dist/api/routes/admin/store/update-store.js.map +1 -1
- package/dist/api/routes/admin/uploads/create-upload.d.ts +1 -1
- package/dist/api/routes/admin/uploads/create-upload.js +5 -5
- package/dist/api/routes/admin/uploads/create-upload.js.map +1 -1
- package/dist/api/routes/admin/uploads/delete-upload.d.ts +4 -1
- package/dist/api/routes/admin/uploads/delete-upload.js +29 -11
- package/dist/api/routes/admin/uploads/delete-upload.js.map +1 -1
- package/dist/api/routes/admin/uploads/get-download-url.d.ts +28 -0
- package/dist/api/routes/admin/uploads/get-download-url.js +99 -0
- package/dist/api/routes/admin/uploads/get-download-url.js.map +1 -0
- package/dist/api/routes/admin/uploads/index.d.ts +10 -3
- package/dist/api/routes/admin/uploads/index.js +19 -4
- package/dist/api/routes/admin/uploads/index.js.map +1 -1
- package/dist/api/routes/store/carts/add-shipping-method.js +6 -2
- package/dist/api/routes/store/carts/add-shipping-method.js.map +1 -1
- package/dist/api/routes/store/carts/calculate-taxes.js +9 -2
- package/dist/api/routes/store/carts/calculate-taxes.js.map +1 -1
- package/dist/api/routes/store/carts/create-cart.js +6 -2
- package/dist/api/routes/store/carts/create-cart.js.map +1 -1
- package/dist/api/routes/store/carts/create-line-item.js +6 -2
- package/dist/api/routes/store/carts/create-line-item.js.map +1 -1
- package/dist/api/routes/store/carts/create-payment-sessions.js +6 -2
- package/dist/api/routes/store/carts/create-payment-sessions.js.map +1 -1
- package/dist/api/routes/store/carts/decorate-line-items-with-totals.d.ts +5 -0
- package/dist/api/routes/store/carts/decorate-line-items-with-totals.js +71 -0
- package/dist/api/routes/store/carts/decorate-line-items-with-totals.js.map +1 -0
- package/dist/api/routes/store/carts/delete-discount.js +6 -2
- package/dist/api/routes/store/carts/delete-discount.js.map +1 -1
- package/dist/api/routes/store/carts/delete-line-item.js +6 -2
- package/dist/api/routes/store/carts/delete-line-item.js.map +1 -1
- package/dist/api/routes/store/carts/delete-payment-session.js +6 -2
- package/dist/api/routes/store/carts/delete-payment-session.js.map +1 -1
- package/dist/api/routes/store/carts/get-cart.js +6 -2
- package/dist/api/routes/store/carts/get-cart.js.map +1 -1
- package/dist/api/routes/store/carts/refresh-payment-session.js +6 -2
- package/dist/api/routes/store/carts/refresh-payment-session.js.map +1 -1
- package/dist/api/routes/store/carts/set-payment-session.js +6 -2
- package/dist/api/routes/store/carts/set-payment-session.js.map +1 -1
- package/dist/api/routes/store/carts/update-cart.js +6 -2
- package/dist/api/routes/store/carts/update-cart.js.map +1 -1
- package/dist/api/routes/store/carts/update-line-item.js +6 -2
- package/dist/api/routes/store/carts/update-line-item.js.map +1 -1
- package/dist/api/routes/store/carts/update-payment-method.d.ts +38 -0
- package/dist/api/routes/store/carts/update-payment-method.js +122 -0
- package/dist/api/routes/store/carts/update-payment-method.js.map +1 -0
- package/dist/api/routes/store/carts/update-payment-session.js +6 -2
- package/dist/api/routes/store/carts/update-payment-session.js.map +1 -1
- package/dist/api/routes/store/customers/get-payment-methods.js +6 -7
- package/dist/api/routes/store/customers/get-payment-methods.js.map +1 -1
- package/dist/api/routes/store/customers/index.d.ts +1 -1
- package/dist/api/routes/store/customers/index.js.map +1 -1
- package/dist/api/routes/store/customers/update-address.js +1 -1
- package/dist/api/routes/store/customers/update-address.js.map +1 -1
- package/dist/api/routes/store/customers/update-customer.d.ts +1 -1
- package/dist/api/routes/store/customers/update-customer.js.map +1 -1
- package/dist/api/routes/store/gift-cards/index.d.ts +1 -1
- package/dist/api/routes/store/gift-cards/index.js +6 -1
- package/dist/api/routes/store/gift-cards/index.js.map +1 -1
- package/dist/api/routes/store/products/get-product.js +51 -12
- package/dist/api/routes/store/products/get-product.js.map +1 -1
- package/dist/api/routes/store/products/list-products.js +30 -7
- package/dist/api/routes/store/products/list-products.js.map +1 -1
- package/dist/api/routes/store/shipping-options/list-options.js +6 -2
- package/dist/api/routes/store/shipping-options/list-options.js.map +1 -1
- package/dist/api/routes/store/shipping-options/list-shipping-options.js +8 -2
- package/dist/api/routes/store/shipping-options/list-shipping-options.js.map +1 -1
- package/dist/api/routes/store/variants/get-variant.js +51 -12
- package/dist/api/routes/store/variants/get-variant.js.map +1 -1
- package/dist/api/routes/store/variants/list-variants.js +29 -6
- package/dist/api/routes/store/variants/list-variants.js.map +1 -1
- package/dist/commands/migrate.js +29 -14
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/seed.js +14 -10
- package/dist/commands/seed.js.map +1 -1
- package/dist/commands/start.js +1 -1
- package/dist/commands/utils/get-migrations.d.ts +2 -1
- package/dist/commands/utils/get-migrations.js +95 -36
- package/dist/commands/utils/get-migrations.js.map +1 -1
- package/dist/config/index.d.ts +14 -0
- package/dist/config/index.js +40 -0
- package/dist/config/index.js.map +1 -0
- package/dist/controllers/products/admin-list-products.js +16 -8
- package/dist/controllers/products/admin-list-products.js.map +1 -1
- package/dist/helpers/test-request.js +21 -15
- package/dist/helpers/test-request.js.map +1 -1
- package/dist/interfaces/abstract-parser.d.ts +25 -0
- package/dist/interfaces/abstract-parser.js +14 -0
- package/dist/interfaces/abstract-parser.js.map +1 -0
- package/dist/interfaces/base-service.d.ts +66 -0
- package/dist/interfaces/base-service.js +377 -0
- package/dist/interfaces/base-service.js.map +1 -0
- package/dist/interfaces/batch-job-strategy.d.ts +34 -0
- package/dist/interfaces/batch-job-strategy.js +182 -0
- package/dist/interfaces/batch-job-strategy.js.map +1 -0
- package/dist/interfaces/csv-parser.d.ts +46 -0
- package/dist/interfaces/csv-parser.js +15 -0
- package/dist/interfaces/csv-parser.js.map +1 -0
- package/dist/interfaces/file-service.d.ts +66 -0
- package/dist/interfaces/file-service.js +32 -0
- package/dist/interfaces/file-service.js.map +1 -0
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/interfaces/index.js.map +1 -1
- package/dist/loaders/config.js +3 -2
- package/dist/loaders/config.js.map +1 -1
- package/dist/loaders/feature-flags/index.d.ts +6 -0
- package/dist/loaders/feature-flags/index.js +71 -0
- package/dist/loaders/feature-flags/index.js.map +1 -0
- package/dist/loaders/index.d.ts +1 -1
- package/dist/loaders/index.js +8 -5
- package/dist/loaders/index.js.map +1 -1
- package/dist/loaders/plugins.d.ts +4 -3
- package/dist/loaders/plugins.js +71 -34
- package/dist/loaders/plugins.js.map +1 -1
- package/dist/loaders/redis.d.ts +1 -1
- package/dist/loaders/redis.js.map +1 -1
- package/dist/loaders/search-index.js +1 -0
- package/dist/loaders/search-index.js.map +1 -1
- package/dist/loaders/strategies.d.ts +2 -2
- package/dist/loaders/strategies.js +21 -7
- package/dist/loaders/strategies.js.map +1 -1
- package/dist/migrations/1649775522087-add_batch_job_model.js +4 -4
- package/dist/migrations/1649775522087-add_batch_job_model.js.map +1 -1
- package/dist/models/batch-job.d.ts +45 -4
- package/dist/models/batch-job.js +94 -7
- package/dist/models/batch-job.js.map +1 -1
- package/dist/models/customer.d.ts +1 -1
- package/dist/models/customer.js +1 -1
- package/dist/models/customer.js.map +1 -1
- package/dist/models/draft-order.d.ts +1 -2
- package/dist/models/draft-order.js +2 -2
- package/dist/models/draft-order.js.map +1 -1
- package/dist/models/line-item.d.ts +9 -2
- package/dist/models/line-item.js +2 -2
- package/dist/models/line-item.js.map +1 -1
- package/dist/models/product.d.ts +17 -17
- package/dist/models/product.js +34 -34
- package/dist/models/product.js.map +1 -1
- package/dist/models/shipping-method.d.ts +1 -1
- package/dist/models/shipping-method.js +1 -1
- package/dist/models/shipping-method.js.map +1 -1
- package/dist/models/shipping-option.d.ts +1 -1
- package/dist/models/shipping-option.js +1 -1
- package/dist/models/shipping-option.js.map +1 -1
- package/dist/repositories/customer.d.ts +2 -1
- package/dist/repositories/customer.js +18 -7
- package/dist/repositories/customer.js.map +1 -1
- package/dist/repositories/gift-card.d.ts +5 -1
- package/dist/repositories/gift-card.js +124 -29
- package/dist/repositories/gift-card.js.map +1 -1
- package/dist/repositories/image.d.ts +1 -0
- package/dist/repositories/image.js +100 -0
- package/dist/repositories/image.js.map +1 -1
- package/dist/repositories/price-list.js.map +1 -1
- package/dist/repositories/product-tag.d.ts +6 -0
- package/dist/repositories/product-tag.js +113 -0
- package/dist/repositories/product-tag.js.map +1 -1
- package/dist/repositories/product-type.d.ts +5 -0
- package/dist/repositories/product-type.js +64 -0
- package/dist/repositories/product-type.js.map +1 -1
- package/dist/repositories/product-variant.js +4 -5
- package/dist/repositories/product-variant.js.map +1 -1
- package/dist/repositories/product.d.ts +14 -17
- package/dist/repositories/product.js +64 -2
- package/dist/repositories/product.js.map +1 -1
- package/dist/repositories/tax-rate.d.ts +1 -1
- package/dist/repositories/tax-rate.js +2 -9
- package/dist/repositories/tax-rate.js.map +1 -1
- package/dist/services/auth.d.ts +16 -7
- package/dist/services/auth.js +130 -93
- package/dist/services/auth.js.map +1 -1
- package/dist/services/batch-job.d.ts +30 -5
- package/dist/services/batch-job.js +437 -2
- package/dist/services/batch-job.js.map +1 -1
- package/dist/services/cart.js +34 -13
- package/dist/services/cart.js.map +1 -1
- package/dist/services/claim-item.d.ts +23 -27
- package/dist/services/claim-item.js +217 -247
- package/dist/services/claim-item.js.map +1 -1
- package/dist/services/claim.d.ts +89 -71
- package/dist/services/claim.js +911 -879
- package/dist/services/claim.js.map +1 -1
- package/dist/services/csv-parser.d.ts +17 -0
- package/dist/services/csv-parser.js +319 -0
- package/dist/services/csv-parser.js.map +1 -0
- package/dist/services/custom-shipping-option.d.ts +30 -32
- package/dist/services/custom-shipping-option.js +78 -74
- package/dist/services/custom-shipping-option.js.map +1 -1
- package/dist/services/customer.d.ts +48 -50
- package/dist/services/customer.js +465 -428
- package/dist/services/customer.js.map +1 -1
- package/dist/services/discount-condition.d.ts +13 -13
- package/dist/services/discount-condition.js +5 -16
- package/dist/services/discount-condition.js.map +1 -1
- package/dist/services/discount.d.ts +22 -16
- package/dist/services/discount.js +530 -484
- package/dist/services/discount.js.map +1 -1
- package/dist/services/draft-order.d.ts +69 -66
- package/dist/services/draft-order.js +375 -353
- package/dist/services/draft-order.js.map +1 -1
- package/dist/services/event-bus.d.ts +72 -56
- package/dist/services/event-bus.js +122 -99
- package/dist/services/event-bus.js.map +1 -1
- package/dist/services/file.d.ts +14 -0
- package/dist/services/file.js +43 -0
- package/dist/services/file.js.map +1 -0
- package/dist/services/fulfillment.d.ts +63 -64
- package/dist/services/fulfillment.js +200 -194
- package/dist/services/fulfillment.js.map +1 -1
- package/dist/services/gift-card.d.ts +54 -45
- package/dist/services/gift-card.js +239 -221
- package/dist/services/gift-card.js.map +1 -1
- package/dist/services/idempotency-key.d.ts +1 -5
- package/dist/services/idempotency-key.js +2 -5
- package/dist/services/idempotency-key.js.map +1 -1
- package/dist/services/index.d.ts +11 -9
- package/dist/services/index.js +23 -19
- package/dist/services/index.js.map +1 -1
- package/dist/services/line-item.d.ts +3 -2
- package/dist/services/line-item.js +9 -7
- package/dist/services/line-item.js.map +1 -1
- package/dist/services/price-list.d.ts +4 -1
- package/dist/services/price-list.js +7 -4
- package/dist/services/price-list.js.map +1 -1
- package/dist/services/pricing.d.ts +101 -0
- package/dist/services/pricing.js +588 -0
- package/dist/services/pricing.js.map +1 -0
- package/dist/services/product-variant.d.ts +0 -11
- package/dist/services/product-variant.js +28 -138
- package/dist/services/product-variant.js.map +1 -1
- package/dist/services/product.d.ts +107 -145
- package/dist/services/product.js +708 -1036
- package/dist/services/product.js.map +1 -1
- package/dist/services/region.js +4 -4
- package/dist/services/region.js.map +1 -1
- package/dist/services/shipping-option.d.ts +43 -108
- package/dist/services/shipping-option.js +305 -352
- package/dist/services/shipping-option.js.map +1 -1
- package/dist/services/shipping-profile.d.ts +2 -2
- package/dist/services/shipping-profile.js +1 -1
- package/dist/services/store.d.ts +36 -45
- package/dist/services/store.js +207 -217
- package/dist/services/store.js.map +1 -1
- package/dist/services/strategy-resolver.d.ts +13 -0
- package/dist/services/strategy-resolver.js +40 -0
- package/dist/services/strategy-resolver.js.map +1 -0
- package/dist/services/tax-provider.d.ts +7 -3
- package/dist/services/tax-provider.js +6 -6
- package/dist/services/tax-provider.js.map +1 -1
- package/dist/services/tax-rate.d.ts +1 -1
- package/dist/services/tax-rate.js +2 -2
- package/dist/services/tax-rate.js.map +1 -1
- package/dist/services/totals.js.map +1 -1
- package/dist/services/user.d.ts +8 -9
- package/dist/services/user.js +216 -168
- package/dist/services/user.js.map +1 -1
- package/dist/strategies/__fixtures__/order-export-data.d.ts +3 -0
- package/dist/strategies/__fixtures__/order-export-data.js +70 -0
- package/dist/strategies/__fixtures__/order-export-data.js.map +1 -0
- package/dist/strategies/__fixtures__/product-export-data.d.ts +319 -0
- package/dist/strategies/__fixtures__/product-export-data.js +401 -0
- package/dist/strategies/__fixtures__/product-export-data.js.map +1 -0
- package/dist/strategies/batch-jobs/order/export.d.ts +36 -0
- package/dist/strategies/batch-jobs/order/export.js +351 -0
- package/dist/strategies/batch-jobs/order/export.js.map +1 -0
- package/dist/strategies/batch-jobs/order/index.d.ts +29 -0
- package/dist/strategies/batch-jobs/order/index.js +115 -0
- package/dist/strategies/batch-jobs/order/index.js.map +1 -0
- package/dist/strategies/batch-jobs/product/export.d.ts +36 -0
- package/dist/strategies/batch-jobs/product/export.js +546 -0
- package/dist/strategies/batch-jobs/product/export.js.map +1 -0
- package/dist/strategies/batch-jobs/product/index.d.ts +45 -0
- package/dist/strategies/batch-jobs/product/index.js +272 -0
- package/dist/strategies/batch-jobs/product/index.js.map +1 -0
- package/dist/subscribers/batch-job.d.ts +17 -0
- package/dist/subscribers/batch-job.js +96 -0
- package/dist/subscribers/batch-job.js.map +1 -0
- package/dist/types/batch-job.d.ts +23 -2
- package/dist/types/batch-job.js +4 -1
- package/dist/types/batch-job.js.map +1 -1
- package/dist/types/claim.d.ts +67 -0
- package/dist/types/claim.js +3 -0
- package/dist/types/claim.js.map +1 -0
- package/dist/types/common.d.ts +27 -3
- package/dist/types/common.js.map +1 -1
- package/dist/types/customers.d.ts +24 -0
- package/dist/types/customers.js.map +1 -1
- package/dist/types/discount.d.ts +2 -1
- package/dist/types/discount.js.map +1 -1
- package/dist/types/feature-flags.d.ts +9 -0
- package/dist/types/feature-flags.js +3 -0
- package/dist/types/feature-flags.js.map +1 -0
- package/dist/types/fulfillment.d.ts +27 -0
- package/dist/types/fulfillment.js +3 -0
- package/dist/types/fulfillment.js.map +1 -0
- package/dist/types/gift-card.d.ts +21 -0
- package/dist/types/gift-card.js +3 -0
- package/dist/types/gift-card.js.map +1 -0
- package/dist/types/global.d.ts +12 -1
- package/dist/types/price-list.d.ts +9 -0
- package/dist/types/pricing.d.ts +30 -0
- package/dist/types/pricing.js +3 -0
- package/dist/types/pricing.js.map +1 -0
- package/dist/types/product-variant.d.ts +4 -3
- package/dist/types/product-variant.js.map +1 -1
- package/dist/types/product.d.ts +110 -8
- package/dist/types/product.js +8 -11
- package/dist/types/product.js.map +1 -1
- package/dist/types/shipping-options.d.ts +62 -0
- package/dist/types/shipping-options.js +3 -0
- package/dist/types/shipping-options.js.map +1 -0
- package/dist/types/store.d.ts +9 -0
- package/dist/types/store.js +3 -0
- package/dist/types/store.js.map +1 -0
- package/dist/utils/build-query.d.ts +7 -7
- package/dist/utils/build-query.js +9 -5
- package/dist/utils/build-query.js.map +1 -1
- package/dist/utils/countries.d.ts +3 -2
- package/dist/utils/countries.js.map +1 -1
- package/dist/utils/currencies.d.ts +10 -1899
- package/dist/utils/currencies.js.map +1 -1
- package/dist/utils/db-aware-column.js +2 -2
- package/dist/utils/db-aware-column.js.map +1 -1
- package/dist/utils/feature-flag-decorators.d.ts +4 -0
- package/dist/utils/feature-flag-decorators.js +52 -0
- package/dist/utils/feature-flag-decorators.js.map +1 -0
- package/dist/utils/flag-router.d.ts +7 -0
- package/dist/utils/flag-router.js +19 -0
- package/dist/utils/flag-router.js.map +1 -0
- package/dist/utils/format-registration-name.d.ts +4 -4
- package/dist/utils/format-registration-name.js +7 -10
- package/dist/utils/format-registration-name.js.map +1 -1
- package/dist/utils/get-query-config.d.ts +4 -6
- package/dist/utils/get-query-config.js +46 -1
- package/dist/utils/get-query-config.js.map +1 -1
- package/dist/utils/omit-relation-if-exists.d.ts +7 -0
- package/dist/utils/omit-relation-if-exists.js +16 -0
- package/dist/utils/omit-relation-if-exists.js.map +1 -0
- package/dist/utils/set-metadata.d.ts +6 -6
- package/dist/utils/set-metadata.js +5 -5
- package/dist/utils/set-metadata.js.map +1 -1
- package/dist/utils/sleep.d.ts +1 -0
- package/dist/utils/sleep.js +50 -0
- package/dist/utils/sleep.js.map +1 -0
- package/package.json +6 -4
- package/yarn-error.log +29038 -0
package/dist/services/product.js
CHANGED
|
@@ -110,78 +110,46 @@ var __values = (this && this.__values) || function(o) {
|
|
|
110
110
|
};
|
|
111
111
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
112
112
|
var medusa_core_utils_1 = require("medusa-core-utils");
|
|
113
|
-
var
|
|
114
|
-
var
|
|
113
|
+
var interfaces_1 = require("../interfaces");
|
|
114
|
+
var utils_1 = require("../utils");
|
|
115
115
|
var exception_formatter_1 = require("../utils/exception-formatter");
|
|
116
|
-
var products_1 = require("../api/routes/admin/products");
|
|
117
|
-
/**
|
|
118
|
-
* Provides layer to manipulate products.
|
|
119
|
-
* @extends BaseService
|
|
120
|
-
*/
|
|
121
116
|
var ProductService = /** @class */ (function (_super) {
|
|
122
117
|
__extends(ProductService, _super);
|
|
123
118
|
function ProductService(_a) {
|
|
124
|
-
var manager = _a.manager, productRepository = _a.productRepository, productVariantRepository = _a.productVariantRepository, productOptionRepository = _a.productOptionRepository, eventBusService = _a.eventBusService, productVariantService = _a.productVariantService,
|
|
125
|
-
var _this = _super.call(this
|
|
126
|
-
|
|
119
|
+
var manager = _a.manager, productRepository = _a.productRepository, productVariantRepository = _a.productVariantRepository, productOptionRepository = _a.productOptionRepository, eventBusService = _a.eventBusService, productVariantService = _a.productVariantService, productTypeRepository = _a.productTypeRepository, productTagRepository = _a.productTagRepository, imageRepository = _a.imageRepository, searchService = _a.searchService;
|
|
120
|
+
var _this = _super.call(this, {
|
|
121
|
+
manager: manager,
|
|
122
|
+
productRepository: productRepository,
|
|
123
|
+
productVariantRepository: productVariantRepository,
|
|
124
|
+
productOptionRepository: productOptionRepository,
|
|
125
|
+
eventBusService: eventBusService,
|
|
126
|
+
productVariantService: productVariantService,
|
|
127
|
+
productTypeRepository: productTypeRepository,
|
|
128
|
+
productTagRepository: productTagRepository,
|
|
129
|
+
imageRepository: imageRepository,
|
|
130
|
+
searchService: searchService,
|
|
131
|
+
}) || this;
|
|
127
132
|
_this.manager_ = manager;
|
|
128
|
-
/** @private @const {ProductOption} */
|
|
129
133
|
_this.productOptionRepository_ = productOptionRepository;
|
|
130
|
-
/** @private @const {Product} */
|
|
131
134
|
_this.productRepository_ = productRepository;
|
|
132
|
-
/** @private @const {ProductVariant} */
|
|
133
135
|
_this.productVariantRepository_ = productVariantRepository;
|
|
134
|
-
/** @private @const {EventBus} */
|
|
135
136
|
_this.eventBus_ = eventBusService;
|
|
136
|
-
/** @private @const {ProductVariantService} */
|
|
137
137
|
_this.productVariantService_ = productVariantService;
|
|
138
|
-
/** @private @const {ProductCollectionService} */
|
|
139
|
-
_this.productCollectionService_ = productCollectionService;
|
|
140
|
-
/** @private @const {ProductCollectionService} */
|
|
141
138
|
_this.productTypeRepository_ = productTypeRepository;
|
|
142
|
-
/** @private @const {ProductCollectionService} */
|
|
143
139
|
_this.productTagRepository_ = productTagRepository;
|
|
144
|
-
/** @private @const {ImageRepository} */
|
|
145
140
|
_this.imageRepository_ = imageRepository;
|
|
146
|
-
/** @private @const {SearchService} */
|
|
147
141
|
_this.searchService_ = searchService;
|
|
148
|
-
/** @private @const {CartRepository} */
|
|
149
|
-
_this.cartRepository_ = cartRepository;
|
|
150
|
-
/** @private @const {IPriceSelectionStrategy} */
|
|
151
|
-
_this.priceSelectionStrategy_ = priceSelectionStrategy;
|
|
152
142
|
return _this;
|
|
153
143
|
}
|
|
154
|
-
ProductService.prototype.withTransaction = function (transactionManager) {
|
|
155
|
-
if (!transactionManager) {
|
|
156
|
-
return this;
|
|
157
|
-
}
|
|
158
|
-
var cloned = new ProductService({
|
|
159
|
-
manager: transactionManager,
|
|
160
|
-
productRepository: this.productRepository_,
|
|
161
|
-
productVariantRepository: this.productVariantRepository_,
|
|
162
|
-
productOptionRepository: this.productOptionRepository_,
|
|
163
|
-
eventBusService: this.eventBus_,
|
|
164
|
-
productVariantService: this.productVariantService_,
|
|
165
|
-
productCollectionService: this.productCollectionService_,
|
|
166
|
-
productTagRepository: this.productTagRepository_,
|
|
167
|
-
productTypeRepository: this.productTypeRepository_,
|
|
168
|
-
imageRepository: this.imageRepository_,
|
|
169
|
-
cartRepository: this.cartRepository_,
|
|
170
|
-
priceSelectionStrategy: this.priceSelectionStrategy_,
|
|
171
|
-
});
|
|
172
|
-
cloned.transactionManager_ = transactionManager;
|
|
173
|
-
return cloned;
|
|
174
|
-
};
|
|
175
144
|
/**
|
|
176
145
|
* Lists products based on the provided parameters.
|
|
177
|
-
* @param
|
|
146
|
+
* @param selector - an object that defines rules to filter products
|
|
178
147
|
* by
|
|
179
|
-
* @param
|
|
148
|
+
* @param config - object that defines the scope for what should be
|
|
180
149
|
* returned
|
|
181
|
-
* @return
|
|
150
|
+
* @return the result of the find operation
|
|
182
151
|
*/
|
|
183
152
|
ProductService.prototype.list = function (selector, config) {
|
|
184
|
-
var _a, _b, _c;
|
|
185
153
|
if (selector === void 0) { selector = {}; }
|
|
186
154
|
if (config === void 0) { config = {
|
|
187
155
|
relations: [],
|
|
@@ -190,34 +158,27 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
190
158
|
include_discount_prices: false,
|
|
191
159
|
}; }
|
|
192
160
|
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
-
var
|
|
194
|
-
return __generator(this, function (
|
|
195
|
-
switch (
|
|
196
|
-
case 0:
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
case 3:
|
|
215
|
-
_e = _f.sent();
|
|
216
|
-
return [3 /*break*/, 5];
|
|
217
|
-
case 4:
|
|
218
|
-
_e = products;
|
|
219
|
-
_f.label = 5;
|
|
220
|
-
case 5: return [2 /*return*/, _e];
|
|
161
|
+
var _this = this;
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
switch (_a.label) {
|
|
164
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
165
|
+
var productRepo, _a, q, query, relations, _b, products;
|
|
166
|
+
return __generator(this, function (_c) {
|
|
167
|
+
switch (_c.label) {
|
|
168
|
+
case 0:
|
|
169
|
+
productRepo = manager.getCustomRepository(this.productRepository_);
|
|
170
|
+
_a = this.prepareListQuery_(selector, config), q = _a.q, query = _a.query, relations = _a.relations;
|
|
171
|
+
if (!q) return [3 /*break*/, 2];
|
|
172
|
+
return [4 /*yield*/, productRepo.getFreeTextSearchResultsAndCount(q, query, relations)];
|
|
173
|
+
case 1:
|
|
174
|
+
_b = __read.apply(void 0, [_c.sent(), 1]), products = _b[0];
|
|
175
|
+
return [2 /*return*/, products];
|
|
176
|
+
case 2: return [4 /*yield*/, productRepo.findWithRelations(relations, query)];
|
|
177
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}); })];
|
|
181
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
221
182
|
}
|
|
222
183
|
});
|
|
223
184
|
});
|
|
@@ -225,17 +186,15 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
225
186
|
/**
|
|
226
187
|
* Lists products based on the provided parameters and includes the count of
|
|
227
188
|
* products that match the query.
|
|
228
|
-
* @param
|
|
189
|
+
* @param selector - an object that defines rules to filter products
|
|
229
190
|
* by
|
|
230
|
-
* @param
|
|
191
|
+
* @param config - object that defines the scope for what should be
|
|
231
192
|
* returned
|
|
232
|
-
* @return
|
|
193
|
+
* @return an array containing the products as
|
|
233
194
|
* the first element and the total count of products that matches the query
|
|
234
195
|
* as the second element.
|
|
235
196
|
*/
|
|
236
197
|
ProductService.prototype.listAndCount = function (selector, config) {
|
|
237
|
-
var _a, _b, _c;
|
|
238
|
-
if (selector === void 0) { selector = {}; }
|
|
239
198
|
if (config === void 0) { config = {
|
|
240
199
|
relations: [],
|
|
241
200
|
skip: 0,
|
|
@@ -243,35 +202,25 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
243
202
|
include_discount_prices: false,
|
|
244
203
|
}; }
|
|
245
204
|
return __awaiter(this, void 0, void 0, function () {
|
|
246
|
-
var
|
|
247
|
-
return __generator(this, function (
|
|
248
|
-
switch (
|
|
249
|
-
case 0:
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return [2 /*return*/, [products_2, count_1]];
|
|
266
|
-
case 3: return [4 /*yield*/, productRepo.findWithRelationsAndCount(relations, query)];
|
|
267
|
-
case 4:
|
|
268
|
-
_f = __read.apply(void 0, [_g.sent(), 2]), products = _f[0], count = _f[1];
|
|
269
|
-
if (!(priceIndex > -1)) return [3 /*break*/, 6];
|
|
270
|
-
return [4 /*yield*/, this.setAdditionalPrices(products, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
|
|
271
|
-
case 5:
|
|
272
|
-
productsWithAdditionalPrices = _g.sent();
|
|
273
|
-
return [2 /*return*/, [productsWithAdditionalPrices, count]];
|
|
274
|
-
case 6: return [2 /*return*/, [products, count]];
|
|
205
|
+
var _this = this;
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
switch (_a.label) {
|
|
208
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
209
|
+
var productRepo, _a, q, query, relations;
|
|
210
|
+
return __generator(this, function (_b) {
|
|
211
|
+
switch (_b.label) {
|
|
212
|
+
case 0:
|
|
213
|
+
productRepo = manager.getCustomRepository(this.productRepository_);
|
|
214
|
+
_a = this.prepareListQuery_(selector, config), q = _a.q, query = _a.query, relations = _a.relations;
|
|
215
|
+
if (!q) return [3 /*break*/, 2];
|
|
216
|
+
return [4 /*yield*/, productRepo.getFreeTextSearchResultsAndCount(q, query, relations)];
|
|
217
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
218
|
+
case 2: return [4 /*yield*/, productRepo.findWithRelationsAndCount(relations, query)];
|
|
219
|
+
case 3: return [2 /*return*/, _b.sent()];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}); })];
|
|
223
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
275
224
|
}
|
|
276
225
|
});
|
|
277
226
|
});
|
|
@@ -283,57 +232,52 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
283
232
|
*/
|
|
284
233
|
ProductService.prototype.count = function (selector) {
|
|
285
234
|
if (selector === void 0) { selector = {}; }
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
235
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
236
|
+
var _this = this;
|
|
237
|
+
return __generator(this, function (_a) {
|
|
238
|
+
switch (_a.label) {
|
|
239
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
240
|
+
var productRepo, query;
|
|
241
|
+
return __generator(this, function (_a) {
|
|
242
|
+
switch (_a.label) {
|
|
243
|
+
case 0:
|
|
244
|
+
productRepo = manager.getCustomRepository(this.productRepository_);
|
|
245
|
+
query = (0, utils_1.buildQuery)(selector);
|
|
246
|
+
return [4 /*yield*/, productRepo.count(query)];
|
|
247
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}); })];
|
|
251
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|
|
289
255
|
};
|
|
290
256
|
/**
|
|
291
257
|
* Gets a product by id.
|
|
292
258
|
* Throws in case of DB Error and if product was not found.
|
|
293
|
-
* @param
|
|
294
|
-
* @param
|
|
259
|
+
* @param productId - id of the product to get.
|
|
260
|
+
* @param config - object that defines what should be included in the
|
|
295
261
|
* query response
|
|
296
|
-
* @return
|
|
262
|
+
* @return the result of the find one operation.
|
|
297
263
|
*/
|
|
298
264
|
ProductService.prototype.retrieve = function (productId, config) {
|
|
299
|
-
|
|
300
|
-
|
|
265
|
+
if (config === void 0) { config = {
|
|
266
|
+
include_discount_prices: false,
|
|
267
|
+
}; }
|
|
301
268
|
return __awaiter(this, void 0, void 0, function () {
|
|
302
|
-
var
|
|
303
|
-
return __generator(this, function (
|
|
304
|
-
switch (
|
|
305
|
-
case 0:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (config.relations && config.relations.length > 0) {
|
|
315
|
-
query.relations = config.relations;
|
|
316
|
-
}
|
|
317
|
-
if (config.select && config.select.length > 0) {
|
|
318
|
-
query.select = config.select;
|
|
319
|
-
}
|
|
320
|
-
rels = query.relations;
|
|
321
|
-
delete query.relations;
|
|
322
|
-
return [4 /*yield*/, productRepo.findOneWithRelations(rels, query)];
|
|
323
|
-
case 1:
|
|
324
|
-
product = _d.sent();
|
|
325
|
-
if (!product) {
|
|
326
|
-
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Product with id: ".concat(productId, " was not found"));
|
|
327
|
-
}
|
|
328
|
-
if (!(priceIndex > -1)) return [3 /*break*/, 3];
|
|
329
|
-
return [4 /*yield*/, this.setAdditionalPrices(product, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
|
|
330
|
-
case 2:
|
|
331
|
-
_c = _d.sent();
|
|
332
|
-
return [3 /*break*/, 4];
|
|
333
|
-
case 3:
|
|
334
|
-
_c = product;
|
|
335
|
-
_d.label = 4;
|
|
336
|
-
case 4: return [2 /*return*/, _c];
|
|
269
|
+
var _this = this;
|
|
270
|
+
return __generator(this, function (_a) {
|
|
271
|
+
switch (_a.label) {
|
|
272
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
273
|
+
return __generator(this, function (_a) {
|
|
274
|
+
switch (_a.label) {
|
|
275
|
+
case 0: return [4 /*yield*/, this.retrieve_({ id: productId }, config)];
|
|
276
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}); })];
|
|
280
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
337
281
|
}
|
|
338
282
|
});
|
|
339
283
|
});
|
|
@@ -341,48 +285,25 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
341
285
|
/**
|
|
342
286
|
* Gets a product by handle.
|
|
343
287
|
* Throws in case of DB Error and if product was not found.
|
|
344
|
-
* @param
|
|
345
|
-
* @param
|
|
346
|
-
* @return
|
|
288
|
+
* @param productHandle - handle of the product to get.
|
|
289
|
+
* @param config - details about what to get from the product
|
|
290
|
+
* @return the result of the find one operation.
|
|
347
291
|
*/
|
|
348
292
|
ProductService.prototype.retrieveByHandle = function (productHandle, config) {
|
|
349
|
-
var _a, _b;
|
|
350
293
|
if (config === void 0) { config = {}; }
|
|
351
294
|
return __awaiter(this, void 0, void 0, function () {
|
|
352
|
-
var
|
|
353
|
-
return __generator(this, function (
|
|
354
|
-
switch (
|
|
355
|
-
case 0:
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
query.relations = config.relations;
|
|
365
|
-
}
|
|
366
|
-
if (config.select && config.select.length > 0) {
|
|
367
|
-
query.select = config.select;
|
|
368
|
-
}
|
|
369
|
-
rels = query.relations;
|
|
370
|
-
delete query.relations;
|
|
371
|
-
return [4 /*yield*/, productRepo.findOneWithRelations(rels, query)];
|
|
372
|
-
case 1:
|
|
373
|
-
product = _d.sent();
|
|
374
|
-
if (!product) {
|
|
375
|
-
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Product with handle: ".concat(productHandle, " was not found"));
|
|
376
|
-
}
|
|
377
|
-
if (!(priceIndex > -1)) return [3 /*break*/, 3];
|
|
378
|
-
return [4 /*yield*/, this.setAdditionalPrices(product, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
|
|
379
|
-
case 2:
|
|
380
|
-
_c = _d.sent();
|
|
381
|
-
return [3 /*break*/, 4];
|
|
382
|
-
case 3:
|
|
383
|
-
_c = product;
|
|
384
|
-
_d.label = 4;
|
|
385
|
-
case 4: return [2 /*return*/, _c];
|
|
295
|
+
var _this = this;
|
|
296
|
+
return __generator(this, function (_a) {
|
|
297
|
+
switch (_a.label) {
|
|
298
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
299
|
+
return __generator(this, function (_a) {
|
|
300
|
+
switch (_a.label) {
|
|
301
|
+
case 0: return [4 /*yield*/, this.retrieve_({ handle: productHandle }, config)];
|
|
302
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}); })];
|
|
306
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
386
307
|
}
|
|
387
308
|
});
|
|
388
309
|
});
|
|
@@ -390,319 +311,246 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
390
311
|
/**
|
|
391
312
|
* Gets a product by external id.
|
|
392
313
|
* Throws in case of DB Error and if product was not found.
|
|
393
|
-
* @param
|
|
394
|
-
* @param
|
|
395
|
-
* @return
|
|
314
|
+
* @param externalId - handle of the product to get.
|
|
315
|
+
* @param config - details about what to get from the product
|
|
316
|
+
* @return the result of the find one operation.
|
|
396
317
|
*/
|
|
397
318
|
ProductService.prototype.retrieveByExternalId = function (externalId, config) {
|
|
398
|
-
var _a, _b;
|
|
399
319
|
if (config === void 0) { config = {}; }
|
|
400
320
|
return __awaiter(this, void 0, void 0, function () {
|
|
401
|
-
var
|
|
402
|
-
return __generator(this, function (
|
|
403
|
-
switch (
|
|
404
|
-
case 0:
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
query.relations = config.relations;
|
|
414
|
-
}
|
|
415
|
-
if (config.select && config.select.length > 0) {
|
|
416
|
-
query.select = config.select;
|
|
417
|
-
}
|
|
418
|
-
rels = query.relations;
|
|
419
|
-
delete query.relations;
|
|
420
|
-
return [4 /*yield*/, productRepo.findOneWithRelations(rels, query)];
|
|
421
|
-
case 1:
|
|
422
|
-
product = _d.sent();
|
|
423
|
-
if (!product) {
|
|
424
|
-
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Product with exteral_id: ".concat(externalId, " was not found"));
|
|
425
|
-
}
|
|
426
|
-
if (!(priceIndex > -1)) return [3 /*break*/, 3];
|
|
427
|
-
return [4 /*yield*/, this.setAdditionalPrices(product, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
|
|
428
|
-
case 2:
|
|
429
|
-
_c = _d.sent();
|
|
430
|
-
return [3 /*break*/, 4];
|
|
431
|
-
case 3:
|
|
432
|
-
_c = product;
|
|
433
|
-
_d.label = 4;
|
|
434
|
-
case 4: return [2 /*return*/, _c];
|
|
321
|
+
var _this = this;
|
|
322
|
+
return __generator(this, function (_a) {
|
|
323
|
+
switch (_a.label) {
|
|
324
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
325
|
+
return __generator(this, function (_a) {
|
|
326
|
+
switch (_a.label) {
|
|
327
|
+
case 0: return [4 /*yield*/, this.retrieve_({ external_id: externalId }, config)];
|
|
328
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}); })];
|
|
332
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
435
333
|
}
|
|
436
334
|
});
|
|
437
335
|
});
|
|
438
336
|
};
|
|
439
337
|
/**
|
|
440
|
-
* Gets
|
|
441
|
-
*
|
|
442
|
-
* @param
|
|
443
|
-
* @
|
|
338
|
+
* Gets a product by selector.
|
|
339
|
+
* Throws in case of DB Error and if product was not found.
|
|
340
|
+
* @param selector - selector object
|
|
341
|
+
* @param config - object that defines what should be included in the
|
|
342
|
+
* query response
|
|
343
|
+
* @return the result of the find one operation.
|
|
444
344
|
*/
|
|
445
|
-
ProductService.prototype.
|
|
345
|
+
ProductService.prototype.retrieve_ = function (selector, config) {
|
|
446
346
|
if (config === void 0) { config = {
|
|
447
|
-
|
|
448
|
-
take: 50,
|
|
449
|
-
relations: products_1.defaultAdminProductsVariantsRelations,
|
|
347
|
+
include_discount_prices: false,
|
|
450
348
|
}; }
|
|
451
349
|
return __awaiter(this, void 0, void 0, function () {
|
|
452
|
-
var
|
|
350
|
+
var _this = this;
|
|
453
351
|
return __generator(this, function (_a) {
|
|
454
352
|
switch (_a.label) {
|
|
455
|
-
case 0: return [4 /*yield*/, this.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
353
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
354
|
+
var productRepo, _a, relations, query, product, selectorConstraints;
|
|
355
|
+
return __generator(this, function (_b) {
|
|
356
|
+
switch (_b.label) {
|
|
357
|
+
case 0:
|
|
358
|
+
productRepo = manager.getCustomRepository(this.productRepository_);
|
|
359
|
+
_a = (0, utils_1.buildQuery)(selector, config), relations = _a.relations, query = __rest(_a, ["relations"]);
|
|
360
|
+
return [4 /*yield*/, productRepo.findOneWithRelations(relations, query)];
|
|
361
|
+
case 1:
|
|
362
|
+
product = _b.sent();
|
|
363
|
+
if (!product) {
|
|
364
|
+
selectorConstraints = Object.entries(selector)
|
|
365
|
+
.map(function (_a) {
|
|
366
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
367
|
+
return "".concat(key, ": ").concat(value);
|
|
368
|
+
})
|
|
369
|
+
.join(", ");
|
|
370
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Product with ".concat(selectorConstraints, " was not found"));
|
|
371
|
+
}
|
|
372
|
+
return [2 /*return*/, product];
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}); })];
|
|
376
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
459
377
|
}
|
|
460
378
|
});
|
|
461
379
|
});
|
|
462
380
|
};
|
|
463
|
-
|
|
381
|
+
/**
|
|
382
|
+
* Gets all variants belonging to a product.
|
|
383
|
+
* @param productId - the id of the product to get variants from.
|
|
384
|
+
* @param config - The config to select and configure relations etc...
|
|
385
|
+
* @return an array of variants
|
|
386
|
+
*/
|
|
387
|
+
ProductService.prototype.retrieveVariants = function (productId, config) {
|
|
388
|
+
if (config === void 0) { config = {
|
|
389
|
+
skip: 0,
|
|
390
|
+
take: 50,
|
|
391
|
+
}; }
|
|
464
392
|
return __awaiter(this, void 0, void 0, function () {
|
|
465
|
-
var
|
|
393
|
+
var _this = this;
|
|
466
394
|
return __generator(this, function (_a) {
|
|
467
395
|
switch (_a.label) {
|
|
468
|
-
case 0:
|
|
469
|
-
|
|
470
|
-
|
|
396
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
397
|
+
var givenRelations, requiredRelations, relationsSet, product;
|
|
398
|
+
var _a;
|
|
399
|
+
return __generator(this, function (_b) {
|
|
400
|
+
switch (_b.label) {
|
|
401
|
+
case 0:
|
|
402
|
+
givenRelations = (_a = config.relations) !== null && _a !== void 0 ? _a : [];
|
|
403
|
+
requiredRelations = ["variants"];
|
|
404
|
+
relationsSet = new Set(__spreadArray(__spreadArray([], __read(givenRelations), false), __read(requiredRelations), false));
|
|
405
|
+
return [4 /*yield*/, this.retrieve(productId, __assign(__assign({}, config), { relations: __spreadArray([], __read(relationsSet), false) }))];
|
|
406
|
+
case 1:
|
|
407
|
+
product = _b.sent();
|
|
408
|
+
return [2 /*return*/, product.variants];
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
}); })];
|
|
471
412
|
case 1: return [2 /*return*/, _a.sent()];
|
|
472
413
|
}
|
|
473
414
|
});
|
|
474
415
|
});
|
|
475
416
|
};
|
|
476
|
-
ProductService.prototype.
|
|
477
|
-
if (count === void 0) { count = 10; }
|
|
417
|
+
ProductService.prototype.listTypes = function () {
|
|
478
418
|
return __awaiter(this, void 0, void 0, function () {
|
|
479
|
-
var
|
|
419
|
+
var _this = this;
|
|
480
420
|
return __generator(this, function (_a) {
|
|
481
421
|
switch (_a.label) {
|
|
482
|
-
case 0: return [4 /*yield*/, this.
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
422
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
423
|
+
var productTypeRepository;
|
|
424
|
+
return __generator(this, function (_a) {
|
|
425
|
+
switch (_a.label) {
|
|
426
|
+
case 0:
|
|
427
|
+
productTypeRepository = manager.getCustomRepository(this.productTypeRepository_);
|
|
428
|
+
return [4 /*yield*/, productTypeRepository.find({})];
|
|
429
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
}); })];
|
|
433
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
486
434
|
}
|
|
487
435
|
});
|
|
488
436
|
});
|
|
489
437
|
};
|
|
490
|
-
ProductService.prototype.
|
|
438
|
+
ProductService.prototype.listTagsByUsage = function (count) {
|
|
439
|
+
if (count === void 0) { count = 10; }
|
|
491
440
|
return __awaiter(this, void 0, void 0, function () {
|
|
492
|
-
var
|
|
441
|
+
var _this = this;
|
|
493
442
|
return __generator(this, function (_a) {
|
|
494
443
|
switch (_a.label) {
|
|
495
|
-
case 0:
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
}
|
|
508
|
-
created = productTypeRepository.create({
|
|
509
|
-
value: type.value,
|
|
510
|
-
});
|
|
511
|
-
return [4 /*yield*/, productTypeRepository.save(created)];
|
|
512
|
-
case 2:
|
|
513
|
-
result = _a.sent();
|
|
514
|
-
return [2 /*return*/, result.id];
|
|
515
|
-
}
|
|
516
|
-
});
|
|
517
|
-
});
|
|
518
|
-
};
|
|
519
|
-
ProductService.prototype.upsertProductTags_ = function (tags) {
|
|
520
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
521
|
-
var productTagRepository, newTags, tags_1, tags_1_1, tag, existing, created, result, e_1_1;
|
|
522
|
-
var e_1, _a;
|
|
523
|
-
return __generator(this, function (_b) {
|
|
524
|
-
switch (_b.label) {
|
|
525
|
-
case 0:
|
|
526
|
-
productTagRepository = this.manager_.getCustomRepository(this.productTagRepository_);
|
|
527
|
-
newTags = [];
|
|
528
|
-
_b.label = 1;
|
|
529
|
-
case 1:
|
|
530
|
-
_b.trys.push([1, 8, 9, 10]);
|
|
531
|
-
tags_1 = __values(tags), tags_1_1 = tags_1.next();
|
|
532
|
-
_b.label = 2;
|
|
533
|
-
case 2:
|
|
534
|
-
if (!!tags_1_1.done) return [3 /*break*/, 7];
|
|
535
|
-
tag = tags_1_1.value;
|
|
536
|
-
return [4 /*yield*/, productTagRepository.findOne({
|
|
537
|
-
where: { value: tag.value },
|
|
538
|
-
})];
|
|
539
|
-
case 3:
|
|
540
|
-
existing = _b.sent();
|
|
541
|
-
if (!existing) return [3 /*break*/, 4];
|
|
542
|
-
newTags.push(existing);
|
|
543
|
-
return [3 /*break*/, 6];
|
|
544
|
-
case 4:
|
|
545
|
-
created = productTagRepository.create(tag);
|
|
546
|
-
return [4 /*yield*/, productTagRepository.save(created)];
|
|
547
|
-
case 5:
|
|
548
|
-
result = _b.sent();
|
|
549
|
-
newTags.push(result);
|
|
550
|
-
_b.label = 6;
|
|
551
|
-
case 6:
|
|
552
|
-
tags_1_1 = tags_1.next();
|
|
553
|
-
return [3 /*break*/, 2];
|
|
554
|
-
case 7: return [3 /*break*/, 10];
|
|
555
|
-
case 8:
|
|
556
|
-
e_1_1 = _b.sent();
|
|
557
|
-
e_1 = { error: e_1_1 };
|
|
558
|
-
return [3 /*break*/, 10];
|
|
559
|
-
case 9:
|
|
560
|
-
try {
|
|
561
|
-
if (tags_1_1 && !tags_1_1.done && (_a = tags_1.return)) _a.call(tags_1);
|
|
562
|
-
}
|
|
563
|
-
finally { if (e_1) throw e_1.error; }
|
|
564
|
-
return [7 /*endfinally*/];
|
|
565
|
-
case 10: return [2 /*return*/, newTags];
|
|
444
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
445
|
+
var productTagRepo;
|
|
446
|
+
return __generator(this, function (_a) {
|
|
447
|
+
switch (_a.label) {
|
|
448
|
+
case 0:
|
|
449
|
+
productTagRepo = manager.getCustomRepository(this.productTagRepository_);
|
|
450
|
+
return [4 /*yield*/, productTagRepo.listTagsByUsage(count)];
|
|
451
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}); })];
|
|
455
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
566
456
|
}
|
|
567
457
|
});
|
|
568
458
|
});
|
|
569
459
|
};
|
|
570
460
|
/**
|
|
571
461
|
* Creates a product.
|
|
572
|
-
* @param
|
|
573
|
-
* @return
|
|
462
|
+
* @param productObject - the product to create
|
|
463
|
+
* @return resolves to the creation result.
|
|
574
464
|
*/
|
|
575
465
|
ProductService.prototype.create = function (productObject) {
|
|
576
466
|
return __awaiter(this, void 0, void 0, function () {
|
|
577
467
|
var _this = this;
|
|
578
468
|
return __generator(this, function (_a) {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
rest.
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
var e_2, _a;
|
|
665
|
-
return __generator(this, function (_b) {
|
|
666
|
-
switch (_b.label) {
|
|
667
|
-
case 0:
|
|
668
|
-
imageRepository = this.manager_.getCustomRepository(this.imageRepository_);
|
|
669
|
-
productImages = [];
|
|
670
|
-
_b.label = 1;
|
|
671
|
-
case 1:
|
|
672
|
-
_b.trys.push([1, 6, 7, 8]);
|
|
673
|
-
images_1 = __values(images), images_1_1 = images_1.next();
|
|
674
|
-
_b.label = 2;
|
|
675
|
-
case 2:
|
|
676
|
-
if (!!images_1_1.done) return [3 /*break*/, 5];
|
|
677
|
-
img = images_1_1.value;
|
|
678
|
-
return [4 /*yield*/, imageRepository.findOne({
|
|
679
|
-
where: { url: img },
|
|
680
|
-
})];
|
|
681
|
-
case 3:
|
|
682
|
-
existing = _b.sent();
|
|
683
|
-
if (existing) {
|
|
684
|
-
productImages.push(existing);
|
|
685
|
-
}
|
|
686
|
-
else {
|
|
687
|
-
created = imageRepository.create({ url: img });
|
|
688
|
-
productImages.push(created);
|
|
689
|
-
}
|
|
690
|
-
_b.label = 4;
|
|
691
|
-
case 4:
|
|
692
|
-
images_1_1 = images_1.next();
|
|
693
|
-
return [3 /*break*/, 2];
|
|
694
|
-
case 5: return [3 /*break*/, 8];
|
|
695
|
-
case 6:
|
|
696
|
-
e_2_1 = _b.sent();
|
|
697
|
-
e_2 = { error: e_2_1 };
|
|
698
|
-
return [3 /*break*/, 8];
|
|
699
|
-
case 7:
|
|
700
|
-
try {
|
|
701
|
-
if (images_1_1 && !images_1_1.done && (_a = images_1.return)) _a.call(images_1);
|
|
702
|
-
}
|
|
703
|
-
finally { if (e_2) throw e_2.error; }
|
|
704
|
-
return [7 /*endfinally*/];
|
|
705
|
-
case 8: return [2 /*return*/, productImages];
|
|
469
|
+
switch (_a.label) {
|
|
470
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
471
|
+
var productRepo, productTagRepo, productTypeRepo, imageRepo, optionRepo, options, tags, type, images, rest, product_1, _a, _b, _c, _d, result, error_1;
|
|
472
|
+
var _this = this;
|
|
473
|
+
var _e;
|
|
474
|
+
return __generator(this, function (_f) {
|
|
475
|
+
switch (_f.label) {
|
|
476
|
+
case 0:
|
|
477
|
+
productRepo = manager.getCustomRepository(this.productRepository_);
|
|
478
|
+
productTagRepo = manager.getCustomRepository(this.productTagRepository_);
|
|
479
|
+
productTypeRepo = manager.getCustomRepository(this.productTypeRepository_);
|
|
480
|
+
imageRepo = manager.getCustomRepository(this.imageRepository_);
|
|
481
|
+
optionRepo = manager.getCustomRepository(this.productOptionRepository_);
|
|
482
|
+
options = productObject.options, tags = productObject.tags, type = productObject.type, images = productObject.images, rest = __rest(productObject, ["options", "tags", "type", "images"]);
|
|
483
|
+
if (!rest.thumbnail && (images === null || images === void 0 ? void 0 : images.length)) {
|
|
484
|
+
rest.thumbnail = images[0];
|
|
485
|
+
}
|
|
486
|
+
// if product is a giftcard, we should disallow discounts
|
|
487
|
+
if (rest.is_giftcard) {
|
|
488
|
+
rest.discountable = false;
|
|
489
|
+
}
|
|
490
|
+
_f.label = 1;
|
|
491
|
+
case 1:
|
|
492
|
+
_f.trys.push([1, 12, , 13]);
|
|
493
|
+
product_1 = productRepo.create(rest);
|
|
494
|
+
if (!(images === null || images === void 0 ? void 0 : images.length)) return [3 /*break*/, 3];
|
|
495
|
+
_a = product_1;
|
|
496
|
+
return [4 /*yield*/, imageRepo.upsertImages(images)];
|
|
497
|
+
case 2:
|
|
498
|
+
_a.images = _f.sent();
|
|
499
|
+
_f.label = 3;
|
|
500
|
+
case 3:
|
|
501
|
+
if (!(tags === null || tags === void 0 ? void 0 : tags.length)) return [3 /*break*/, 5];
|
|
502
|
+
_b = product_1;
|
|
503
|
+
return [4 /*yield*/, productTagRepo.upsertTags(tags)];
|
|
504
|
+
case 4:
|
|
505
|
+
_b.tags = _f.sent();
|
|
506
|
+
_f.label = 5;
|
|
507
|
+
case 5:
|
|
508
|
+
if (!(typeof type !== "undefined")) return [3 /*break*/, 7];
|
|
509
|
+
_c = product_1;
|
|
510
|
+
return [4 /*yield*/, productTypeRepo.upsertType(type)];
|
|
511
|
+
case 6:
|
|
512
|
+
_c.type_id = ((_e = (_f.sent())) === null || _e === void 0 ? void 0 : _e.id) || null;
|
|
513
|
+
_f.label = 7;
|
|
514
|
+
case 7: return [4 /*yield*/, productRepo.save(product_1)];
|
|
515
|
+
case 8:
|
|
516
|
+
product_1 = _f.sent();
|
|
517
|
+
_d = product_1;
|
|
518
|
+
return [4 /*yield*/, Promise.all((options !== null && options !== void 0 ? options : []).map(function (option) { return __awaiter(_this, void 0, void 0, function () {
|
|
519
|
+
var res;
|
|
520
|
+
return __generator(this, function (_a) {
|
|
521
|
+
switch (_a.label) {
|
|
522
|
+
case 0:
|
|
523
|
+
res = optionRepo.create(__assign(__assign({}, option), { product_id: product_1.id }));
|
|
524
|
+
return [4 /*yield*/, optionRepo.save(res)];
|
|
525
|
+
case 1:
|
|
526
|
+
_a.sent();
|
|
527
|
+
return [2 /*return*/, res];
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
}); }))];
|
|
531
|
+
case 9:
|
|
532
|
+
_d.options = _f.sent();
|
|
533
|
+
return [4 /*yield*/, this.retrieve(product_1.id, {
|
|
534
|
+
relations: ["options"],
|
|
535
|
+
})];
|
|
536
|
+
case 10:
|
|
537
|
+
result = _f.sent();
|
|
538
|
+
return [4 /*yield*/, this.eventBus_
|
|
539
|
+
.withTransaction(manager)
|
|
540
|
+
.emit(ProductService.Events.CREATED, {
|
|
541
|
+
id: result.id,
|
|
542
|
+
})];
|
|
543
|
+
case 11:
|
|
544
|
+
_f.sent();
|
|
545
|
+
return [2 /*return*/, result];
|
|
546
|
+
case 12:
|
|
547
|
+
error_1 = _f.sent();
|
|
548
|
+
throw (0, exception_formatter_1.formatException)(error_1);
|
|
549
|
+
case 13: return [2 /*return*/];
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}); })];
|
|
553
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
706
554
|
}
|
|
707
555
|
});
|
|
708
556
|
});
|
|
@@ -720,221 +568,231 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
720
568
|
return __awaiter(this, void 0, void 0, function () {
|
|
721
569
|
var _this = this;
|
|
722
570
|
return __generator(this, function (_a) {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
return
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
571
|
+
switch (_a.label) {
|
|
572
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
573
|
+
var productRepo, productVariantRepo, productTagRepo, productTypeRepo, imageRepo, product, variants, metadata, images, tags, type, rest, _a, _b, _c, _loop_1, _d, _e, variant, e_1_1, newVariants, _loop_2, this_1, _f, _g, _h, i, newVariant, e_2_1, _j, _k, _l, key, value, result;
|
|
574
|
+
var e_1, _m, e_2, _o, e_3, _p;
|
|
575
|
+
var _q;
|
|
576
|
+
return __generator(this, function (_r) {
|
|
577
|
+
switch (_r.label) {
|
|
578
|
+
case 0:
|
|
579
|
+
productRepo = manager.getCustomRepository(this.productRepository_);
|
|
580
|
+
productVariantRepo = manager.getCustomRepository(this.productVariantRepository_);
|
|
581
|
+
productTagRepo = manager.getCustomRepository(this.productTagRepository_);
|
|
582
|
+
productTypeRepo = manager.getCustomRepository(this.productTypeRepository_);
|
|
583
|
+
imageRepo = manager.getCustomRepository(this.imageRepository_);
|
|
584
|
+
return [4 /*yield*/, this.retrieve(productId, {
|
|
585
|
+
relations: ["variants", "tags", "images"],
|
|
586
|
+
})];
|
|
587
|
+
case 1:
|
|
588
|
+
product = _r.sent();
|
|
589
|
+
variants = update.variants, metadata = update.metadata, images = update.images, tags = update.tags, type = update.type, rest = __rest(update, ["variants", "metadata", "images", "tags", "type"]);
|
|
590
|
+
if (!product.thumbnail && !update.thumbnail && (images === null || images === void 0 ? void 0 : images.length)) {
|
|
591
|
+
product.thumbnail = images[0];
|
|
592
|
+
}
|
|
593
|
+
if (!images) return [3 /*break*/, 3];
|
|
594
|
+
_a = product;
|
|
595
|
+
return [4 /*yield*/, imageRepo.upsertImages(images)];
|
|
596
|
+
case 2:
|
|
597
|
+
_a.images = _r.sent();
|
|
598
|
+
_r.label = 3;
|
|
599
|
+
case 3:
|
|
600
|
+
if (metadata) {
|
|
601
|
+
product.metadata = (0, utils_1.setMetadata)(product, metadata);
|
|
602
|
+
}
|
|
603
|
+
if (!(typeof type !== "undefined")) return [3 /*break*/, 5];
|
|
604
|
+
_b = product;
|
|
605
|
+
return [4 /*yield*/, productTypeRepo.upsertType(type)];
|
|
606
|
+
case 4:
|
|
607
|
+
_b.type_id = ((_q = (_r.sent())) === null || _q === void 0 ? void 0 : _q.id) || null;
|
|
608
|
+
_r.label = 5;
|
|
609
|
+
case 5:
|
|
610
|
+
if (!tags) return [3 /*break*/, 7];
|
|
611
|
+
_c = product;
|
|
612
|
+
return [4 /*yield*/, productTagRepo.upsertTags(tags)];
|
|
613
|
+
case 6:
|
|
614
|
+
_c.tags = _r.sent();
|
|
615
|
+
_r.label = 7;
|
|
616
|
+
case 7:
|
|
617
|
+
if (!variants) return [3 /*break*/, 24];
|
|
618
|
+
_loop_1 = function (variant) {
|
|
619
|
+
var exists;
|
|
620
|
+
return __generator(this, function (_s) {
|
|
621
|
+
switch (_s.label) {
|
|
622
|
+
case 0:
|
|
623
|
+
exists = variants.find(function (v) { return v.id && variant.id === v.id; });
|
|
624
|
+
if (!!exists) return [3 /*break*/, 2];
|
|
625
|
+
return [4 /*yield*/, productVariantRepo.remove(variant)];
|
|
626
|
+
case 1:
|
|
627
|
+
_s.sent();
|
|
628
|
+
_s.label = 2;
|
|
629
|
+
case 2: return [2 /*return*/];
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
};
|
|
633
|
+
_r.label = 8;
|
|
634
|
+
case 8:
|
|
635
|
+
_r.trys.push([8, 13, 14, 15]);
|
|
636
|
+
_d = __values(product.variants), _e = _d.next();
|
|
637
|
+
_r.label = 9;
|
|
638
|
+
case 9:
|
|
639
|
+
if (!!_e.done) return [3 /*break*/, 12];
|
|
640
|
+
variant = _e.value;
|
|
641
|
+
return [5 /*yield**/, _loop_1(variant)];
|
|
642
|
+
case 10:
|
|
643
|
+
_r.sent();
|
|
644
|
+
_r.label = 11;
|
|
645
|
+
case 11:
|
|
646
|
+
_e = _d.next();
|
|
647
|
+
return [3 /*break*/, 9];
|
|
648
|
+
case 12: return [3 /*break*/, 15];
|
|
649
|
+
case 13:
|
|
650
|
+
e_1_1 = _r.sent();
|
|
651
|
+
e_1 = { error: e_1_1 };
|
|
652
|
+
return [3 /*break*/, 15];
|
|
653
|
+
case 14:
|
|
654
|
+
try {
|
|
655
|
+
if (_e && !_e.done && (_m = _d.return)) _m.call(_d);
|
|
656
|
+
}
|
|
657
|
+
finally { if (e_1) throw e_1.error; }
|
|
658
|
+
return [7 /*endfinally*/];
|
|
659
|
+
case 15:
|
|
660
|
+
newVariants = [];
|
|
661
|
+
_loop_2 = function (i, newVariant) {
|
|
662
|
+
var variant_rank, variant, saved, created;
|
|
663
|
+
return __generator(this, function (_t) {
|
|
664
|
+
switch (_t.label) {
|
|
665
|
+
case 0:
|
|
666
|
+
variant_rank = i;
|
|
667
|
+
if (!newVariant.id) return [3 /*break*/, 2];
|
|
668
|
+
variant = product.variants.find(function (v) { return v.id === newVariant.id; });
|
|
669
|
+
if (!variant) {
|
|
670
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Variant with id: ".concat(newVariant.id, " is not associated with this product"));
|
|
671
|
+
}
|
|
672
|
+
return [4 /*yield*/, this_1.productVariantService_
|
|
673
|
+
.withTransaction(manager)
|
|
674
|
+
.update(variant, __assign(__assign({}, newVariant), { variant_rank: variant_rank, product_id: variant.product_id }))];
|
|
675
|
+
case 1:
|
|
676
|
+
saved = _t.sent();
|
|
677
|
+
newVariants.push(saved);
|
|
678
|
+
return [3 /*break*/, 4];
|
|
679
|
+
case 2: return [4 /*yield*/, this_1.productVariantService_
|
|
820
680
|
.withTransaction(manager)
|
|
821
|
-
.
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
return [
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
case 21:
|
|
855
|
-
e_4_1 = _q.sent();
|
|
856
|
-
e_4 = { error: e_4_1 };
|
|
857
|
-
return [3 /*break*/, 23];
|
|
858
|
-
case 22:
|
|
859
|
-
try {
|
|
860
|
-
if (_g && !_g.done && (_o = _f.return)) _o.call(_f);
|
|
861
|
-
}
|
|
862
|
-
finally { if (e_4) throw e_4.error; }
|
|
863
|
-
return [7 /*endfinally*/];
|
|
864
|
-
case 23:
|
|
865
|
-
product.variants = newVariants;
|
|
866
|
-
_q.label = 24;
|
|
867
|
-
case 24:
|
|
868
|
-
try {
|
|
869
|
-
for (_j = __values(Object.entries(rest)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
870
|
-
_l = __read(_k.value, 2), key = _l[0], value = _l[1];
|
|
871
|
-
if (typeof value !== "undefined") {
|
|
872
|
-
product[key] = value;
|
|
873
|
-
}
|
|
681
|
+
.create(product.id, __assign(__assign({}, newVariant), { variant_rank: variant_rank, options: newVariant.options || [], prices: newVariant.prices || [] }))];
|
|
682
|
+
case 3:
|
|
683
|
+
created = _t.sent();
|
|
684
|
+
newVariants.push(created);
|
|
685
|
+
_t.label = 4;
|
|
686
|
+
case 4: return [2 /*return*/];
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
};
|
|
690
|
+
this_1 = this;
|
|
691
|
+
_r.label = 16;
|
|
692
|
+
case 16:
|
|
693
|
+
_r.trys.push([16, 21, 22, 23]);
|
|
694
|
+
_f = __values(variants.entries()), _g = _f.next();
|
|
695
|
+
_r.label = 17;
|
|
696
|
+
case 17:
|
|
697
|
+
if (!!_g.done) return [3 /*break*/, 20];
|
|
698
|
+
_h = __read(_g.value, 2), i = _h[0], newVariant = _h[1];
|
|
699
|
+
return [5 /*yield**/, _loop_2(i, newVariant)];
|
|
700
|
+
case 18:
|
|
701
|
+
_r.sent();
|
|
702
|
+
_r.label = 19;
|
|
703
|
+
case 19:
|
|
704
|
+
_g = _f.next();
|
|
705
|
+
return [3 /*break*/, 17];
|
|
706
|
+
case 20: return [3 /*break*/, 23];
|
|
707
|
+
case 21:
|
|
708
|
+
e_2_1 = _r.sent();
|
|
709
|
+
e_2 = { error: e_2_1 };
|
|
710
|
+
return [3 /*break*/, 23];
|
|
711
|
+
case 22:
|
|
712
|
+
try {
|
|
713
|
+
if (_g && !_g.done && (_o = _f.return)) _o.call(_f);
|
|
874
714
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
715
|
+
finally { if (e_2) throw e_2.error; }
|
|
716
|
+
return [7 /*endfinally*/];
|
|
717
|
+
case 23:
|
|
718
|
+
product.variants = newVariants;
|
|
719
|
+
_r.label = 24;
|
|
720
|
+
case 24:
|
|
878
721
|
try {
|
|
879
|
-
|
|
722
|
+
for (_j = __values(Object.entries(rest)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
723
|
+
_l = __read(_k.value, 2), key = _l[0], value = _l[1];
|
|
724
|
+
if (typeof value !== "undefined") {
|
|
725
|
+
product[key] = value;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
880
728
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
729
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
730
|
+
finally {
|
|
731
|
+
try {
|
|
732
|
+
if (_k && !_k.done && (_p = _j.return)) _p.call(_j);
|
|
733
|
+
}
|
|
734
|
+
finally { if (e_3) throw e_3.error; }
|
|
735
|
+
}
|
|
736
|
+
return [4 /*yield*/, productRepo.save(product)];
|
|
737
|
+
case 25:
|
|
738
|
+
result = _r.sent();
|
|
739
|
+
return [4 /*yield*/, this.eventBus_
|
|
740
|
+
.withTransaction(manager)
|
|
741
|
+
.emit(ProductService.Events.UPDATED, {
|
|
742
|
+
id: result.id,
|
|
743
|
+
fields: Object.keys(update),
|
|
744
|
+
})];
|
|
745
|
+
case 26:
|
|
746
|
+
_r.sent();
|
|
747
|
+
return [2 /*return*/, result];
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
}); })];
|
|
751
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
752
|
+
}
|
|
898
753
|
});
|
|
899
754
|
});
|
|
900
755
|
};
|
|
901
756
|
/**
|
|
902
757
|
* Deletes a product from a given product id. The product's associated
|
|
903
758
|
* variants will also be deleted.
|
|
904
|
-
* @param
|
|
759
|
+
* @param productId - the id of the product to delete. Must be
|
|
905
760
|
* castable as an ObjectId
|
|
906
|
-
* @return
|
|
761
|
+
* @return empty promise
|
|
907
762
|
*/
|
|
908
763
|
ProductService.prototype.delete = function (productId) {
|
|
909
764
|
return __awaiter(this, void 0, void 0, function () {
|
|
910
765
|
var _this = this;
|
|
911
766
|
return __generator(this, function (_a) {
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
767
|
+
switch (_a.label) {
|
|
768
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
769
|
+
var productRepo, product;
|
|
770
|
+
return __generator(this, function (_a) {
|
|
771
|
+
switch (_a.label) {
|
|
772
|
+
case 0:
|
|
773
|
+
productRepo = manager.getCustomRepository(this.productRepository_);
|
|
774
|
+
return [4 /*yield*/, productRepo.findOne({ id: productId }, { relations: ["variants", "variants.prices", "variants.options"] })];
|
|
775
|
+
case 1:
|
|
776
|
+
product = _a.sent();
|
|
777
|
+
if (!product) {
|
|
778
|
+
return [2 /*return*/];
|
|
779
|
+
}
|
|
780
|
+
return [4 /*yield*/, productRepo.softRemove(product)];
|
|
781
|
+
case 2:
|
|
782
|
+
_a.sent();
|
|
783
|
+
return [4 /*yield*/, this.eventBus_
|
|
784
|
+
.withTransaction(manager)
|
|
785
|
+
.emit(ProductService.Events.DELETED, {
|
|
786
|
+
id: productId,
|
|
787
|
+
})];
|
|
788
|
+
case 3:
|
|
789
|
+
_a.sent();
|
|
790
|
+
return [2 /*return*/, Promise.resolve()];
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
}); })];
|
|
794
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
795
|
+
}
|
|
938
796
|
});
|
|
939
797
|
});
|
|
940
798
|
};
|
|
@@ -942,314 +800,240 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
942
800
|
* Adds an option to a product. Options can, for example, be "Size", "Color",
|
|
943
801
|
* etc. Will update all the products variants with a dummy value for the newly
|
|
944
802
|
* created option. The same option cannot be added more than once.
|
|
945
|
-
* @param
|
|
946
|
-
* @param
|
|
947
|
-
* @return
|
|
803
|
+
* @param productId - the product to apply the new option to
|
|
804
|
+
* @param optionTitle - the display title of the option, e.g. "Size"
|
|
805
|
+
* @return the result of the model update operation
|
|
948
806
|
*/
|
|
949
807
|
ProductService.prototype.addOption = function (productId, optionTitle) {
|
|
950
808
|
return __awaiter(this, void 0, void 0, function () {
|
|
951
809
|
var _this = this;
|
|
952
810
|
return __generator(this, function (_a) {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
return [4 /*yield*/, productOptionRepo.create({
|
|
969
|
-
title: optionTitle,
|
|
970
|
-
product_id: productId,
|
|
971
|
-
})];
|
|
972
|
-
case 2:
|
|
973
|
-
option = _d.sent();
|
|
974
|
-
return [4 /*yield*/, productOptionRepo.save(option)];
|
|
975
|
-
case 3:
|
|
976
|
-
_d.sent();
|
|
977
|
-
try {
|
|
978
|
-
for (_a = __values(product.variants), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
979
|
-
variant = _b.value;
|
|
980
|
-
this.productVariantService_
|
|
981
|
-
.withTransaction(manager)
|
|
982
|
-
.addOptionValue(variant.id, option.id, "Default Value");
|
|
811
|
+
switch (_a.label) {
|
|
812
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
813
|
+
var productOptionRepo, product, option, _a, _b, variant, result;
|
|
814
|
+
var e_4, _c;
|
|
815
|
+
return __generator(this, function (_d) {
|
|
816
|
+
switch (_d.label) {
|
|
817
|
+
case 0:
|
|
818
|
+
productOptionRepo = manager.getCustomRepository(this.productOptionRepository_);
|
|
819
|
+
return [4 /*yield*/, this.retrieve(productId, {
|
|
820
|
+
relations: ["options", "variants"],
|
|
821
|
+
})];
|
|
822
|
+
case 1:
|
|
823
|
+
product = _d.sent();
|
|
824
|
+
if (product.options.find(function (o) { return o.title === optionTitle; })) {
|
|
825
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.DUPLICATE_ERROR, "An option with the title: ".concat(optionTitle, " already exists"));
|
|
983
826
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
827
|
+
return [4 /*yield*/, productOptionRepo.create({
|
|
828
|
+
title: optionTitle,
|
|
829
|
+
product_id: productId,
|
|
830
|
+
})];
|
|
831
|
+
case 2:
|
|
832
|
+
option = _d.sent();
|
|
833
|
+
return [4 /*yield*/, productOptionRepo.save(option)];
|
|
834
|
+
case 3:
|
|
835
|
+
_d.sent();
|
|
987
836
|
try {
|
|
988
|
-
|
|
837
|
+
for (_a = __values(product.variants), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
838
|
+
variant = _b.value;
|
|
839
|
+
this.productVariantService_
|
|
840
|
+
.withTransaction(manager)
|
|
841
|
+
.addOptionValue(variant.id, option.id, "Default Value");
|
|
842
|
+
}
|
|
989
843
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
.withTransaction(manager)
|
|
997
|
-
.emit(ProductService.Events.UPDATED, result)];
|
|
998
|
-
case 5:
|
|
999
|
-
_d.sent();
|
|
1000
|
-
return [2 /*return*/, result];
|
|
1001
|
-
}
|
|
1002
|
-
});
|
|
1003
|
-
}); })];
|
|
1004
|
-
});
|
|
1005
|
-
});
|
|
1006
|
-
};
|
|
1007
|
-
ProductService.prototype.reorderVariants = function (productId, variantOrder) {
|
|
1008
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1009
|
-
var _this = this;
|
|
1010
|
-
return __generator(this, function (_a) {
|
|
1011
|
-
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
1012
|
-
var productRepo, product, result;
|
|
1013
|
-
return __generator(this, function (_a) {
|
|
1014
|
-
switch (_a.label) {
|
|
1015
|
-
case 0:
|
|
1016
|
-
productRepo = manager.getCustomRepository(this.productRepository_);
|
|
1017
|
-
return [4 /*yield*/, this.retrieve(productId, {
|
|
1018
|
-
relations: ["variants"],
|
|
1019
|
-
})];
|
|
1020
|
-
case 1:
|
|
1021
|
-
product = _a.sent();
|
|
1022
|
-
if (product.variants.length !== variantOrder.length) {
|
|
1023
|
-
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Product variants and new variant order differ in length.");
|
|
1024
|
-
}
|
|
1025
|
-
product.variants = variantOrder.map(function (vId) {
|
|
1026
|
-
var variant = product.variants.find(function (v) { return v.id === vId; });
|
|
1027
|
-
if (!variant) {
|
|
1028
|
-
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Product has no variant with id: ".concat(vId));
|
|
844
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
845
|
+
finally {
|
|
846
|
+
try {
|
|
847
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
848
|
+
}
|
|
849
|
+
finally { if (e_4) throw e_4.error; }
|
|
1029
850
|
}
|
|
1030
|
-
return
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
851
|
+
return [4 /*yield*/, this.retrieve(productId)];
|
|
852
|
+
case 4:
|
|
853
|
+
result = _d.sent();
|
|
854
|
+
return [4 /*yield*/, this.eventBus_
|
|
855
|
+
.withTransaction(manager)
|
|
856
|
+
.emit(ProductService.Events.UPDATED, result)];
|
|
857
|
+
case 5:
|
|
858
|
+
_d.sent();
|
|
859
|
+
return [2 /*return*/, result];
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
}); })];
|
|
863
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
864
|
+
}
|
|
1042
865
|
});
|
|
1043
866
|
});
|
|
1044
867
|
};
|
|
1045
|
-
|
|
1046
|
-
* Changes the order of a product's options. Will throw if the length of
|
|
1047
|
-
* optionOrder and the length of the product's options are different. Will
|
|
1048
|
-
* throw optionOrder contains an id not associated with the product.
|
|
1049
|
-
* @param {string} productId - the product whose options we are reordering
|
|
1050
|
-
* @param {string[]} optionOrder - the ids of the product's options in the
|
|
1051
|
-
* new order
|
|
1052
|
-
* @return {Promise} the result of the update operation
|
|
1053
|
-
*/
|
|
1054
|
-
ProductService.prototype.reorderOptions = function (productId, optionOrder) {
|
|
868
|
+
ProductService.prototype.reorderVariants = function (productId, variantOrder) {
|
|
1055
869
|
return __awaiter(this, void 0, void 0, function () {
|
|
1056
870
|
var _this = this;
|
|
1057
871
|
return __generator(this, function (_a) {
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
if (!option) {
|
|
1073
|
-
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Product has no option with id: ".concat(oId));
|
|
872
|
+
switch (_a.label) {
|
|
873
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
874
|
+
var productRepo, product, result;
|
|
875
|
+
return __generator(this, function (_a) {
|
|
876
|
+
switch (_a.label) {
|
|
877
|
+
case 0:
|
|
878
|
+
productRepo = manager.getCustomRepository(this.productRepository_);
|
|
879
|
+
return [4 /*yield*/, this.retrieve(productId, {
|
|
880
|
+
relations: ["variants"],
|
|
881
|
+
})];
|
|
882
|
+
case 1:
|
|
883
|
+
product = _a.sent();
|
|
884
|
+
if (product.variants.length !== variantOrder.length) {
|
|
885
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Product variants and new variant order differ in length.");
|
|
1074
886
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
887
|
+
product.variants = variantOrder.map(function (vId) {
|
|
888
|
+
var variant = product.variants.find(function (v) { return v.id === vId; });
|
|
889
|
+
if (!variant) {
|
|
890
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Product has no variant with id: ".concat(vId));
|
|
891
|
+
}
|
|
892
|
+
return variant;
|
|
893
|
+
});
|
|
894
|
+
result = productRepo.save(product);
|
|
895
|
+
return [4 /*yield*/, this.eventBus_
|
|
896
|
+
.withTransaction(manager)
|
|
897
|
+
.emit(ProductService.Events.UPDATED, result)];
|
|
898
|
+
case 2:
|
|
899
|
+
_a.sent();
|
|
900
|
+
return [2 /*return*/, result];
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
}); })];
|
|
904
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
905
|
+
}
|
|
1087
906
|
});
|
|
1088
907
|
});
|
|
1089
908
|
};
|
|
1090
909
|
/**
|
|
1091
910
|
* Updates a product's option. Throws if the call tries to update an option
|
|
1092
911
|
* not associated with the product. Throws if the updated title already exists.
|
|
1093
|
-
* @param
|
|
1094
|
-
* @param
|
|
1095
|
-
* @param
|
|
1096
|
-
* @return
|
|
912
|
+
* @param productId - the product whose option we are updating
|
|
913
|
+
* @param optionId - the id of the option we are updating
|
|
914
|
+
* @param data - the data to update the option with
|
|
915
|
+
* @return the updated product
|
|
1097
916
|
*/
|
|
1098
917
|
ProductService.prototype.updateOption = function (productId, optionId, data) {
|
|
1099
918
|
return __awaiter(this, void 0, void 0, function () {
|
|
1100
919
|
var _this = this;
|
|
1101
920
|
return __generator(this, function (_a) {
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
921
|
+
switch (_a.label) {
|
|
922
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
923
|
+
var productOptionRepo, product, title, values, optionExists, productOption;
|
|
924
|
+
return __generator(this, function (_a) {
|
|
925
|
+
switch (_a.label) {
|
|
926
|
+
case 0:
|
|
927
|
+
productOptionRepo = manager.getCustomRepository(this.productOptionRepository_);
|
|
928
|
+
return [4 /*yield*/, this.retrieve(productId, { relations: ["options"] })];
|
|
929
|
+
case 1:
|
|
930
|
+
product = _a.sent();
|
|
931
|
+
title = data.title, values = data.values;
|
|
932
|
+
optionExists = product.options.some(function (o) {
|
|
933
|
+
return o.title.toUpperCase() === title.toUpperCase() && o.id !== optionId;
|
|
934
|
+
});
|
|
935
|
+
if (optionExists) {
|
|
936
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "An option with title ".concat(title, " already exists"));
|
|
937
|
+
}
|
|
938
|
+
return [4 /*yield*/, productOptionRepo.findOne({
|
|
939
|
+
where: { id: optionId },
|
|
940
|
+
})];
|
|
941
|
+
case 2:
|
|
942
|
+
productOption = _a.sent();
|
|
943
|
+
if (!productOption) {
|
|
944
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Option with id: ".concat(optionId, " does not exist"));
|
|
945
|
+
}
|
|
946
|
+
productOption.title = title;
|
|
947
|
+
if (values) {
|
|
948
|
+
productOption.values = values;
|
|
949
|
+
}
|
|
950
|
+
return [4 /*yield*/, productOptionRepo.save(productOption)];
|
|
951
|
+
case 3:
|
|
952
|
+
_a.sent();
|
|
953
|
+
return [4 /*yield*/, this.eventBus_
|
|
954
|
+
.withTransaction(manager)
|
|
955
|
+
.emit(ProductService.Events.UPDATED, product)];
|
|
956
|
+
case 4:
|
|
957
|
+
_a.sent();
|
|
958
|
+
return [2 /*return*/, product];
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
}); })];
|
|
962
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
963
|
+
}
|
|
1140
964
|
});
|
|
1141
965
|
});
|
|
1142
966
|
};
|
|
1143
967
|
/**
|
|
1144
968
|
* Delete an option from a product.
|
|
1145
|
-
* @param
|
|
1146
|
-
* @param
|
|
1147
|
-
* @return
|
|
969
|
+
* @param productId - the product to delete an option from
|
|
970
|
+
* @param optionId - the option to delete
|
|
971
|
+
* @return the updated product
|
|
1148
972
|
*/
|
|
1149
973
|
ProductService.prototype.deleteOption = function (productId, optionId) {
|
|
1150
974
|
return __awaiter(this, void 0, void 0, function () {
|
|
1151
975
|
var _this = this;
|
|
1152
976
|
return __generator(this, function (_a) {
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
option
|
|
1179
|
-
return
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
/**
|
|
1205
|
-
* Decorates a product with product variants.
|
|
1206
|
-
* @param {string} productId - the productId to decorate.
|
|
1207
|
-
* @param {string[]} fields - the fields to include.
|
|
1208
|
-
* @param {string[]} expandFields - fields to expand.
|
|
1209
|
-
* @param {object} config - retrieve config for price calculation.
|
|
1210
|
-
* @return {Product} return the decorated product.
|
|
1211
|
-
*/
|
|
1212
|
-
ProductService.prototype.decorate = function (productId, fields, expandFields, config) {
|
|
1213
|
-
var _a;
|
|
1214
|
-
if (fields === void 0) { fields = []; }
|
|
1215
|
-
if (expandFields === void 0) { expandFields = []; }
|
|
1216
|
-
if (config === void 0) { config = {}; }
|
|
1217
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1218
|
-
var requiredFields, priceIndex, product, _b;
|
|
1219
|
-
return __generator(this, function (_c) {
|
|
1220
|
-
switch (_c.label) {
|
|
1221
|
-
case 0:
|
|
1222
|
-
requiredFields = ["id", "metadata"];
|
|
1223
|
-
priceIndex = (_a = expandFields.indexOf("variants.prices")) !== null && _a !== void 0 ? _a : -1;
|
|
1224
|
-
if (priceIndex >= 0 && expandFields.length) {
|
|
1225
|
-
expandFields = __spreadArray([], __read(expandFields), false);
|
|
1226
|
-
expandFields.splice(priceIndex, 1);
|
|
1227
|
-
}
|
|
1228
|
-
fields = fields.concat(requiredFields);
|
|
1229
|
-
return [4 /*yield*/, this.retrieve(productId, {
|
|
1230
|
-
select: fields,
|
|
1231
|
-
relations: expandFields,
|
|
1232
|
-
})];
|
|
1233
|
-
case 1:
|
|
1234
|
-
product = _c.sent();
|
|
1235
|
-
if (!(priceIndex > -1)) return [3 /*break*/, 3];
|
|
1236
|
-
return [4 /*yield*/, this.setAdditionalPrices(product, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
|
|
1237
|
-
case 2:
|
|
1238
|
-
_b = _c.sent();
|
|
1239
|
-
return [3 /*break*/, 4];
|
|
1240
|
-
case 3:
|
|
1241
|
-
_b = product;
|
|
1242
|
-
_c.label = 4;
|
|
1243
|
-
case 4: return [2 /*return*/, _b];
|
|
977
|
+
switch (_a.label) {
|
|
978
|
+
case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
979
|
+
var productOptionRepo, product, productOption, firstVariant, valueToMatch, equalsFirst;
|
|
980
|
+
var _this = this;
|
|
981
|
+
var _a;
|
|
982
|
+
return __generator(this, function (_b) {
|
|
983
|
+
switch (_b.label) {
|
|
984
|
+
case 0:
|
|
985
|
+
productOptionRepo = manager.getCustomRepository(this.productOptionRepository_);
|
|
986
|
+
return [4 /*yield*/, this.retrieve(productId, {
|
|
987
|
+
relations: ["variants", "variants.options"],
|
|
988
|
+
})];
|
|
989
|
+
case 1:
|
|
990
|
+
product = _b.sent();
|
|
991
|
+
return [4 /*yield*/, productOptionRepo.findOne({
|
|
992
|
+
where: { id: optionId, product_id: productId },
|
|
993
|
+
})];
|
|
994
|
+
case 2:
|
|
995
|
+
productOption = _b.sent();
|
|
996
|
+
if (!productOption) {
|
|
997
|
+
return [2 /*return*/, Promise.resolve()];
|
|
998
|
+
}
|
|
999
|
+
firstVariant = product.variants[0];
|
|
1000
|
+
valueToMatch = (_a = firstVariant.options.find(function (o) { return o.option_id === optionId; })) === null || _a === void 0 ? void 0 : _a.value;
|
|
1001
|
+
return [4 /*yield*/, Promise.all(product.variants.map(function (v) { return __awaiter(_this, void 0, void 0, function () {
|
|
1002
|
+
var option;
|
|
1003
|
+
return __generator(this, function (_a) {
|
|
1004
|
+
option = v.options.find(function (o) { return o.option_id === optionId; });
|
|
1005
|
+
return [2 /*return*/, (option === null || option === void 0 ? void 0 : option.value) === valueToMatch];
|
|
1006
|
+
});
|
|
1007
|
+
}); }))];
|
|
1008
|
+
case 3:
|
|
1009
|
+
equalsFirst = _b.sent();
|
|
1010
|
+
if (!equalsFirst.every(function (v) { return v; })) {
|
|
1011
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "To delete an option, first delete all variants, such that when an option is deleted, no duplicate variants will exist.");
|
|
1012
|
+
}
|
|
1013
|
+
// If we reach this point, we can safely delete the product option
|
|
1014
|
+
return [4 /*yield*/, productOptionRepo.softRemove(productOption)];
|
|
1015
|
+
case 4:
|
|
1016
|
+
// If we reach this point, we can safely delete the product option
|
|
1017
|
+
_b.sent();
|
|
1018
|
+
return [4 /*yield*/, this.eventBus_
|
|
1019
|
+
.withTransaction(manager)
|
|
1020
|
+
.emit(ProductService.Events.UPDATED, product)];
|
|
1021
|
+
case 5:
|
|
1022
|
+
_b.sent();
|
|
1023
|
+
return [2 /*return*/, product];
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
}); })];
|
|
1027
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1244
1028
|
}
|
|
1245
1029
|
});
|
|
1246
1030
|
});
|
|
1247
1031
|
};
|
|
1248
1032
|
/**
|
|
1249
1033
|
* Creates a query object to be used for list queries.
|
|
1250
|
-
* @param
|
|
1251
|
-
* @param
|
|
1252
|
-
* @return
|
|
1034
|
+
* @param selector - the selector to create the query from
|
|
1035
|
+
* @param config - the config to use for the query
|
|
1036
|
+
* @return an object containing the query, relations and free-text
|
|
1253
1037
|
* search param.
|
|
1254
1038
|
*/
|
|
1255
1039
|
ProductService.prototype.prepareListQuery_ = function (selector, config) {
|
|
@@ -1258,7 +1042,7 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
1258
1042
|
q = selector.q;
|
|
1259
1043
|
delete selector.q;
|
|
1260
1044
|
}
|
|
1261
|
-
var query =
|
|
1045
|
+
var query = (0, utils_1.buildQuery)(selector, config);
|
|
1262
1046
|
if (config.relations && config.relations.length > 0) {
|
|
1263
1047
|
query.relations = config.relations;
|
|
1264
1048
|
}
|
|
@@ -1273,118 +1057,6 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
1273
1057
|
q: q,
|
|
1274
1058
|
};
|
|
1275
1059
|
};
|
|
1276
|
-
/**
|
|
1277
|
-
* Creates a QueryBuilder that can fetch products based on free text.
|
|
1278
|
-
* @param {ProductRepository} productRepo - an instance of a ProductRepositry
|
|
1279
|
-
* @param {FindOptions<Product>} query - the query to get products by
|
|
1280
|
-
* @param {string} q - the text to perform free text search from
|
|
1281
|
-
* @return {QueryBuilder<Product>} a query builder that can fetch products
|
|
1282
|
-
*/
|
|
1283
|
-
ProductService.prototype.getFreeTextQueryBuilder_ = function (productRepo, query, q) {
|
|
1284
|
-
var where = query.where;
|
|
1285
|
-
delete where.description;
|
|
1286
|
-
delete where.title;
|
|
1287
|
-
var qb = productRepo
|
|
1288
|
-
.createQueryBuilder("product")
|
|
1289
|
-
.leftJoinAndSelect("product.variants", "variant")
|
|
1290
|
-
.leftJoinAndSelect("product.collection", "collection")
|
|
1291
|
-
.select(["product.id"])
|
|
1292
|
-
.where(where)
|
|
1293
|
-
.andWhere(new typeorm_1.Brackets(function (qb) {
|
|
1294
|
-
qb.where("product.description ILIKE :q", { q: "%".concat(q, "%") })
|
|
1295
|
-
.orWhere("product.title ILIKE :q", { q: "%".concat(q, "%") })
|
|
1296
|
-
.orWhere("variant.title ILIKE :q", { q: "%".concat(q, "%") })
|
|
1297
|
-
.orWhere("variant.sku ILIKE :q", { q: "%".concat(q, "%") })
|
|
1298
|
-
.orWhere("collection.title ILIKE :q", { q: "%".concat(q, "%") });
|
|
1299
|
-
}))
|
|
1300
|
-
.skip(query.skip)
|
|
1301
|
-
.take(query.take);
|
|
1302
|
-
if (query.withDeleted) {
|
|
1303
|
-
qb = qb.withDeleted();
|
|
1304
|
-
}
|
|
1305
|
-
return qb;
|
|
1306
|
-
};
|
|
1307
|
-
/**
|
|
1308
|
-
* Set additional prices on a list of products.
|
|
1309
|
-
* @param {Product[] | Product} products list of products on which to set additional prices
|
|
1310
|
-
* @param {string} currency_code currency code to fetch prices for
|
|
1311
|
-
* @param {string} region_id region to fetch prices for
|
|
1312
|
-
* @param {string} cart_id string of cart to use as a basis for getting currency and region
|
|
1313
|
-
* @param {string} customer_id id of potentially logged in customer, used to get prices valid for their customer groups
|
|
1314
|
-
* @param {boolean} include_discount_prices indication wether or not to include sales prices in result
|
|
1315
|
-
* @return {Promise<Product[]>} A list of products with variants decorated with "additional_prices"
|
|
1316
|
-
*/
|
|
1317
|
-
ProductService.prototype.setAdditionalPrices = function (products, currency_code, region_id, cart_id, customer_id, include_discount_prices) {
|
|
1318
|
-
if (include_discount_prices === void 0) { include_discount_prices = false; }
|
|
1319
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1320
|
-
var _this = this;
|
|
1321
|
-
return __generator(this, function (_a) {
|
|
1322
|
-
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
1323
|
-
var cartRepo, regionId, currencyCode, cart, productArray, priceSelectionStrategy, productsWithPrices;
|
|
1324
|
-
var _this = this;
|
|
1325
|
-
return __generator(this, function (_a) {
|
|
1326
|
-
switch (_a.label) {
|
|
1327
|
-
case 0:
|
|
1328
|
-
cartRepo = this.manager_.getCustomRepository(this.cartRepository_);
|
|
1329
|
-
regionId = region_id;
|
|
1330
|
-
currencyCode = currency_code;
|
|
1331
|
-
if (!cart_id) return [3 /*break*/, 2];
|
|
1332
|
-
return [4 /*yield*/, cartRepo.findOne({
|
|
1333
|
-
where: { id: cart_id },
|
|
1334
|
-
relations: ["region"],
|
|
1335
|
-
})];
|
|
1336
|
-
case 1:
|
|
1337
|
-
cart = _a.sent();
|
|
1338
|
-
regionId = cart.region.id;
|
|
1339
|
-
currencyCode = cart.region.currency_code;
|
|
1340
|
-
_a.label = 2;
|
|
1341
|
-
case 2:
|
|
1342
|
-
productArray = Array.isArray(products) ? products : [products];
|
|
1343
|
-
priceSelectionStrategy = this.priceSelectionStrategy_.withTransaction(manager);
|
|
1344
|
-
return [4 /*yield*/, Promise.all(productArray.map(function (p) { return __awaiter(_this, void 0, void 0, function () {
|
|
1345
|
-
var _a;
|
|
1346
|
-
var _this = this;
|
|
1347
|
-
var _b;
|
|
1348
|
-
return __generator(this, function (_c) {
|
|
1349
|
-
switch (_c.label) {
|
|
1350
|
-
case 0:
|
|
1351
|
-
if (!((_b = p.variants) === null || _b === void 0 ? void 0 : _b.length)) return [3 /*break*/, 2];
|
|
1352
|
-
_a = p;
|
|
1353
|
-
return [4 /*yield*/, Promise.all(p.variants.map(function (v) { return __awaiter(_this, void 0, void 0, function () {
|
|
1354
|
-
var prices;
|
|
1355
|
-
return __generator(this, function (_a) {
|
|
1356
|
-
switch (_a.label) {
|
|
1357
|
-
case 0: return [4 /*yield*/, priceSelectionStrategy.calculateVariantPrice(v.id, {
|
|
1358
|
-
region_id: regionId,
|
|
1359
|
-
currency_code: currencyCode,
|
|
1360
|
-
cart_id: cart_id,
|
|
1361
|
-
customer_id: customer_id,
|
|
1362
|
-
include_discount_prices: include_discount_prices,
|
|
1363
|
-
})];
|
|
1364
|
-
case 1:
|
|
1365
|
-
prices = _a.sent();
|
|
1366
|
-
return [2 /*return*/, __assign(__assign({}, v), { prices: prices.prices, original_price: prices.originalPrice, calculated_price: prices.calculatedPrice, calculated_price_type: prices.calculatedPriceType })];
|
|
1367
|
-
}
|
|
1368
|
-
});
|
|
1369
|
-
}); }))];
|
|
1370
|
-
case 1:
|
|
1371
|
-
_a.variants = _c.sent();
|
|
1372
|
-
_c.label = 2;
|
|
1373
|
-
case 2: return [2 /*return*/, p];
|
|
1374
|
-
}
|
|
1375
|
-
});
|
|
1376
|
-
}); }))];
|
|
1377
|
-
case 3:
|
|
1378
|
-
productsWithPrices = _a.sent();
|
|
1379
|
-
return [2 /*return*/, Array.isArray(products)
|
|
1380
|
-
? productsWithPrices
|
|
1381
|
-
: productsWithPrices[0]];
|
|
1382
|
-
}
|
|
1383
|
-
});
|
|
1384
|
-
}); })];
|
|
1385
|
-
});
|
|
1386
|
-
});
|
|
1387
|
-
};
|
|
1388
1060
|
ProductService.IndexName = "products";
|
|
1389
1061
|
ProductService.Events = {
|
|
1390
1062
|
UPDATED: "product.updated",
|
|
@@ -1392,6 +1064,6 @@ var ProductService = /** @class */ (function (_super) {
|
|
|
1392
1064
|
DELETED: "product.deleted",
|
|
1393
1065
|
};
|
|
1394
1066
|
return ProductService;
|
|
1395
|
-
}(
|
|
1067
|
+
}(interfaces_1.TransactionBaseService));
|
|
1396
1068
|
exports.default = ProductService;
|
|
1397
1069
|
//# sourceMappingURL=product.js.map
|