@vicacha-devs/medusa-plugin-b2b 0.0.0-stage → 0.0.1
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/.medusa/server/src/admin/index.cjs +8706 -0
- package/.medusa/server/src/admin/index.js +8683 -0
- package/.medusa/server/src/api/admin/b2b/approvals/[id]/route.js +24 -0
- package/.medusa/server/src/api/admin/b2b/approvals/middlewares.js +23 -0
- package/.medusa/server/src/api/admin/b2b/approvals/query-config.js +13 -0
- package/.medusa/server/src/api/admin/b2b/approvals/route.js +45 -0
- package/.medusa/server/src/api/admin/b2b/approvals/validators.js +15 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/approval-settings/route.js +36 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/customer-group/[customerGroupId]/route.js +10 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/customer-group/route.js +35 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/employees/[employeeId]/route.js +48 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/employees/route.js +64 -0
- package/.medusa/server/src/api/admin/b2b/companies/[id]/route.js +48 -0
- package/.medusa/server/src/api/admin/b2b/companies/middlewares.js +77 -0
- package/.medusa/server/src/api/admin/b2b/companies/query-config.js +91 -0
- package/.medusa/server/src/api/admin/b2b/companies/route.js +68 -0
- package/.medusa/server/src/api/admin/b2b/companies/validators.js +113 -0
- package/.medusa/server/src/api/admin/b2b/customers/[id]/employee/route.js +20 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/messages/route.js +20 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/reject/route.js +19 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/route.js +30 -0
- package/.medusa/server/src/api/admin/b2b/quotes/[id]/send/route.js +19 -0
- package/.medusa/server/src/api/admin/b2b/quotes/middlewares.js +44 -0
- package/.medusa/server/src/api/admin/b2b/quotes/query-config.js +43 -0
- package/.medusa/server/src/api/admin/b2b/quotes/route.js +54 -0
- package/.medusa/server/src/api/admin/b2b/quotes/validators.js +37 -0
- package/.medusa/server/src/api/admin/companies/route.js +32 -0
- package/.medusa/server/src/api/admin/middlewares.js +9 -0
- package/.medusa/server/src/api/admin/validators.js +4 -0
- package/.medusa/server/src/api/admin/views/b2b-approvals/columns/route.js +119 -0
- package/.medusa/server/src/api/admin/views/b2b-companies/columns/route.js +144 -0
- package/.medusa/server/src/api/admin/views/b2b-company-employees/columns/route.js +73 -0
- package/.medusa/server/src/api/admin/views/b2b-quotes/columns/route.js +108 -0
- package/.medusa/server/src/api/middlewares/ensure-role.js +88 -0
- package/.medusa/server/src/api/middlewares.js +20 -0
- package/.medusa/server/src/api/store/b2b/approvals/[id]/route.js +24 -0
- package/.medusa/server/src/api/store/b2b/approvals/middlewares.js +71 -0
- package/.medusa/server/src/api/store/b2b/approvals/query-config.js +13 -0
- package/.medusa/server/src/api/store/b2b/approvals/route.js +76 -0
- package/.medusa/server/src/api/store/b2b/approvals/validators.js +22 -0
- package/.medusa/server/src/api/store/b2b/carts/[id]/approvals/route.js +24 -0
- package/.medusa/server/src/api/store/b2b/carts/[id]/line-items/bulk/route.js +26 -0
- package/.medusa/server/src/api/store/b2b/carts/middlewares.js +19 -0
- package/.medusa/server/src/api/store/b2b/carts/query-config.js +13 -0
- package/.medusa/server/src/api/store/b2b/carts/validators.js +12 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/approval-settings/route.js +21 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/employees/[employeeId]/route.js +53 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/employees/route.js +44 -0
- package/.medusa/server/src/api/store/b2b/companies/[id]/route.js +39 -0
- package/.medusa/server/src/api/store/b2b/companies/middlewares.js +94 -0
- package/.medusa/server/src/api/store/b2b/companies/query-config.js +62 -0
- package/.medusa/server/src/api/store/b2b/companies/route.js +18 -0
- package/.medusa/server/src/api/store/b2b/companies/validators.js +66 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/middlewares.js +15 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/prices/route.js +41 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/utils.js +51 -0
- package/.medusa/server/src/api/store/b2b/free-shipping/validators.js +11 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/accept/route.js +20 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/messages/route.js +20 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/preview/route.js +19 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/reject/route.js +19 -0
- package/.medusa/server/src/api/store/b2b/quotes/[id]/route.js +15 -0
- package/.medusa/server/src/api/store/b2b/quotes/middlewares.js +64 -0
- package/.medusa/server/src/api/store/b2b/quotes/query-config.js +58 -0
- package/.medusa/server/src/api/store/b2b/quotes/route.js +39 -0
- package/.medusa/server/src/api/store/b2b/quotes/validators.js +35 -0
- package/.medusa/server/src/api/store/middlewares.js +13 -0
- package/.medusa/server/src/api/store/validators.js +6 -0
- package/.medusa/server/src/api/validators.js +3 -0
- package/.medusa/server/src/jobs/expire-quotes.js +22 -0
- package/.medusa/server/src/links/cart-approval-status.js +12 -0
- package/.medusa/server/src/links/cart-approvals.js +13 -0
- package/.medusa/server/src/links/company-approval-setting.js +5 -0
- package/.medusa/server/src/links/company-carts.js +12 -0
- package/.medusa/server/src/links/company-customer-group.js +11 -0
- package/.medusa/server/src/links/employee-customer.js +9 -0
- package/.medusa/server/src/links/order-company.js +9 -0
- package/.medusa/server/src/links/quote-links.js +77 -0
- package/.medusa/server/src/modules/approval/index.js +7 -0
- package/.medusa/server/src/modules/approval/migrations/Migration20260912010000.js +22 -0
- package/.medusa/server/src/modules/approval/models/approval-settings.js +21 -0
- package/.medusa/server/src/modules/approval/models/approval-status.js +21 -0
- package/.medusa/server/src/modules/approval/models/approval.js +36 -0
- package/.medusa/server/src/modules/approval/models/index.js +4 -0
- package/.medusa/server/src/modules/approval/service.js +18 -0
- package/.medusa/server/src/modules/company/index.js +7 -0
- package/.medusa/server/src/modules/company/migrations/Migration20260912010000.js +24 -0
- package/.medusa/server/src/modules/company/models/company.js +44 -0
- package/.medusa/server/src/modules/company/models/employee.js +30 -0
- package/.medusa/server/src/modules/company/models/index.js +3 -0
- package/.medusa/server/src/modules/company/service.js +9 -0
- package/.medusa/server/src/modules/company/types/common.js +2 -0
- package/.medusa/server/src/modules/company/types/mutations.js +2 -0
- package/.medusa/server/src/modules/quote/index.js +5 -0
- package/.medusa/server/src/modules/quote/migrations/Migration20260912010000.js +29 -0
- package/.medusa/server/src/modules/quote/models/index.js +3 -0
- package/.medusa/server/src/modules/quote/models/message.js +34 -0
- package/.medusa/server/src/modules/quote/models/quote.js +57 -0
- package/.medusa/server/src/modules/quote/service.js +6 -0
- package/.medusa/server/src/rbac.js +122 -0
- package/.medusa/server/src/scripts/seed-b2b-data.js +99 -0
- package/.medusa/server/src/scripts/seed-b2b-test-data.js +813 -0
- package/.medusa/server/src/types/approval/http.js +2 -0
- package/.medusa/server/src/types/approval/index.js +5 -0
- package/.medusa/server/src/types/approval/module.js +14 -0
- package/.medusa/server/src/types/approval/query.js +2 -0
- package/.medusa/server/src/types/approval/service.js +2 -0
- package/.medusa/server/src/types/company/http.js +2 -0
- package/.medusa/server/src/types/company/index.js +5 -0
- package/.medusa/server/src/types/company/module.js +3 -0
- package/.medusa/server/src/types/company/query.js +2 -0
- package/.medusa/server/src/types/company/service.js +2 -0
- package/.medusa/server/src/types/constants.js +16 -0
- package/.medusa/server/src/types/enums.js +18 -0
- package/.medusa/server/src/types/index.js +6 -0
- package/.medusa/server/src/types/quote/http.js +2 -0
- package/.medusa/server/src/types/quote/index.js +5 -0
- package/.medusa/server/src/types/quote/module.js +3 -0
- package/.medusa/server/src/types/quote/query.js +2 -0
- package/.medusa/server/src/types/quote/service.js +2 -0
- package/.medusa/server/src/types/shipping-options/http.js +2 -0
- package/.medusa/server/src/types/shipping-options/index.js +2 -0
- package/.medusa/server/src/types/types.js +2 -0
- package/.medusa/server/src/utils/check-spending-limit.js +51 -0
- package/.medusa/server/src/utils/get-cart-approval-status.js +22 -0
- package/.medusa/server/src/workflows/approval/steps/create-approval-settings.js +18 -0
- package/.medusa/server/src/workflows/approval/steps/create-approval-status.js +37 -0
- package/.medusa/server/src/workflows/approval/steps/create-approvals.js +55 -0
- package/.medusa/server/src/workflows/approval/steps/delete-approval-settings.js +23 -0
- package/.medusa/server/src/workflows/approval/steps/delete-approvals.js +11 -0
- package/.medusa/server/src/workflows/approval/steps/index.js +9 -0
- package/.medusa/server/src/workflows/approval/steps/update-approval-settings.js +12 -0
- package/.medusa/server/src/workflows/approval/steps/update-approval-statuses.js +49 -0
- package/.medusa/server/src/workflows/approval/steps/update-approval.js +60 -0
- package/.medusa/server/src/workflows/approval/workflows/create-approval-settings.js +20 -0
- package/.medusa/server/src/workflows/approval/workflows/create-approvals.js +43 -0
- package/.medusa/server/src/workflows/approval/workflows/index.js +5 -0
- package/.medusa/server/src/workflows/approval/workflows/update-approval-settings.js +6 -0
- package/.medusa/server/src/workflows/approval/workflows/update-approval.js +8 -0
- package/.medusa/server/src/workflows/company/steps/add-company-employees-to-customer-group.js +41 -0
- package/.medusa/server/src/workflows/company/steps/create-companies.js +14 -0
- package/.medusa/server/src/workflows/company/steps/delete-companies.js +11 -0
- package/.medusa/server/src/workflows/company/steps/dismiss-company-customer-group-link.js +40 -0
- package/.medusa/server/src/workflows/company/steps/index.js +7 -0
- package/.medusa/server/src/workflows/company/steps/remove-company-employees-from-customer-group.js +39 -0
- package/.medusa/server/src/workflows/company/steps/update-companies.js +14 -0
- package/.medusa/server/src/workflows/company/workflows/add-company-to-customer-group.js +25 -0
- package/.medusa/server/src/workflows/company/workflows/create-companies.js +21 -0
- package/.medusa/server/src/workflows/company/workflows/delete-companies.js +12 -0
- package/.medusa/server/src/workflows/company/workflows/index.js +6 -0
- package/.medusa/server/src/workflows/company/workflows/remove-company-from-customer-group.js +22 -0
- package/.medusa/server/src/workflows/company/workflows/update-companies.js +6 -0
- package/.medusa/server/src/workflows/employee/steps/add-employee-to-customer-group.js +41 -0
- package/.medusa/server/src/workflows/employee/steps/create-employees.js +20 -0
- package/.medusa/server/src/workflows/employee/steps/delete-employees.js +14 -0
- package/.medusa/server/src/workflows/employee/steps/index.js +8 -0
- package/.medusa/server/src/workflows/employee/steps/link-employee-to-customer.js +29 -0
- package/.medusa/server/src/workflows/employee/steps/remove-admin-role.js +37 -0
- package/.medusa/server/src/workflows/employee/steps/set-admin-role.js +56 -0
- package/.medusa/server/src/workflows/employee/steps/sync-customer-company-name.js +41 -0
- package/.medusa/server/src/workflows/employee/steps/update-employees.js +29 -0
- package/.medusa/server/src/workflows/employee/workflows/create-employees.js +34 -0
- package/.medusa/server/src/workflows/employee/workflows/delete-employees.js +15 -0
- package/.medusa/server/src/workflows/employee/workflows/index.js +4 -0
- package/.medusa/server/src/workflows/employee/workflows/update-employees.js +14 -0
- package/.medusa/server/src/workflows/hooks/cart-created.js +37 -0
- package/.medusa/server/src/workflows/hooks/order-created.js +30 -0
- package/.medusa/server/src/workflows/hooks/validate-add-to-cart.js +20 -0
- package/.medusa/server/src/workflows/hooks/validate-cart-completion.js +38 -0
- package/.medusa/server/src/workflows/hooks/validate-update-cart.js +20 -0
- package/.medusa/server/src/workflows/index.js +6 -0
- package/.medusa/server/src/workflows/order/steps/update-order.js +28 -0
- package/.medusa/server/src/workflows/order/workflows/update-order.js +21 -0
- package/.medusa/server/src/workflows/quote/steps/create-quote-message.js +18 -0
- package/.medusa/server/src/workflows/quote/steps/create-quotes.js +18 -0
- package/.medusa/server/src/workflows/quote/steps/update-quotes.js +28 -0
- package/.medusa/server/src/workflows/quote/steps/validate-quote-acceptance.js +11 -0
- package/.medusa/server/src/workflows/quote/steps/validate-quote-rejection.js +10 -0
- package/.medusa/server/src/workflows/quote/workflows/create-quote-message.js +11 -0
- package/.medusa/server/src/workflows/quote/workflows/create-quote.js +9 -0
- package/.medusa/server/src/workflows/quote/workflows/create-request-for-quote.js +84 -0
- package/.medusa/server/src/workflows/quote/workflows/customer-accept-quote.js +39 -0
- package/.medusa/server/src/workflows/quote/workflows/customer-reject-quote.js +27 -0
- package/.medusa/server/src/workflows/quote/workflows/index.js +9 -0
- package/.medusa/server/src/workflows/quote/workflows/merchant-reject-quote.js +28 -0
- package/.medusa/server/src/workflows/quote/workflows/merchant-send-quote.js +29 -0
- package/.medusa/server/src/workflows/quote/workflows/update-quote.js +9 -0
- package/LICENSE +21 -0
- package/README.md +587 -2
- package/package.json +121 -3
- package/src/__tests__/b2b-contract.spec.ts +41 -0
- package/src/admin/README.md +73 -0
- package/src/admin/constants.ts +1 -0
- package/src/admin/hooks/api/approvals.tsx +106 -0
- package/src/admin/hooks/api/companies.tsx +288 -0
- package/src/admin/hooks/api/customers.tsx +44 -0
- package/src/admin/hooks/api/employees.tsx +170 -0
- package/src/admin/hooks/api/index.ts +5 -0
- package/src/admin/hooks/api/quotes.tsx +329 -0
- package/src/admin/i18n/README.md +78 -0
- package/src/admin/i18n/index.ts +23 -0
- package/src/admin/i18n/json/ar.json +388 -0
- package/src/admin/i18n/json/de.json +388 -0
- package/src/admin/i18n/json/en.json +388 -0
- package/src/admin/i18n/json/es.json +388 -0
- package/src/admin/i18n/json/fr.json +388 -0
- package/src/admin/i18n/json/it.json +388 -0
- package/src/admin/i18n/json/nl.json +388 -0
- package/src/admin/i18n/json/pl.json +388 -0
- package/src/admin/i18n/json/pt.json +388 -0
- package/src/admin/i18n/json/tr.json +388 -0
- package/src/admin/routes/b2b/approvals/components/approval-actions.tsx +129 -0
- package/src/admin/routes/b2b/approvals/components/approval-status-badge.tsx +24 -0
- package/src/admin/routes/b2b/approvals/components/approvals-items-popover.tsx +69 -0
- package/src/admin/routes/b2b/approvals/components/approvals-table-adapter.tsx +45 -0
- package/src/admin/routes/b2b/approvals/components/approvals-table-renderers.tsx +74 -0
- package/src/admin/routes/b2b/approvals/components/approvals-table.tsx +66 -0
- package/src/admin/routes/b2b/approvals/components/table/columns.tsx +113 -0
- package/src/admin/routes/b2b/approvals/components/table/filters.tsx +30 -0
- package/src/admin/routes/b2b/approvals/components/table/query.tsx +25 -0
- package/src/admin/routes/b2b/approvals/page.tsx +66 -0
- package/src/admin/routes/b2b/companies/@create/page.tsx +70 -0
- package/src/admin/routes/b2b/companies/[id]/@approval-settings/page.tsx +106 -0
- package/src/admin/routes/b2b/companies/[id]/@customer-group/page.tsx +152 -0
- package/src/admin/routes/b2b/companies/[id]/@edit/page.tsx +93 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/[employeeId]/page.tsx +82 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/employees-actions-menu.tsx +61 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/employees-create-form.tsx +190 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/employees-update-form.tsx +160 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/index.ts +3 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/components/validators.ts +25 -0
- package/src/admin/routes/b2b/companies/[id]/@employee/create/page.tsx +91 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-approval-settings-section.tsx +67 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-customer-group-section.tsx +55 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-employees-section.tsx +70 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-employees-table-renderers.tsx +53 -0
- package/src/admin/routes/b2b/companies/[id]/components/company-general-section.tsx +59 -0
- package/src/admin/routes/b2b/companies/[id]/page.tsx +85 -0
- package/src/admin/routes/b2b/companies/components/companies-table-adapter.tsx +46 -0
- package/src/admin/routes/b2b/companies/components/companies-table-renderers.tsx +53 -0
- package/src/admin/routes/b2b/companies/components/companies-table.tsx +83 -0
- package/src/admin/routes/b2b/companies/components/company-actions-menu.tsx +46 -0
- package/src/admin/routes/b2b/companies/components/company-create-admin-tab.tsx +185 -0
- package/src/admin/routes/b2b/companies/components/company-create-details-tab.tsx +169 -0
- package/src/admin/routes/b2b/companies/components/company-create-form.tsx +201 -0
- package/src/admin/routes/b2b/companies/components/company-form-admin-tab.tsx +99 -0
- package/src/admin/routes/b2b/companies/components/company-form-details-tab.tsx +159 -0
- package/src/admin/routes/b2b/companies/components/company-form.tsx +159 -0
- package/src/admin/routes/b2b/companies/components/index.ts +9 -0
- package/src/admin/routes/b2b/companies/components/table/columns.tsx +81 -0
- package/src/admin/routes/b2b/companies/components/table/filters.tsx +23 -0
- package/src/admin/routes/b2b/companies/components/table/query.tsx +27 -0
- package/src/admin/routes/b2b/companies/components/use-delete-company-list-action.tsx +37 -0
- package/src/admin/routes/b2b/companies/components/validators.ts +49 -0
- package/src/admin/routes/b2b/companies/page.tsx +66 -0
- package/src/admin/routes/b2b/components/index.ts +6 -0
- package/src/admin/routes/b2b/components/navigation-card.tsx +51 -0
- package/src/admin/routes/b2b/components/stat-card.tsx +48 -0
- package/src/admin/routes/b2b/page.tsx +173 -0
- package/src/admin/routes/b2b/quotes/[id]/components/index.ts +8 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-company-section.tsx +54 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-customer-section.tsx +75 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-detail-actions.tsx +57 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-general-section.tsx +66 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-message-bubble.tsx +132 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-message-composer.tsx +135 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-messages-section.tsx +100 -0
- package/src/admin/routes/b2b/quotes/[id]/components/quote-order-section.tsx +115 -0
- package/src/admin/routes/b2b/quotes/[id]/components/validators.ts +8 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/index.ts +7 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-item-info.tsx +63 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-item-price-form.tsx +60 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-item.tsx +227 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-items-section.tsx +145 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-items-table.tsx +117 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/manage-quote-form.tsx +187 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/columns.tsx +29 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/filters.tsx +8 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/index.ts +3 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/table/query.tsx +25 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/components/validators.ts +5 -0
- package/src/admin/routes/b2b/quotes/[id]/manage/page.tsx +60 -0
- package/src/admin/routes/b2b/quotes/[id]/page.tsx +213 -0
- package/src/admin/routes/b2b/quotes/components/index.ts +4 -0
- package/src/admin/routes/b2b/quotes/components/quote-actions-menu.tsx +119 -0
- package/src/admin/routes/b2b/quotes/components/quote-status-badge.tsx +30 -0
- package/src/admin/routes/b2b/quotes/components/quotes-table-adapter.tsx +43 -0
- package/src/admin/routes/b2b/quotes/components/quotes-table-renderers.tsx +87 -0
- package/src/admin/routes/b2b/quotes/components/quotes-table.tsx +70 -0
- package/src/admin/routes/b2b/quotes/components/send-quote-drawer.tsx +69 -0
- package/src/admin/routes/b2b/quotes/components/table/columns.tsx +75 -0
- package/src/admin/routes/b2b/quotes/components/table/filters.tsx +44 -0
- package/src/admin/routes/b2b/quotes/components/table/query.tsx +27 -0
- package/src/admin/routes/b2b/quotes/page.tsx +65 -0
- package/src/admin/tsconfig.json +23 -0
- package/src/admin/validators.ts +4 -0
- package/src/admin/vite-env.d.ts +1 -0
- package/src/admin/widgets/customer-company-widget.tsx +63 -0
- package/src/admin/widgets/customer-employee-widget.tsx +48 -0
- package/src/admin/widgets/customer-group-companies-widget.tsx +68 -0
- package/src/api/README.md +64 -0
- package/src/api/admin/b2b/approvals/[id]/route.ts +34 -0
- package/src/api/admin/b2b/approvals/middlewares.ts +31 -0
- package/src/api/admin/b2b/approvals/query-config.ts +13 -0
- package/src/api/admin/b2b/approvals/route.ts +56 -0
- package/src/api/admin/b2b/approvals/validators.ts +23 -0
- package/src/api/admin/b2b/companies/[id]/approval-settings/route.ts +57 -0
- package/src/api/admin/b2b/companies/[id]/customer-group/[customerGroupId]/route.ts +17 -0
- package/src/api/admin/b2b/companies/[id]/customer-group/route.ts +56 -0
- package/src/api/admin/b2b/companies/[id]/employees/[employeeId]/route.ts +84 -0
- package/src/api/admin/b2b/companies/[id]/employees/route.ts +90 -0
- package/src/api/admin/b2b/companies/[id]/route.ts +88 -0
- package/src/api/admin/b2b/companies/middlewares.ts +123 -0
- package/src/api/admin/b2b/companies/query-config.ts +99 -0
- package/src/api/admin/b2b/companies/route.ts +101 -0
- package/src/api/admin/b2b/companies/validators.ts +165 -0
- package/src/api/admin/b2b/customers/[id]/employee/route.ts +31 -0
- package/src/api/admin/b2b/quotes/[id]/messages/route.ts +36 -0
- package/src/api/admin/b2b/quotes/[id]/reject/route.ts +35 -0
- package/src/api/admin/b2b/quotes/[id]/route.ts +48 -0
- package/src/api/admin/b2b/quotes/[id]/send/route.ts +35 -0
- package/src/api/admin/b2b/quotes/middlewares.ts +71 -0
- package/src/api/admin/b2b/quotes/query-config.ts +45 -0
- package/src/api/admin/b2b/quotes/route.ts +72 -0
- package/src/api/admin/b2b/quotes/validators.ts +49 -0
- package/src/api/admin/companies/route.ts +43 -0
- package/src/api/admin/middlewares.ts +10 -0
- package/src/api/admin/validators.ts +3 -0
- package/src/api/admin/views/b2b-approvals/columns/route.ts +121 -0
- package/src/api/admin/views/b2b-companies/columns/route.ts +146 -0
- package/src/api/admin/views/b2b-company-employees/columns/route.ts +74 -0
- package/src/api/admin/views/b2b-quotes/columns/route.ts +110 -0
- package/src/api/middlewares/ensure-role.ts +138 -0
- package/src/api/middlewares.ts +26 -0
- package/src/api/store/b2b/approvals/[id]/route.ts +34 -0
- package/src/api/store/b2b/approvals/middlewares.ts +103 -0
- package/src/api/store/b2b/approvals/query-config.ts +13 -0
- package/src/api/store/b2b/approvals/route.ts +105 -0
- package/src/api/store/b2b/approvals/validators.ts +30 -0
- package/src/api/store/b2b/carts/[id]/approvals/route.ts +33 -0
- package/src/api/store/b2b/carts/[id]/line-items/bulk/route.ts +46 -0
- package/src/api/store/b2b/carts/middlewares.ts +27 -0
- package/src/api/store/b2b/carts/query-config.ts +13 -0
- package/src/api/store/b2b/carts/validators.ts +19 -0
- package/src/api/store/b2b/companies/[id]/approval-settings/route.ts +33 -0
- package/src/api/store/b2b/companies/[id]/employees/[employeeId]/route.ts +86 -0
- package/src/api/store/b2b/companies/[id]/employees/route.ts +72 -0
- package/src/api/store/b2b/companies/[id]/route.ts +70 -0
- package/src/api/store/b2b/companies/middlewares.ts +137 -0
- package/src/api/store/b2b/companies/query-config.ts +76 -0
- package/src/api/store/b2b/companies/route.ts +34 -0
- package/src/api/store/b2b/companies/validators.ts +88 -0
- package/src/api/store/b2b/free-shipping/middlewares.ts +16 -0
- package/src/api/store/b2b/free-shipping/prices/route.ts +71 -0
- package/src/api/store/b2b/free-shipping/utils.ts +60 -0
- package/src/api/store/b2b/free-shipping/validators.ts +16 -0
- package/src/api/store/b2b/quotes/[id]/accept/route.ts +36 -0
- package/src/api/store/b2b/quotes/[id]/messages/route.ts +36 -0
- package/src/api/store/b2b/quotes/[id]/preview/route.ts +45 -0
- package/src/api/store/b2b/quotes/[id]/reject/route.ts +35 -0
- package/src/api/store/b2b/quotes/[id]/route.ts +30 -0
- package/src/api/store/b2b/quotes/middlewares.ts +96 -0
- package/src/api/store/b2b/quotes/query-config.ts +59 -0
- package/src/api/store/b2b/quotes/route.ts +65 -0
- package/src/api/store/b2b/quotes/validators.ts +51 -0
- package/src/api/store/middlewares.ts +14 -0
- package/src/api/store/validators.ts +5 -0
- package/src/api/validators.ts +2 -0
- package/src/jobs/expire-quotes.ts +31 -0
- package/src/links/README.md +62 -0
- package/src/links/cart-approval-status.ts +14 -0
- package/src/links/cart-approvals.ts +15 -0
- package/src/links/company-approval-setting.ts +8 -0
- package/src/links/company-carts.ts +14 -0
- package/src/links/company-customer-group.ts +16 -0
- package/src/links/employee-customer.ts +14 -0
- package/src/links/order-company.ts +14 -0
- package/src/links/quote-links.ts +77 -0
- package/src/modules/README.md +75 -0
- package/src/modules/approval/index.ts +8 -0
- package/src/modules/approval/migrations/Migration20260912010000.ts +47 -0
- package/src/modules/approval/models/approval-settings.ts +21 -0
- package/src/modules/approval/models/approval-status.ts +21 -0
- package/src/modules/approval/models/approval.ts +36 -0
- package/src/modules/approval/models/index.ts +3 -0
- package/src/modules/approval/service.ts +20 -0
- package/src/modules/company/index.ts +8 -0
- package/src/modules/company/migrations/Migration20260912010000.ts +50 -0
- package/src/modules/company/models/company.ts +44 -0
- package/src/modules/company/models/employee.ts +30 -0
- package/src/modules/company/models/index.ts +2 -0
- package/src/modules/company/service.ts +9 -0
- package/src/modules/company/types/common.ts +30 -0
- package/src/modules/company/types/mutations.ts +30 -0
- package/src/modules/quote/index.ts +6 -0
- package/src/modules/quote/migrations/Migration20260912010000.ts +65 -0
- package/src/modules/quote/models/index.ts +2 -0
- package/src/modules/quote/models/message.ts +35 -0
- package/src/modules/quote/models/quote.ts +58 -0
- package/src/modules/quote/service.ts +6 -0
- package/src/rbac.ts +136 -0
- package/src/scripts/README.md +40 -0
- package/src/scripts/seed-b2b-data.ts +177 -0
- package/src/scripts/seed-b2b-test-data.ts +986 -0
- package/src/types/README.md +52 -0
- package/src/types/approval/http.ts +56 -0
- package/src/types/approval/index.ts +4 -0
- package/src/types/approval/module.ts +77 -0
- package/src/types/approval/query.ts +11 -0
- package/src/types/approval/service.ts +126 -0
- package/src/types/company/http.ts +126 -0
- package/src/types/company/index.ts +4 -0
- package/src/types/company/module.ts +78 -0
- package/src/types/company/query.ts +15 -0
- package/src/types/company/service.ts +109 -0
- package/src/types/constants.ts +16 -0
- package/src/types/enums.ts +16 -0
- package/src/types/index.ts +5 -0
- package/src/types/quote/http.ts +50 -0
- package/src/types/quote/index.ts +4 -0
- package/src/types/quote/module.ts +45 -0
- package/src/types/quote/query.ts +22 -0
- package/src/types/quote/service.ts +65 -0
- package/src/types/shipping-options/http.ts +7 -0
- package/src/types/shipping-options/index.ts +1 -0
- package/src/types/types.ts +5 -0
- package/src/utils/README.md +37 -0
- package/src/utils/check-spending-limit.ts +81 -0
- package/src/utils/get-cart-approval-status.ts +35 -0
- package/src/workflows/README.md +85 -0
- package/src/workflows/approval/steps/create-approval-settings.ts +34 -0
- package/src/workflows/approval/steps/create-approval-status.ts +56 -0
- package/src/workflows/approval/steps/create-approvals.ts +114 -0
- package/src/workflows/approval/steps/delete-approval-settings.ts +52 -0
- package/src/workflows/approval/steps/delete-approvals.ts +21 -0
- package/src/workflows/approval/steps/index.ts +8 -0
- package/src/workflows/approval/steps/update-approval-settings.ts +27 -0
- package/src/workflows/approval/steps/update-approval-statuses.ts +77 -0
- package/src/workflows/approval/steps/update-approval.ts +87 -0
- package/src/workflows/approval/workflows/create-approval-settings.ts +32 -0
- package/src/workflows/approval/workflows/create-approvals.ts +60 -0
- package/src/workflows/approval/workflows/index.ts +4 -0
- package/src/workflows/approval/workflows/update-approval-settings.ts +13 -0
- package/src/workflows/approval/workflows/update-approval.ts +17 -0
- package/src/workflows/company/steps/add-company-employees-to-customer-group.ts +74 -0
- package/src/workflows/company/steps/create-companies.ts +28 -0
- package/src/workflows/company/steps/delete-companies.ts +21 -0
- package/src/workflows/company/steps/dismiss-company-customer-group-link.ts +53 -0
- package/src/workflows/company/steps/index.ts +6 -0
- package/src/workflows/company/steps/remove-company-employees-from-customer-group.ts +76 -0
- package/src/workflows/company/steps/update-companies.ts +25 -0
- package/src/workflows/company/workflows/add-company-to-customer-group.ts +34 -0
- package/src/workflows/company/workflows/create-companies.ts +35 -0
- package/src/workflows/company/workflows/delete-companies.ts +18 -0
- package/src/workflows/company/workflows/index.ts +5 -0
- package/src/workflows/company/workflows/remove-company-from-customer-group.ts +30 -0
- package/src/workflows/company/workflows/update-companies.ts +13 -0
- package/src/workflows/employee/steps/add-employee-to-customer-group.ts +81 -0
- package/src/workflows/employee/steps/create-employees.ts +46 -0
- package/src/workflows/employee/steps/delete-employees.ts +25 -0
- package/src/workflows/employee/steps/index.ts +7 -0
- package/src/workflows/employee/steps/link-employee-to-customer.ts +49 -0
- package/src/workflows/employee/steps/remove-admin-role.ts +59 -0
- package/src/workflows/employee/steps/set-admin-role.ts +89 -0
- package/src/workflows/employee/steps/sync-customer-company-name.ts +83 -0
- package/src/workflows/employee/steps/update-employees.ts +61 -0
- package/src/workflows/employee/workflows/create-employees.ts +61 -0
- package/src/workflows/employee/workflows/delete-employees.ts +26 -0
- package/src/workflows/employee/workflows/index.ts +3 -0
- package/src/workflows/employee/workflows/update-employees.ts +31 -0
- package/src/workflows/hooks/cart-created.ts +56 -0
- package/src/workflows/hooks/order-created.ts +38 -0
- package/src/workflows/hooks/validate-add-to-cart.ts +32 -0
- package/src/workflows/hooks/validate-cart-completion.ts +61 -0
- package/src/workflows/hooks/validate-update-cart.ts +32 -0
- package/src/workflows/index.ts +5 -0
- package/src/workflows/order/steps/update-order.ts +53 -0
- package/src/workflows/order/workflows/update-order.ts +28 -0
- package/src/workflows/quote/steps/create-quote-message.ts +33 -0
- package/src/workflows/quote/steps/create-quotes.ts +32 -0
- package/src/workflows/quote/steps/update-quotes.ts +48 -0
- package/src/workflows/quote/steps/validate-quote-acceptance.ts +22 -0
- package/src/workflows/quote/steps/validate-quote-rejection.ts +17 -0
- package/src/workflows/quote/workflows/create-quote-message.ts +20 -0
- package/src/workflows/quote/workflows/create-quote.ts +16 -0
- package/src/workflows/quote/workflows/create-request-for-quote.ts +102 -0
- package/src/workflows/quote/workflows/customer-accept-quote.ts +49 -0
- package/src/workflows/quote/workflows/customer-reject-quote.ts +31 -0
- package/src/workflows/quote/workflows/index.ts +8 -0
- package/src/workflows/quote/workflows/merchant-reject-quote.ts +34 -0
- package/src/workflows/quote/workflows/merchant-send-quote.ts +33 -0
- package/src/workflows/quote/workflows/update-quote.ts +16 -0
- package/tsconfig.json +40 -0
|
@@ -0,0 +1,986 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addToCartWorkflow,
|
|
3
|
+
beginOrderEditOrderWorkflow,
|
|
4
|
+
createCartWorkflow,
|
|
5
|
+
createOrderWorkflow,
|
|
6
|
+
} from "@medusajs/core-flows"
|
|
7
|
+
import { MedusaContainer } from "@medusajs/framework"
|
|
8
|
+
import {
|
|
9
|
+
ContainerRegistrationKeys,
|
|
10
|
+
Modules,
|
|
11
|
+
OrderStatus,
|
|
12
|
+
} from "@medusajs/framework/utils"
|
|
13
|
+
|
|
14
|
+
import { APPROVAL_MODULE } from "../modules/approval"
|
|
15
|
+
import { QUOTE_MODULE } from "../modules/quote"
|
|
16
|
+
import { EQuoteStatus, ESpendingLimitResetFrequency } from "../types/enums"
|
|
17
|
+
import { createCompaniesWorkflow } from "../workflows/company/workflows/create-companies"
|
|
18
|
+
import { createEmployeesWorkflow } from "../workflows/employee/workflows/create-employees"
|
|
19
|
+
import { merchantSendQuoteWorkflow } from "../workflows/quote/workflows/merchant-send-quote"
|
|
20
|
+
import { merchantRejectQuoteWorkflow } from "../workflows/quote/workflows/merchant-reject-quote"
|
|
21
|
+
import { customerRejectQuoteWorkflow } from "../workflows/quote/workflows/customer-reject-quote"
|
|
22
|
+
import { customerAcceptQuoteWorkflow } from "../workflows/quote/workflows/customer-accept-quote"
|
|
23
|
+
|
|
24
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
25
|
+
// Helpers
|
|
26
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
type ItemInput = {
|
|
29
|
+
title: string
|
|
30
|
+
sku?: string
|
|
31
|
+
quantity: number
|
|
32
|
+
unit_price: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function createDraftOrderWithChange(
|
|
36
|
+
container: MedusaContainer,
|
|
37
|
+
{
|
|
38
|
+
customer,
|
|
39
|
+
currency_code,
|
|
40
|
+
region_id,
|
|
41
|
+
sales_channel_id,
|
|
42
|
+
items,
|
|
43
|
+
}: {
|
|
44
|
+
customer: {
|
|
45
|
+
id: string
|
|
46
|
+
email: string
|
|
47
|
+
first_name?: string | null
|
|
48
|
+
last_name?: string | null
|
|
49
|
+
}
|
|
50
|
+
currency_code: string
|
|
51
|
+
region_id: string | undefined
|
|
52
|
+
sales_channel_id: string | undefined
|
|
53
|
+
items: ItemInput[]
|
|
54
|
+
}
|
|
55
|
+
) {
|
|
56
|
+
const address = {
|
|
57
|
+
first_name: customer.first_name ?? "",
|
|
58
|
+
last_name: customer.last_name ?? "",
|
|
59
|
+
country_code: "co",
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { result: draftOrder } = await createOrderWorkflow(container).run({
|
|
63
|
+
input: {
|
|
64
|
+
is_draft_order: true,
|
|
65
|
+
status: OrderStatus.DRAFT,
|
|
66
|
+
...(sales_channel_id && { sales_channel_id }),
|
|
67
|
+
...(region_id && { region_id }),
|
|
68
|
+
email: customer.email,
|
|
69
|
+
customer_id: customer.id,
|
|
70
|
+
currency_code,
|
|
71
|
+
billing_address: address,
|
|
72
|
+
shipping_address: address,
|
|
73
|
+
items: items.map((i) => ({
|
|
74
|
+
title: i.title,
|
|
75
|
+
...(i.sku && { variant_sku: i.sku }),
|
|
76
|
+
quantity: i.quantity,
|
|
77
|
+
unit_price: i.unit_price,
|
|
78
|
+
})),
|
|
79
|
+
shipping_methods: [],
|
|
80
|
+
} as any,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const { result: orderChange } = await beginOrderEditOrderWorkflow(
|
|
84
|
+
container
|
|
85
|
+
).run({
|
|
86
|
+
input: { order_id: draftOrder.id },
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
return { draftOrder, orderChange }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
93
|
+
// Seed
|
|
94
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
export default async function seedB2bTestData({
|
|
97
|
+
container,
|
|
98
|
+
}: {
|
|
99
|
+
container: MedusaContainer
|
|
100
|
+
}) {
|
|
101
|
+
const logger = container.resolve(ContainerRegistrationKeys.LOGGER)
|
|
102
|
+
const customerService = container.resolve(Modules.CUSTOMER)
|
|
103
|
+
const userService = container.resolve(Modules.USER)
|
|
104
|
+
const regionService = container.resolve(Modules.REGION)
|
|
105
|
+
const salesChannelService = container.resolve(Modules.SALES_CHANNEL)
|
|
106
|
+
// resolve company service or query module
|
|
107
|
+
const approvalService = container.resolve(APPROVAL_MODULE) as any
|
|
108
|
+
const quoteService = container.resolve(QUOTE_MODULE) as any
|
|
109
|
+
|
|
110
|
+
// ── Admin user ──────────────────────────────────────────────────────────
|
|
111
|
+
|
|
112
|
+
const [adminUser] = await userService.listUsers({}, { take: 1 })
|
|
113
|
+
const adminId: string = adminUser?.id ?? "usr_seed_fallback"
|
|
114
|
+
logger.info(
|
|
115
|
+
adminUser
|
|
116
|
+
? `Using admin: ${[adminUser.first_name, adminUser.last_name].filter(Boolean).join(" ")} (${adminUser.id})`
|
|
117
|
+
: "No admin user found — messages will show generic 'Admin'"
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
// ── Region + sales channel ──────────────────────────────────────────────
|
|
121
|
+
|
|
122
|
+
const [region] = await regionService.listRegions({}, { take: 1 })
|
|
123
|
+
const regionId: string | undefined = region?.id
|
|
124
|
+
if (!regionId)
|
|
125
|
+
logger.warn("No region found — draft orders will have no region_id")
|
|
126
|
+
|
|
127
|
+
// Dynamically adopt the region's currency code to prevent cart validation errors
|
|
128
|
+
const currency = region?.currency_code?.toLowerCase() ?? "cop"
|
|
129
|
+
logger.info(`Using region currency: ${currency.toUpperCase()}`)
|
|
130
|
+
|
|
131
|
+
const salesChannels = await salesChannelService.listSalesChannels({
|
|
132
|
+
name: ["B2B"],
|
|
133
|
+
})
|
|
134
|
+
const b2bChannelId: string | undefined = salesChannels[0]?.id
|
|
135
|
+
if (!b2bChannelId)
|
|
136
|
+
logger.warn("B2B sales channel not found — run seed-b2b-data.ts first")
|
|
137
|
+
|
|
138
|
+
// ── Customers (find-or-create) ──────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
logger.info("Resolving test customers...")
|
|
141
|
+
|
|
142
|
+
const CUSTOMER_DEFS = [
|
|
143
|
+
{
|
|
144
|
+
first_name: "Ana",
|
|
145
|
+
last_name: "García",
|
|
146
|
+
email: "ana.garcia@acmecorp.co",
|
|
147
|
+
phone: "+57 310 1234567",
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
first_name: "Carlos",
|
|
151
|
+
last_name: "Rodríguez",
|
|
152
|
+
email: "carlos.rodriguez@acmecorp.co",
|
|
153
|
+
phone: "+57 310 2345678",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
first_name: "María",
|
|
157
|
+
last_name: "López",
|
|
158
|
+
email: "maria.lopez@globextravel.co",
|
|
159
|
+
phone: "+57 310 3456789",
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
first_name: "Juan",
|
|
163
|
+
last_name: "Martínez",
|
|
164
|
+
email: "juan.martinez@globextravel.co",
|
|
165
|
+
phone: "+57 310 4567890",
|
|
166
|
+
},
|
|
167
|
+
]
|
|
168
|
+
|
|
169
|
+
const existingCustomers = await customerService.listCustomers(
|
|
170
|
+
{ email: { $in: CUSTOMER_DEFS.map((c) => c.email) } },
|
|
171
|
+
{ take: CUSTOMER_DEFS.length }
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
const existingByEmail = new Map(
|
|
175
|
+
existingCustomers.map((c: any) => [c.email, c])
|
|
176
|
+
)
|
|
177
|
+
const toCreateCustomers = CUSTOMER_DEFS.filter(
|
|
178
|
+
(c) => !existingByEmail.has(c.email)
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
const newCustomers =
|
|
182
|
+
toCreateCustomers.length > 0
|
|
183
|
+
? await customerService.createCustomers(toCreateCustomers)
|
|
184
|
+
: []
|
|
185
|
+
|
|
186
|
+
const customers = CUSTOMER_DEFS.map(
|
|
187
|
+
(def) =>
|
|
188
|
+
existingByEmail.get(def.email) ??
|
|
189
|
+
newCustomers.find((c: any) => c.email === def.email)
|
|
190
|
+
)
|
|
191
|
+
logger.info(
|
|
192
|
+
`Customers ready: ${existingCustomers.length} existing, ${newCustomers.length} created`
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
// ── Companies (find-or-create) ──────────────────────────────────────────
|
|
196
|
+
|
|
197
|
+
logger.info("Resolving companies...")
|
|
198
|
+
|
|
199
|
+
const COMPANY_DEFS = [
|
|
200
|
+
{
|
|
201
|
+
name: "Acme Corporation",
|
|
202
|
+
email: "admin@acmecorp.co",
|
|
203
|
+
phone: "+57 1 3001234",
|
|
204
|
+
address: "Calle 72 # 10-34",
|
|
205
|
+
city: "Bogotá",
|
|
206
|
+
state: "Cundinamarca",
|
|
207
|
+
zip: "110231",
|
|
208
|
+
country: "CO",
|
|
209
|
+
logo_url: null,
|
|
210
|
+
currency_code: currency,
|
|
211
|
+
spending_limit_reset_frequency: ESpendingLimitResetFrequency.MONTHLY,
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: "Globex Travel",
|
|
215
|
+
email: "admin@globextravel.co",
|
|
216
|
+
phone: "+57 4 3002345",
|
|
217
|
+
address: "El Poblado, Carrera 43A # 1-50",
|
|
218
|
+
city: "Medellín",
|
|
219
|
+
state: "Antioquia",
|
|
220
|
+
zip: "050021",
|
|
221
|
+
country: "CO",
|
|
222
|
+
logo_url: null,
|
|
223
|
+
currency_code: currency,
|
|
224
|
+
spending_limit_reset_frequency: ESpendingLimitResetFrequency.WEEKLY,
|
|
225
|
+
},
|
|
226
|
+
]
|
|
227
|
+
|
|
228
|
+
// Query existing companies by name using Query Module
|
|
229
|
+
const query = container.resolve(ContainerRegistrationKeys.QUERY)
|
|
230
|
+
const { data: existingCompanies } = await query.graph({
|
|
231
|
+
entity: "company",
|
|
232
|
+
fields: ["id", "name", "email"],
|
|
233
|
+
filters: { name: { $in: COMPANY_DEFS.map((c) => c.name) } },
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
const existingCompaniesMap = new Map(
|
|
237
|
+
existingCompanies.map((c: any) => [c.name, c])
|
|
238
|
+
)
|
|
239
|
+
const companiesToCreate = COMPANY_DEFS.filter(
|
|
240
|
+
(c) => !existingCompaniesMap.has(c.name)
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
let createdCompanies: any[] = []
|
|
244
|
+
if (companiesToCreate.length > 0) {
|
|
245
|
+
const { result } = await createCompaniesWorkflow(container).run({
|
|
246
|
+
input: companiesToCreate,
|
|
247
|
+
})
|
|
248
|
+
createdCompanies = result as any[]
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const cos = COMPANY_DEFS.map(
|
|
252
|
+
(def) =>
|
|
253
|
+
existingCompaniesMap.get(def.name) ??
|
|
254
|
+
createdCompanies.find((c: any) => c.name === def.name)
|
|
255
|
+
)
|
|
256
|
+
logger.info(
|
|
257
|
+
`Companies ready: ${existingCompanies.length} existing, ${createdCompanies.length} created`
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
// ── Employees (find-or-create) ──────────────────────────────────────────
|
|
261
|
+
|
|
262
|
+
logger.info("Resolving employees...")
|
|
263
|
+
|
|
264
|
+
const employeeInputs = [
|
|
265
|
+
{
|
|
266
|
+
employeeData: {
|
|
267
|
+
company_id: cos[0].id,
|
|
268
|
+
customer_id: customers[0].id,
|
|
269
|
+
spending_limit: 5_000_000,
|
|
270
|
+
is_admin: true,
|
|
271
|
+
},
|
|
272
|
+
customerId: customers[0].id,
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
employeeData: {
|
|
276
|
+
company_id: cos[0].id,
|
|
277
|
+
customer_id: customers[1].id,
|
|
278
|
+
spending_limit: 2_000_000,
|
|
279
|
+
is_admin: false,
|
|
280
|
+
},
|
|
281
|
+
customerId: customers[1].id,
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
employeeData: {
|
|
285
|
+
company_id: cos[1].id,
|
|
286
|
+
customer_id: customers[2].id,
|
|
287
|
+
spending_limit: 10_000_000,
|
|
288
|
+
is_admin: true,
|
|
289
|
+
},
|
|
290
|
+
customerId: customers[2].id,
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
employeeData: {
|
|
294
|
+
company_id: cos[1].id,
|
|
295
|
+
customer_id: customers[3].id,
|
|
296
|
+
spending_limit: 3_000_000,
|
|
297
|
+
is_admin: false,
|
|
298
|
+
},
|
|
299
|
+
customerId: customers[3].id,
|
|
300
|
+
},
|
|
301
|
+
]
|
|
302
|
+
|
|
303
|
+
// Query employees with linked customer relation via Remote Link Graph
|
|
304
|
+
const { data: existingEmployees } = await query.graph({
|
|
305
|
+
entity: "employee",
|
|
306
|
+
fields: ["id", "company_id", "customer.id"],
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
// Extract linked customer IDs from graph response
|
|
310
|
+
const existingCustomerIds = new Set(
|
|
311
|
+
existingEmployees.map((e: any) => e.customer?.id).filter(Boolean)
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
for (const input of employeeInputs) {
|
|
315
|
+
if (!existingCustomerIds.has(input.customerId)) {
|
|
316
|
+
try {
|
|
317
|
+
await createEmployeesWorkflow(container).run({ input })
|
|
318
|
+
logger.info(`Created employee for customer: ${input.customerId}`)
|
|
319
|
+
} catch (err: any) {
|
|
320
|
+
if (
|
|
321
|
+
err?.message?.includes("Cannot create multiple links") ||
|
|
322
|
+
err?.message?.includes("already exists")
|
|
323
|
+
) {
|
|
324
|
+
logger.warn(
|
|
325
|
+
`Link already exists for customer ${input.customerId}. Skipping.`
|
|
326
|
+
)
|
|
327
|
+
} else {
|
|
328
|
+
throw err
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
logger.info(
|
|
333
|
+
`Employee link already exists for customer ${input.customerId}. Skipping.`
|
|
334
|
+
)
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
logger.info("Employees processed.")
|
|
339
|
+
|
|
340
|
+
// ── Approval Settings ───────────────────────────────────────────────────
|
|
341
|
+
|
|
342
|
+
logger.info("Checking approval settings...")
|
|
343
|
+
|
|
344
|
+
const existingSettings =
|
|
345
|
+
(await approvalService.listApprovalSettings?.({
|
|
346
|
+
company_id: { $in: cos.map((c: any) => c.id) },
|
|
347
|
+
})) ?? []
|
|
348
|
+
|
|
349
|
+
const existingSettingsCompanyIds = new Set(
|
|
350
|
+
existingSettings.map((s: any) => s.company_id)
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
const settingsToCreate = [
|
|
354
|
+
{
|
|
355
|
+
company_id: cos[0].id,
|
|
356
|
+
requires_admin_approval: true,
|
|
357
|
+
requires_sales_manager_approval: true,
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
company_id: cos[1].id,
|
|
361
|
+
requires_admin_approval: true,
|
|
362
|
+
requires_sales_manager_approval: false,
|
|
363
|
+
},
|
|
364
|
+
].filter((s) => !existingSettingsCompanyIds.has(s.company_id))
|
|
365
|
+
|
|
366
|
+
if (settingsToCreate.length > 0) {
|
|
367
|
+
await approvalService.createApprovalSettings(settingsToCreate)
|
|
368
|
+
logger.info(`Created ${settingsToCreate.length} approval settings.`)
|
|
369
|
+
} else {
|
|
370
|
+
logger.info("Approval settings already exist. Skipping.")
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// ── Approval Carts & Approvals ──────────────────────────────────────────
|
|
374
|
+
|
|
375
|
+
logger.info("Checking approval test carts...")
|
|
376
|
+
|
|
377
|
+
const existingApprovals = await approvalService.listApprovals({}, { take: 1 })
|
|
378
|
+
|
|
379
|
+
if (existingApprovals.length === 0) {
|
|
380
|
+
logger.info("Creating approval test carts and approvals...")
|
|
381
|
+
|
|
382
|
+
const apprAddress = {
|
|
383
|
+
first_name: "Approval",
|
|
384
|
+
last_name: "Test",
|
|
385
|
+
country_code: "co",
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const createApprovalCart = async (
|
|
389
|
+
customer: (typeof customers)[0],
|
|
390
|
+
companyId: string,
|
|
391
|
+
items: ItemInput[]
|
|
392
|
+
) => {
|
|
393
|
+
const { result } = await createCartWorkflow(container).run({
|
|
394
|
+
input: {
|
|
395
|
+
...(regionId && { region_id: regionId }),
|
|
396
|
+
...(b2bChannelId && { sales_channel_id: b2bChannelId }),
|
|
397
|
+
currency_code: currency,
|
|
398
|
+
customer_id: customer.id,
|
|
399
|
+
email: customer.email,
|
|
400
|
+
billing_address: apprAddress,
|
|
401
|
+
shipping_address: apprAddress,
|
|
402
|
+
metadata: { company_id: companyId },
|
|
403
|
+
} as any,
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
// Use addToCartWorkflow to create custom line items correctly
|
|
407
|
+
await addToCartWorkflow(container).run({
|
|
408
|
+
input: {
|
|
409
|
+
cart_id: result.id,
|
|
410
|
+
items: items.map((i) => ({
|
|
411
|
+
title: i.title,
|
|
412
|
+
quantity: i.quantity,
|
|
413
|
+
unit_price: i.unit_price,
|
|
414
|
+
})),
|
|
415
|
+
},
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
return result
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// 5 carts — one per approval scenario
|
|
422
|
+
const [aCart1, aCart2, aCart3, gCart1, gCart2] = await Promise.all([
|
|
423
|
+
createApprovalCart(customers[0], cos[0].id, [
|
|
424
|
+
{
|
|
425
|
+
title: "Bogotá → Ciudad de México · Clase Económica",
|
|
426
|
+
quantity: 3,
|
|
427
|
+
unit_price: 1_100_000,
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
title: "Hotel Camino Real CDMX · 2 noches",
|
|
431
|
+
quantity: 3,
|
|
432
|
+
unit_price: 450_000,
|
|
433
|
+
},
|
|
434
|
+
]),
|
|
435
|
+
createApprovalCart(customers[1], cos[0].id, [
|
|
436
|
+
{
|
|
437
|
+
title: "Bogotá → Lima · Clase Ejecutiva",
|
|
438
|
+
quantity: 2,
|
|
439
|
+
unit_price: 3_200_000,
|
|
440
|
+
},
|
|
441
|
+
]),
|
|
442
|
+
createApprovalCart(customers[0], cos[0].id, [
|
|
443
|
+
{
|
|
444
|
+
title: "Bogotá → Buenos Aires · Clase Económica",
|
|
445
|
+
quantity: 5,
|
|
446
|
+
unit_price: 1_800_000,
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
title: "Hotel Sofitel BA · 3 noches",
|
|
450
|
+
quantity: 5,
|
|
451
|
+
unit_price: 620_000,
|
|
452
|
+
},
|
|
453
|
+
]),
|
|
454
|
+
createApprovalCart(customers[2], cos[1].id, [
|
|
455
|
+
{
|
|
456
|
+
title: "Medellín → Cartagena · Clase Económica",
|
|
457
|
+
quantity: 4,
|
|
458
|
+
unit_price: 480_000,
|
|
459
|
+
},
|
|
460
|
+
]),
|
|
461
|
+
createApprovalCart(customers[3], cos[1].id, [
|
|
462
|
+
{
|
|
463
|
+
title: "Bogotá → San Andrés · Clase Económica",
|
|
464
|
+
quantity: 2,
|
|
465
|
+
unit_price: 950_000,
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
title: "Hotel Decameron San Andrés · 4 noches",
|
|
469
|
+
quantity: 2,
|
|
470
|
+
unit_price: 380_000,
|
|
471
|
+
},
|
|
472
|
+
]),
|
|
473
|
+
])
|
|
474
|
+
|
|
475
|
+
const remoteLink = container.resolve(ContainerRegistrationKeys.LINK)
|
|
476
|
+
|
|
477
|
+
// Scenario 1 — Both admin + sales_manager PENDING (Acme / Ana)
|
|
478
|
+
const [appr1Admin, appr1SM] = await approvalService.createApprovals([
|
|
479
|
+
{
|
|
480
|
+
cart_id: aCart1.id,
|
|
481
|
+
type: "admin",
|
|
482
|
+
status: "pending",
|
|
483
|
+
created_by: customers[0].id,
|
|
484
|
+
} as any,
|
|
485
|
+
{
|
|
486
|
+
cart_id: aCart1.id,
|
|
487
|
+
type: "sales_manager",
|
|
488
|
+
status: "pending",
|
|
489
|
+
created_by: customers[0].id,
|
|
490
|
+
} as any,
|
|
491
|
+
])
|
|
492
|
+
const [apprStatus1] = await approvalService.createApprovalStatuses([
|
|
493
|
+
{ cart_id: aCart1.id, status: "pending" },
|
|
494
|
+
])
|
|
495
|
+
|
|
496
|
+
// Scenario 2 — Admin APPROVED, sales_manager PENDING (Acme / Carlos)
|
|
497
|
+
const [appr2Admin, appr2SM] = await approvalService.createApprovals([
|
|
498
|
+
{
|
|
499
|
+
cart_id: aCart2.id,
|
|
500
|
+
type: "admin",
|
|
501
|
+
status: "approved",
|
|
502
|
+
created_by: customers[1].id,
|
|
503
|
+
handled_by: adminId,
|
|
504
|
+
} as any,
|
|
505
|
+
{
|
|
506
|
+
cart_id: aCart2.id,
|
|
507
|
+
type: "sales_manager",
|
|
508
|
+
status: "pending",
|
|
509
|
+
created_by: customers[1].id,
|
|
510
|
+
} as any,
|
|
511
|
+
])
|
|
512
|
+
const [apprStatus2] = await approvalService.createApprovalStatuses([
|
|
513
|
+
{ cart_id: aCart2.id, status: "pending" },
|
|
514
|
+
])
|
|
515
|
+
|
|
516
|
+
// Scenario 3 — Both APPROVED (Acme / Ana)
|
|
517
|
+
const [appr3Admin, appr3SM] = await approvalService.createApprovals([
|
|
518
|
+
{
|
|
519
|
+
cart_id: aCart3.id,
|
|
520
|
+
type: "admin",
|
|
521
|
+
status: "approved",
|
|
522
|
+
created_by: customers[0].id,
|
|
523
|
+
handled_by: adminId,
|
|
524
|
+
} as any,
|
|
525
|
+
{
|
|
526
|
+
cart_id: aCart3.id,
|
|
527
|
+
type: "sales_manager",
|
|
528
|
+
status: "approved",
|
|
529
|
+
created_by: customers[0].id,
|
|
530
|
+
handled_by: adminId,
|
|
531
|
+
} as any,
|
|
532
|
+
])
|
|
533
|
+
const [apprStatus3] = await approvalService.createApprovalStatuses([
|
|
534
|
+
{ cart_id: aCart3.id, status: "approved" },
|
|
535
|
+
])
|
|
536
|
+
|
|
537
|
+
// Scenario 4 — Admin REJECTED (Globex / María)
|
|
538
|
+
const [appr4Admin] = await approvalService.createApprovals([
|
|
539
|
+
{
|
|
540
|
+
cart_id: gCart1.id,
|
|
541
|
+
type: "admin",
|
|
542
|
+
status: "rejected",
|
|
543
|
+
created_by: customers[2].id,
|
|
544
|
+
handled_by: adminId,
|
|
545
|
+
reason: "Budget exceeded for this period.",
|
|
546
|
+
} as any,
|
|
547
|
+
])
|
|
548
|
+
const [apprStatus4] = await approvalService.createApprovalStatuses([
|
|
549
|
+
{ cart_id: gCart1.id, status: "rejected" },
|
|
550
|
+
])
|
|
551
|
+
|
|
552
|
+
// Scenario 5 — Admin PENDING (Globex / Juan)
|
|
553
|
+
const [appr5Admin] = await approvalService.createApprovals([
|
|
554
|
+
{
|
|
555
|
+
cart_id: gCart2.id,
|
|
556
|
+
type: "admin",
|
|
557
|
+
status: "pending",
|
|
558
|
+
created_by: customers[3].id,
|
|
559
|
+
} as any,
|
|
560
|
+
])
|
|
561
|
+
const [apprStatus5] = await approvalService.createApprovalStatuses([
|
|
562
|
+
{ cart_id: gCart2.id, status: "pending" },
|
|
563
|
+
])
|
|
564
|
+
|
|
565
|
+
// Remote links
|
|
566
|
+
await remoteLink.create([
|
|
567
|
+
{
|
|
568
|
+
[Modules.CART]: { cart_id: aCart1.id },
|
|
569
|
+
[APPROVAL_MODULE]: { approval_id: appr1Admin.id },
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
[Modules.CART]: { cart_id: aCart1.id },
|
|
573
|
+
[APPROVAL_MODULE]: { approval_id: appr1SM.id },
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
[Modules.CART]: { cart_id: aCart1.id },
|
|
577
|
+
[APPROVAL_MODULE]: { approval_status_id: apprStatus1.id },
|
|
578
|
+
},
|
|
579
|
+
|
|
580
|
+
{
|
|
581
|
+
[Modules.CART]: { cart_id: aCart2.id },
|
|
582
|
+
[APPROVAL_MODULE]: { approval_id: appr2Admin.id },
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
[Modules.CART]: { cart_id: aCart2.id },
|
|
586
|
+
[APPROVAL_MODULE]: { approval_id: appr2SM.id },
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
[Modules.CART]: { cart_id: aCart2.id },
|
|
590
|
+
[APPROVAL_MODULE]: { approval_status_id: apprStatus2.id },
|
|
591
|
+
},
|
|
592
|
+
|
|
593
|
+
{
|
|
594
|
+
[Modules.CART]: { cart_id: aCart3.id },
|
|
595
|
+
[APPROVAL_MODULE]: { approval_id: appr3Admin.id },
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
[Modules.CART]: { cart_id: aCart3.id },
|
|
599
|
+
[APPROVAL_MODULE]: { approval_id: appr3SM.id },
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
[Modules.CART]: { cart_id: aCart3.id },
|
|
603
|
+
[APPROVAL_MODULE]: { approval_status_id: apprStatus3.id },
|
|
604
|
+
},
|
|
605
|
+
|
|
606
|
+
{
|
|
607
|
+
[Modules.CART]: { cart_id: gCart1.id },
|
|
608
|
+
[APPROVAL_MODULE]: { approval_id: appr4Admin.id },
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
[Modules.CART]: { cart_id: gCart1.id },
|
|
612
|
+
[APPROVAL_MODULE]: { approval_status_id: apprStatus4.id },
|
|
613
|
+
},
|
|
614
|
+
|
|
615
|
+
{
|
|
616
|
+
[Modules.CART]: { cart_id: gCart2.id },
|
|
617
|
+
[APPROVAL_MODULE]: { approval_id: appr5Admin.id },
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
[Modules.CART]: { cart_id: gCart2.id },
|
|
621
|
+
[APPROVAL_MODULE]: { approval_status_id: apprStatus5.id },
|
|
622
|
+
},
|
|
623
|
+
])
|
|
624
|
+
|
|
625
|
+
logger.info("Created approvals and linked cart records.")
|
|
626
|
+
} else {
|
|
627
|
+
logger.info("Approvals already present. Skipping.")
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// ── Quotes (find-or-create) ─────────────────────────────────────────────
|
|
631
|
+
|
|
632
|
+
logger.info("Checking quotes...")
|
|
633
|
+
|
|
634
|
+
const existingQuotes = await quoteService.listQuotes({}, { take: 1 })
|
|
635
|
+
|
|
636
|
+
if (existingQuotes.length === 0) {
|
|
637
|
+
logger.info("Creating draft orders and quotes...")
|
|
638
|
+
|
|
639
|
+
// 1. pending_merchant
|
|
640
|
+
const { draftOrder: do1, orderChange: oc1 } =
|
|
641
|
+
await createDraftOrderWithChange(container, {
|
|
642
|
+
customer: customers[0],
|
|
643
|
+
currency_code: currency,
|
|
644
|
+
region_id: regionId,
|
|
645
|
+
sales_channel_id: b2bChannelId,
|
|
646
|
+
items: [
|
|
647
|
+
{
|
|
648
|
+
title: "Bogotá → Miami · Clase Ejecutiva",
|
|
649
|
+
quantity: 12,
|
|
650
|
+
unit_price: 2_500_000,
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
title: "Hotel Marriott Miami · 3 noches",
|
|
654
|
+
quantity: 12,
|
|
655
|
+
unit_price: 800_000,
|
|
656
|
+
},
|
|
657
|
+
],
|
|
658
|
+
})
|
|
659
|
+
|
|
660
|
+
const [q1] = await quoteService.createQuotes([
|
|
661
|
+
{
|
|
662
|
+
status: EQuoteStatus.PendingMerchant,
|
|
663
|
+
customer_id: customers[0].id,
|
|
664
|
+
draft_order_id: do1.id,
|
|
665
|
+
order_change_id: oc1.id,
|
|
666
|
+
cart_id: `cart_seed_acme_001`,
|
|
667
|
+
},
|
|
668
|
+
])
|
|
669
|
+
|
|
670
|
+
await quoteService.createMessages([
|
|
671
|
+
{
|
|
672
|
+
quote_id: q1.id,
|
|
673
|
+
text: "Necesitamos cotización para 12 ejecutivos — vuelos BOG→MIA más hotel 3 noches, primera quincena de octubre.",
|
|
674
|
+
customer_id: customers[0].id,
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
quote_id: q1.id,
|
|
678
|
+
text: "¿Pueden incluir traslados aeropuerto-hotel en la cotización?",
|
|
679
|
+
customer_id: customers[0].id,
|
|
680
|
+
},
|
|
681
|
+
])
|
|
682
|
+
|
|
683
|
+
// 2. pending_customer
|
|
684
|
+
const { draftOrder: do2, orderChange: oc2 } =
|
|
685
|
+
await createDraftOrderWithChange(container, {
|
|
686
|
+
customer: customers[2],
|
|
687
|
+
currency_code: currency,
|
|
688
|
+
region_id: regionId,
|
|
689
|
+
sales_channel_id: b2bChannelId,
|
|
690
|
+
items: [
|
|
691
|
+
{
|
|
692
|
+
title: "Hotel Medellín · Habitación Doble Deluxe · Octubre",
|
|
693
|
+
quantity: 5,
|
|
694
|
+
unit_price: 280_000,
|
|
695
|
+
},
|
|
696
|
+
],
|
|
697
|
+
})
|
|
698
|
+
|
|
699
|
+
const [q2] = await quoteService.createQuotes([
|
|
700
|
+
{
|
|
701
|
+
status: EQuoteStatus.PendingMerchant,
|
|
702
|
+
customer_id: customers[2].id,
|
|
703
|
+
draft_order_id: do2.id,
|
|
704
|
+
order_change_id: oc2.id,
|
|
705
|
+
cart_id: `cart_seed_globex_001`,
|
|
706
|
+
},
|
|
707
|
+
])
|
|
708
|
+
|
|
709
|
+
await merchantSendQuoteWorkflow(container).run({
|
|
710
|
+
input: { quote_id: q2.id },
|
|
711
|
+
})
|
|
712
|
+
|
|
713
|
+
const item2Id: string | undefined = (do2 as any).items?.[0]?.id
|
|
714
|
+
await quoteService.createMessages([
|
|
715
|
+
{
|
|
716
|
+
quote_id: q2.id,
|
|
717
|
+
text: "¿Pueden ajustar los precios de alojamiento para octubre? Buscamos algo bajo COP 300 000/noche.",
|
|
718
|
+
customer_id: customers[2].id,
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
quote_id: q2.id,
|
|
722
|
+
text: "Revisamos disponibilidad con nuestros proveedores.",
|
|
723
|
+
admin_id: adminId,
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
quote_id: q2.id,
|
|
727
|
+
text: "Tenemos opciones entre COP 250 000 y COP 290 000/noche. Les comparto el ítem actualizado.",
|
|
728
|
+
admin_id: adminId,
|
|
729
|
+
...(item2Id && { item_id: item2Id }),
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
quote_id: q2.id,
|
|
733
|
+
text: "Muchas gracias. Revisamos con el equipo y les confirmamos esta semana.",
|
|
734
|
+
customer_id: customers[2].id,
|
|
735
|
+
},
|
|
736
|
+
])
|
|
737
|
+
|
|
738
|
+
// 3. accepted
|
|
739
|
+
const { draftOrder: do3, orderChange: oc3 } =
|
|
740
|
+
await createDraftOrderWithChange(container, {
|
|
741
|
+
customer: customers[0],
|
|
742
|
+
currency_code: currency,
|
|
743
|
+
region_id: regionId,
|
|
744
|
+
sales_channel_id: b2bChannelId,
|
|
745
|
+
items: [
|
|
746
|
+
{
|
|
747
|
+
title: "Bogotá → Cancún · Clase Económica · Dic 20",
|
|
748
|
+
quantity: 15,
|
|
749
|
+
unit_price: 1_200_000,
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
title: "Bogotá → Cancún · Clase Ejecutiva · Dic 20",
|
|
753
|
+
quantity: 5,
|
|
754
|
+
unit_price: 3_800_000,
|
|
755
|
+
},
|
|
756
|
+
],
|
|
757
|
+
})
|
|
758
|
+
|
|
759
|
+
const [q3] = await quoteService.createQuotes([
|
|
760
|
+
{
|
|
761
|
+
status: EQuoteStatus.PendingMerchant,
|
|
762
|
+
customer_id: customers[0].id,
|
|
763
|
+
draft_order_id: do3.id,
|
|
764
|
+
order_change_id: oc3.id,
|
|
765
|
+
cart_id: `cart_seed_acme_002`,
|
|
766
|
+
},
|
|
767
|
+
])
|
|
768
|
+
|
|
769
|
+
await merchantSendQuoteWorkflow(container).run({
|
|
770
|
+
input: { quote_id: q3.id },
|
|
771
|
+
})
|
|
772
|
+
await customerAcceptQuoteWorkflow(container).run({
|
|
773
|
+
input: { quote_id: q3.id, customer_id: customers[0].id },
|
|
774
|
+
})
|
|
775
|
+
|
|
776
|
+
const item3EconId: string | undefined = (do3 as any).items?.[0]?.id
|
|
777
|
+
const item3ExecId: string | undefined = (do3 as any).items?.[1]?.id
|
|
778
|
+
await quoteService.createMessages([
|
|
779
|
+
{
|
|
780
|
+
quote_id: q3.id,
|
|
781
|
+
text: "Necesitamos cotización para 20 pasajeros en temporada alta — diciembre 20 al 3 de enero.",
|
|
782
|
+
customer_id: customers[0].id,
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
quote_id: q3.id,
|
|
786
|
+
text: "Recibido. ¿Todos en clase económica o requieren mezcla ejecutiva/económica?",
|
|
787
|
+
admin_id: adminId,
|
|
788
|
+
},
|
|
789
|
+
{
|
|
790
|
+
quote_id: q3.id,
|
|
791
|
+
text: "15 en económica, 5 en ejecutiva. Retorno fijo el 3 de enero. Destino Cancún.",
|
|
792
|
+
customer_id: customers[0].id,
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
quote_id: q3.id,
|
|
796
|
+
text: "¿Hay flexibilidad en la fecha de retorno?",
|
|
797
|
+
admin_id: adminId,
|
|
798
|
+
},
|
|
799
|
+
{
|
|
800
|
+
quote_id: q3.id,
|
|
801
|
+
text: "Retorno fijo el 3 de enero, sin flexibilidad.",
|
|
802
|
+
customer_id: customers[0].id,
|
|
803
|
+
},
|
|
804
|
+
{
|
|
805
|
+
quote_id: q3.id,
|
|
806
|
+
text: "Acá la cotización en económica con 10% de descuento por volumen.",
|
|
807
|
+
admin_id: adminId,
|
|
808
|
+
...(item3EconId && { item_id: item3EconId }),
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
quote_id: q3.id,
|
|
812
|
+
text: "¿El descuento incluye el ítem ejecutivo también?",
|
|
813
|
+
customer_id: customers[0].id,
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
quote_id: q3.id,
|
|
817
|
+
text: "Sí, ejecutiva con 15% de descuento por volumen, incluye una maleta de 23 kg.",
|
|
818
|
+
admin_id: adminId,
|
|
819
|
+
...(item3ExecId && { item_id: item3ExecId }),
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
quote_id: q3.id,
|
|
823
|
+
text: "¿Se puede incluir un seguro de viaje para todos los pasajeros?",
|
|
824
|
+
customer_id: customers[0].id,
|
|
825
|
+
},
|
|
826
|
+
{
|
|
827
|
+
quote_id: q3.id,
|
|
828
|
+
text: "Podemos incluirlo por COP 45 000/persona adicional. ¿Lo añadimos?",
|
|
829
|
+
admin_id: adminId,
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
quote_id: q3.id,
|
|
833
|
+
text: "Sí, por favor. Incluyan el seguro de viaje para todos.",
|
|
834
|
+
customer_id: customers[0].id,
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
quote_id: q3.id,
|
|
838
|
+
text: "Cotización actualizada con el seguro incluido en ambos ítems.",
|
|
839
|
+
admin_id: adminId,
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
quote_id: q3.id,
|
|
843
|
+
text: "Perfecto. Aceptamos la cotización. Procedemos con la reserva.",
|
|
844
|
+
customer_id: customers[0].id,
|
|
845
|
+
},
|
|
846
|
+
])
|
|
847
|
+
|
|
848
|
+
// 4. customer_rejected
|
|
849
|
+
const { draftOrder: do4, orderChange: oc4 } =
|
|
850
|
+
await createDraftOrderWithChange(container, {
|
|
851
|
+
customer: customers[1],
|
|
852
|
+
currency_code: currency,
|
|
853
|
+
region_id: regionId,
|
|
854
|
+
sales_channel_id: b2bChannelId,
|
|
855
|
+
items: [
|
|
856
|
+
{
|
|
857
|
+
title: "Bogotá → Cartagena · Ida y Vuelta · Grupo Corporativo",
|
|
858
|
+
quantity: 8,
|
|
859
|
+
unit_price: 950_000,
|
|
860
|
+
},
|
|
861
|
+
],
|
|
862
|
+
})
|
|
863
|
+
|
|
864
|
+
const [q4] = await quoteService.createQuotes([
|
|
865
|
+
{
|
|
866
|
+
status: EQuoteStatus.PendingMerchant,
|
|
867
|
+
customer_id: customers[1].id,
|
|
868
|
+
draft_order_id: do4.id,
|
|
869
|
+
order_change_id: oc4.id,
|
|
870
|
+
cart_id: `cart_seed_acme_003`,
|
|
871
|
+
},
|
|
872
|
+
])
|
|
873
|
+
|
|
874
|
+
await merchantSendQuoteWorkflow(container).run({
|
|
875
|
+
input: { quote_id: q4.id },
|
|
876
|
+
})
|
|
877
|
+
await customerRejectQuoteWorkflow(container).run({
|
|
878
|
+
input: { quote_id: q4.id },
|
|
879
|
+
})
|
|
880
|
+
|
|
881
|
+
const item4Id: string | undefined = (do4 as any).items?.[0]?.id
|
|
882
|
+
await quoteService.createMessages([
|
|
883
|
+
{
|
|
884
|
+
quote_id: q4.id,
|
|
885
|
+
text: "Solicitamos descuento adicional para grupo corporativo de 8 personas.",
|
|
886
|
+
customer_id: customers[1].id,
|
|
887
|
+
},
|
|
888
|
+
{
|
|
889
|
+
quote_id: q4.id,
|
|
890
|
+
text: "Acá la cotización con nuestra mejor tarifa para ese período.",
|
|
891
|
+
admin_id: adminId,
|
|
892
|
+
...(item4Id && { item_id: item4Id }),
|
|
893
|
+
},
|
|
894
|
+
{
|
|
895
|
+
quote_id: q4.id,
|
|
896
|
+
text: "El precio está por encima de nuestro presupuesto. ¿Pueden bajar un 20%?",
|
|
897
|
+
customer_id: customers[1].id,
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
quote_id: q4.id,
|
|
901
|
+
text: "No tenemos margen adicional para ese período. El precio enviado es nuestra tarifa mínima.",
|
|
902
|
+
admin_id: adminId,
|
|
903
|
+
},
|
|
904
|
+
{
|
|
905
|
+
quote_id: q4.id,
|
|
906
|
+
text: "Lamentablemente rechazamos la cotización. Buscaremos otras alternativas.",
|
|
907
|
+
customer_id: customers[1].id,
|
|
908
|
+
},
|
|
909
|
+
])
|
|
910
|
+
|
|
911
|
+
// 5. merchant_rejected
|
|
912
|
+
const { draftOrder: do5, orderChange: oc5 } =
|
|
913
|
+
await createDraftOrderWithChange(container, {
|
|
914
|
+
customer: customers[3],
|
|
915
|
+
currency_code: currency,
|
|
916
|
+
region_id: regionId,
|
|
917
|
+
sales_channel_id: b2bChannelId,
|
|
918
|
+
items: [
|
|
919
|
+
{
|
|
920
|
+
title: "Bogotá → Miami · Clase Ejecutiva · Dic 24",
|
|
921
|
+
quantity: 4,
|
|
922
|
+
unit_price: 4_200_000,
|
|
923
|
+
},
|
|
924
|
+
],
|
|
925
|
+
})
|
|
926
|
+
|
|
927
|
+
const [q5] = await quoteService.createQuotes([
|
|
928
|
+
{
|
|
929
|
+
status: EQuoteStatus.PendingMerchant,
|
|
930
|
+
customer_id: customers[3].id,
|
|
931
|
+
draft_order_id: do5.id,
|
|
932
|
+
order_change_id: oc5.id,
|
|
933
|
+
cart_id: `cart_seed_globex_002`,
|
|
934
|
+
},
|
|
935
|
+
])
|
|
936
|
+
|
|
937
|
+
await merchantRejectQuoteWorkflow(container).run({
|
|
938
|
+
input: { quote_id: q5.id },
|
|
939
|
+
})
|
|
940
|
+
|
|
941
|
+
await quoteService.createMessages([
|
|
942
|
+
{
|
|
943
|
+
quote_id: q5.id,
|
|
944
|
+
text: "Necesitamos tiquetes para el 24 de diciembre. Solo clase ejecutiva, 4 puestos.",
|
|
945
|
+
customer_id: customers[3].id,
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
quote_id: q5.id,
|
|
949
|
+
text: "No tenemos disponibilidad en clase ejecutiva para esa fecha. No podemos procesar esta solicitud.",
|
|
950
|
+
admin_id: adminId,
|
|
951
|
+
},
|
|
952
|
+
])
|
|
953
|
+
|
|
954
|
+
// 6. pending_merchant, no messages
|
|
955
|
+
const { draftOrder: do6, orderChange: oc6 } =
|
|
956
|
+
await createDraftOrderWithChange(container, {
|
|
957
|
+
customer: customers[2],
|
|
958
|
+
currency_code: currency,
|
|
959
|
+
region_id: regionId,
|
|
960
|
+
sales_channel_id: b2bChannelId,
|
|
961
|
+
items: [
|
|
962
|
+
{
|
|
963
|
+
title: "Medellín → Bogotá · Clase Económica · Temporal",
|
|
964
|
+
quantity: 3,
|
|
965
|
+
unit_price: 350_000,
|
|
966
|
+
},
|
|
967
|
+
],
|
|
968
|
+
})
|
|
969
|
+
|
|
970
|
+
await quoteService.createQuotes([
|
|
971
|
+
{
|
|
972
|
+
status: EQuoteStatus.PendingMerchant,
|
|
973
|
+
customer_id: customers[2].id,
|
|
974
|
+
draft_order_id: do6.id,
|
|
975
|
+
order_change_id: oc6.id,
|
|
976
|
+
cart_id: `cart_seed_globex_003`,
|
|
977
|
+
},
|
|
978
|
+
])
|
|
979
|
+
|
|
980
|
+
logger.info("Created 6 quotes.")
|
|
981
|
+
} else {
|
|
982
|
+
logger.info("Quotes already exist. Skipping.")
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
logger.info("B2B test data seeded successfully.")
|
|
986
|
+
}
|