@tailor-platform/erp-kit 0.2.1 → 0.2.2
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 +6 -0
- package/README.md +1 -23
- package/dist/cli.mjs +1613 -0
- package/package.json +14 -13
- package/schemas/app-compose/story.yml +12 -0
- package/schemas/module/command.yml +9 -0
- package/schemas/module/module.yml +4 -0
- package/schemas/module/query.yml +9 -0
- package/skills/erp-kit-app-1-requirements/SKILL.md +4 -4
- package/skills/erp-kit-app-2-requirements-review/SKILL.md +102 -0
- package/skills/erp-kit-app-2-requirements-review/references/best-practices-check.md +66 -0
- package/skills/erp-kit-app-2-requirements-review/references/boundary-consistency-check.md +69 -0
- package/skills/erp-kit-app-2-requirements-review/references/requirements-report-format.md +25 -0
- package/skills/erp-kit-app-3-plan/SKILL.md +157 -0
- package/skills/erp-kit-app-3-plan/references/resolver-extraction.md +107 -0
- package/skills/erp-kit-app-3-plan/references/screen-extraction.md +74 -0
- package/skills/erp-kit-app-3-plan/references/story-extraction.md +86 -0
- package/skills/erp-kit-app-4-plan-review/SKILL.md +177 -0
- package/skills/erp-kit-app-4-plan-review/references/actor-flow-parity.md +73 -0
- package/skills/erp-kit-app-4-plan-review/references/business-flow-story-parity.md +86 -0
- package/skills/erp-kit-app-4-plan-review/references/orphan-detection.md +69 -0
- package/skills/erp-kit-app-4-plan-review/references/parity-report-format.md +52 -0
- package/skills/erp-kit-app-4-plan-review/references/story-resolver-parity.md +83 -0
- package/skills/erp-kit-app-4-plan-review/references/story-screen-parity.md +73 -0
- package/skills/{erp-kit-app-5-implementation → erp-kit-app-5-impl-backend}/SKILL.md +24 -68
- package/skills/erp-kit-app-5-impl-backend/references/app-config.md +38 -0
- package/skills/erp-kit-app-5-impl-backend/references/module-wiring.md +48 -0
- package/skills/erp-kit-app-5-impl-backend/references/resolver-patterns.md +68 -0
- package/skills/erp-kit-app-6-impl-frontend/SKILL.md +74 -0
- package/skills/{erp-kit-app-5-implementation/references/frontend.md → erp-kit-app-6-impl-frontend/references/pages.md} +8 -90
- package/skills/erp-kit-app-7-impl-review/SKILL.md +176 -0
- package/skills/erp-kit-app-7-impl-review/references/impl-parity-report-format.md +52 -0
- package/skills/erp-kit-app-7-impl-review/references/module-wiring-parity.md +84 -0
- package/skills/erp-kit-app-7-impl-review/references/resolver-doc-code-parity.md +86 -0
- package/skills/erp-kit-app-7-impl-review/references/screen-doc-code-parity.md +86 -0
- package/skills/erp-kit-module-1-requirements/SKILL.md +126 -0
- package/skills/erp-kit-module-1-requirements/references/boundary-analysis.md +51 -0
- package/skills/erp-kit-module-1-requirements/references/erp-research.md +57 -0
- package/skills/erp-kit-module-1-requirements/references/feature-doc.md +61 -0
- package/skills/erp-kit-module-2-requirements-review/SKILL.md +112 -0
- package/skills/erp-kit-module-2-requirements-review/references/best-practices-check.md +79 -0
- package/skills/erp-kit-module-2-requirements-review/references/boundary-consistency-check.md +70 -0
- package/skills/erp-kit-module-2-requirements-review/references/requirements-report-format.md +25 -0
- package/skills/erp-kit-module-3-plan/SKILL.md +107 -0
- package/skills/erp-kit-module-3-plan/references/command-extraction.md +87 -0
- package/skills/erp-kit-module-3-plan/references/model-extraction.md +72 -0
- package/skills/erp-kit-module-3-plan/references/query-extraction.md +59 -0
- package/skills/erp-kit-module-4-plan-review/SKILL.md +158 -0
- package/skills/erp-kit-module-4-plan-review/references/command-model-consistency.md +46 -0
- package/skills/erp-kit-module-4-plan-review/references/feature-command-parity.md +97 -0
- package/skills/erp-kit-module-4-plan-review/references/feature-model-parity.md +47 -0
- package/skills/erp-kit-module-4-plan-review/references/feature-query-parity.md +70 -0
- package/skills/erp-kit-module-4-plan-review/references/parity-report-format.md +52 -0
- package/skills/erp-kit-module-5-impl/SKILL.md +118 -0
- package/skills/erp-kit-module-5-impl/references/command-impl.md +68 -0
- package/skills/erp-kit-module-5-impl/references/exports.md +10 -0
- package/skills/erp-kit-module-5-impl/references/model-impl.md +45 -0
- package/skills/erp-kit-module-5-impl/references/query-impl.md +53 -0
- package/skills/erp-kit-module-6-impl-review/SKILL.md +187 -0
- package/skills/erp-kit-module-6-impl-review/references/command-doc-code-parity.md +92 -0
- package/skills/erp-kit-module-6-impl-review/references/command-doc-test-parity.md +93 -0
- package/skills/erp-kit-module-6-impl-review/references/error-implementation-parity.md +95 -0
- package/skills/{erp-kit-module-5-impl-review → erp-kit-module-6-impl-review}/references/errors.md +1 -1
- package/skills/erp-kit-module-6-impl-review/references/impl-parity-report-format.md +52 -0
- package/skills/erp-kit-module-6-impl-review/references/model-doc-code-parity.md +80 -0
- package/skills/erp-kit-module-shared/SKILL.md +1 -1
- package/skills/erp-kit-module-shared/references/commands.md +1 -1
- package/skills/erp-kit-module-shared/references/errors.md +12 -9
- package/skills/erp-kit-module-shared/references/queries.md +109 -36
- package/skills/erp-kit-module-shared/references/testing.md +10 -0
- package/skills/erp-kit-update/SKILL.md +2 -2
- package/src/app.ts +1 -1
- package/src/commands/check.ts +1 -1
- package/src/commands/index.ts +16 -5
- package/src/commands/init.test.ts +22 -69
- package/src/commands/init.ts +28 -115
- package/src/commands/lib/distribute.test.ts +126 -0
- package/src/commands/lib/distribute.ts +129 -0
- package/src/commands/parse-doc-test-cases.ts +55 -0
- package/src/commands/scaffold.test.ts +74 -33
- package/src/commands/scaffold.ts +54 -18
- package/src/commands/sync-check.test.ts +173 -0
- package/src/commands/sync-check.ts +103 -2
- package/src/commands/update.test.ts +87 -0
- package/src/commands/update.ts +41 -0
- package/src/generator/generate-code.test.ts +23 -12
- package/src/generator/generate-code.ts +22 -16
- package/src/integration.test.ts +1 -1
- package/src/module.ts +14 -97
- package/src/modules/item-management/README.md +8 -0
- package/src/modules/item-management/command/activateItem.generated.ts +1 -1
- package/src/modules/item-management/command/activateItem.test.ts +12 -18
- package/src/modules/item-management/command/activateItem.ts +9 -5
- package/src/modules/item-management/command/assignItemToTaxonomy.generated.ts +1 -1
- package/src/modules/item-management/command/assignItemToTaxonomy.test.ts +10 -24
- package/src/modules/item-management/command/assignItemToTaxonomy.ts +19 -16
- package/src/modules/item-management/command/createItem.generated.ts +1 -1
- package/src/modules/item-management/command/createItem.test.ts +11 -11
- package/src/modules/item-management/command/createItem.ts +16 -7
- package/src/modules/item-management/command/createTaxonomyNode.generated.ts +1 -1
- package/src/modules/item-management/command/createTaxonomyNode.test.ts +9 -9
- package/src/modules/item-management/command/createTaxonomyNode.ts +33 -14
- package/src/modules/item-management/command/deactivateItem.generated.ts +1 -1
- package/src/modules/item-management/command/deactivateItem.test.ts +12 -18
- package/src/modules/item-management/command/deactivateItem.ts +9 -5
- package/src/modules/item-management/command/deleteItem.generated.ts +1 -1
- package/src/modules/item-management/command/deleteItem.test.ts +10 -16
- package/src/modules/item-management/command/deleteItem.ts +9 -5
- package/src/modules/item-management/command/deleteTaxonomyNode.generated.ts +1 -1
- package/src/modules/item-management/command/deleteTaxonomyNode.test.ts +10 -16
- package/src/modules/item-management/command/deleteTaxonomyNode.ts +22 -12
- package/src/modules/item-management/command/moveTaxonomyNode.generated.ts +1 -1
- package/src/modules/item-management/command/moveTaxonomyNode.test.ts +10 -10
- package/src/modules/item-management/command/moveTaxonomyNode.ts +63 -19
- package/src/modules/item-management/command/reactivateItem.generated.ts +1 -1
- package/src/modules/item-management/command/reactivateItem.test.ts +12 -18
- package/src/modules/item-management/command/reactivateItem.ts +9 -5
- package/src/modules/item-management/command/removeItemFromTaxonomy.generated.ts +1 -1
- package/src/modules/item-management/command/removeItemFromTaxonomy.test.ts +9 -16
- package/src/modules/item-management/command/removeItemFromTaxonomy.ts +11 -6
- package/src/modules/item-management/command/updateItem.generated.ts +1 -1
- package/src/modules/item-management/command/updateItem.test.ts +16 -16
- package/src/modules/item-management/command/updateItem.ts +11 -6
- package/src/modules/item-management/command/updateTaxonomyNode.generated.ts +1 -1
- package/src/modules/item-management/command/updateTaxonomyNode.test.ts +14 -20
- package/src/modules/item-management/command/updateTaxonomyNode.ts +9 -6
- package/src/modules/item-management/docs/commands/ActivateItem.md +8 -0
- package/src/modules/item-management/docs/commands/AssignItemToTaxonomy.md +7 -0
- package/src/modules/item-management/docs/commands/CreateItem.md +10 -0
- package/src/modules/item-management/docs/commands/CreateTaxonomyNode.md +9 -0
- package/src/modules/item-management/docs/commands/DeactivateItem.md +8 -0
- package/src/modules/item-management/docs/commands/DeleteItem.md +7 -0
- package/src/modules/item-management/docs/commands/DeleteTaxonomyNode.md +7 -0
- package/src/modules/item-management/docs/commands/MoveTaxonomyNode.md +10 -0
- package/src/modules/item-management/docs/commands/ReactivateItem.md +8 -0
- package/src/modules/item-management/docs/commands/RemoveItemFromTaxonomy.md +5 -0
- package/src/modules/item-management/docs/commands/UpdateItem.md +15 -0
- package/src/modules/item-management/docs/commands/UpdateTaxonomyNode.md +9 -0
- package/src/modules/item-management/docs/queries/CalculateNodeDepth.md +8 -0
- package/src/modules/item-management/docs/queries/CalculateSubtreeDepth.md +7 -0
- package/src/modules/item-management/docs/queries/DetectCircularReference.md +9 -0
- package/src/modules/item-management/docs/queries/GetItem.md +9 -0
- package/src/modules/item-management/docs/queries/GetItemTaxonomyAssignment.md +5 -0
- package/src/modules/item-management/docs/queries/GetTaxonomyNode.md +7 -0
- package/src/modules/item-management/docs/queries/GetTaxonomyNodeAssignments.md +5 -0
- package/src/modules/item-management/docs/queries/GetTaxonomyNodeChildren.md +6 -0
- package/src/modules/item-management/index.ts +0 -51
- package/src/modules/item-management/lib/errors.generated.ts +24 -24
- package/src/modules/item-management/lib/permissions.generated.ts +1 -1
- package/src/modules/item-management/lib/types.ts +1 -1
- package/src/modules/item-management/module.ts +1 -1
- package/src/modules/item-management/query/calculateNodeDepth.generated.ts +1 -1
- package/src/modules/item-management/query/calculateNodeDepth.test.ts +21 -6
- package/src/modules/item-management/query/calculateNodeDepth.ts +2 -2
- package/src/modules/item-management/query/calculateSubtreeDepth.generated.ts +1 -1
- package/src/modules/item-management/query/calculateSubtreeDepth.test.ts +17 -5
- package/src/modules/item-management/query/calculateSubtreeDepth.ts +2 -2
- package/src/modules/item-management/query/detectCircularReference.generated.ts +1 -1
- package/src/modules/item-management/query/detectCircularReference.test.ts +25 -7
- package/src/modules/item-management/query/detectCircularReference.ts +4 -4
- package/src/modules/item-management/query/getItem.generated.ts +1 -1
- package/src/modules/item-management/query/getItem.test.ts +25 -7
- package/src/modules/item-management/query/getItem.ts +2 -2
- package/src/modules/item-management/query/getItemTaxonomyAssignment.generated.ts +1 -1
- package/src/modules/item-management/query/getItemTaxonomyAssignment.test.ts +9 -3
- package/src/modules/item-management/query/getItemTaxonomyAssignment.ts +2 -2
- package/src/modules/item-management/query/getTaxonomyNode.generated.ts +1 -1
- package/src/modules/item-management/query/getTaxonomyNode.test.ts +17 -5
- package/src/modules/item-management/query/getTaxonomyNode.ts +2 -2
- package/src/modules/item-management/query/getTaxonomyNodeAssignments.generated.ts +1 -1
- package/src/modules/item-management/query/getTaxonomyNodeAssignments.test.ts +9 -3
- package/src/modules/item-management/query/getTaxonomyNodeAssignments.ts +2 -2
- package/src/modules/item-management/query/getTaxonomyNodeChildren.generated.ts +1 -1
- package/src/modules/item-management/query/getTaxonomyNodeChildren.test.ts +13 -4
- package/src/modules/item-management/query/getTaxonomyNodeChildren.ts +2 -2
- package/src/modules/item-management/tailor.config.ts +6 -4
- package/src/modules/item-management/tailor.d.ts +13 -0
- package/src/modules/primitives/README.md +8 -0
- package/src/modules/primitives/command/activateCategory.generated.ts +1 -1
- package/src/modules/primitives/command/activateCategory.test.ts +8 -18
- package/src/modules/primitives/command/activateCategory.ts +9 -5
- package/src/modules/primitives/command/activateCurrency.generated.ts +1 -1
- package/src/modules/primitives/command/activateCurrency.test.ts +8 -18
- package/src/modules/primitives/command/activateCurrency.ts +9 -5
- package/src/modules/primitives/command/activateUnit.generated.ts +1 -1
- package/src/modules/primitives/command/activateUnit.test.ts +8 -15
- package/src/modules/primitives/command/activateUnit.ts +9 -5
- package/src/modules/primitives/command/createCategory.generated.ts +1 -1
- package/src/modules/primitives/command/createCategory.test.ts +29 -44
- package/src/modules/primitives/command/createCategory.ts +9 -5
- package/src/modules/primitives/command/createCurrency.generated.ts +1 -1
- package/src/modules/primitives/command/createCurrency.test.ts +53 -78
- package/src/modules/primitives/command/createCurrency.ts +9 -6
- package/src/modules/primitives/command/createExchangeRate.generated.ts +1 -1
- package/src/modules/primitives/command/createExchangeRate.test.ts +59 -97
- package/src/modules/primitives/command/createExchangeRate.ts +13 -7
- package/src/modules/primitives/command/createUnit.generated.ts +1 -1
- package/src/modules/primitives/command/createUnit.test.ts +59 -90
- package/src/modules/primitives/command/createUnit.ts +9 -6
- package/src/modules/primitives/command/deactivateCategory.generated.ts +1 -1
- package/src/modules/primitives/command/deactivateCategory.test.ts +15 -33
- package/src/modules/primitives/command/deactivateCategory.ts +9 -5
- package/src/modules/primitives/command/deactivateCurrency.generated.ts +1 -1
- package/src/modules/primitives/command/deactivateCurrency.test.ts +12 -26
- package/src/modules/primitives/command/deactivateCurrency.ts +9 -5
- package/src/modules/primitives/command/deactivateUnit.generated.ts +1 -1
- package/src/modules/primitives/command/deactivateUnit.test.ts +15 -30
- package/src/modules/primitives/command/deactivateUnit.ts +14 -7
- package/src/modules/primitives/command/setBaseCurrency.generated.ts +1 -1
- package/src/modules/primitives/command/setBaseCurrency.test.ts +18 -40
- package/src/modules/primitives/command/setBaseCurrency.ts +15 -7
- package/src/modules/primitives/command/setReferenceUnit.generated.ts +1 -1
- package/src/modules/primitives/command/setReferenceUnit.test.ts +22 -44
- package/src/modules/primitives/command/setReferenceUnit.ts +21 -9
- package/src/modules/primitives/docs/commands/ActivateCategory.md +6 -0
- package/src/modules/primitives/docs/commands/ActivateCurrency.md +6 -0
- package/src/modules/primitives/docs/commands/ActivateUnit.md +6 -0
- package/src/modules/primitives/docs/commands/CreateCategory.md +6 -0
- package/src/modules/primitives/docs/commands/CreateCurrency.md +10 -0
- package/src/modules/primitives/docs/commands/CreateExchangeRate.md +11 -0
- package/src/modules/primitives/docs/commands/CreateUnit.md +10 -0
- package/src/modules/primitives/docs/commands/DeactivateCategory.md +7 -0
- package/src/modules/primitives/docs/commands/DeactivateCurrency.md +7 -0
- package/src/modules/primitives/docs/commands/DeactivateUnit.md +7 -0
- package/src/modules/primitives/docs/commands/SetBaseCurrency.md +7 -0
- package/src/modules/primitives/docs/commands/SetReferenceUnit.md +7 -0
- package/src/modules/primitives/docs/queries/ConvertAmount.md +14 -0
- package/src/modules/primitives/docs/queries/ConvertQuantity.md +13 -0
- package/src/modules/primitives/docs/queries/GetBaseCurrency.md +5 -0
- package/src/modules/primitives/docs/queries/GetCurrency.md +7 -0
- package/src/modules/primitives/docs/queries/GetUnit.md +7 -0
- package/src/modules/primitives/docs/queries/GetUoMCategory.md +7 -0
- package/src/modules/primitives/docs/queries/ListUnitsByCategory.md +15 -5
- package/src/modules/primitives/index.ts +0 -49
- package/src/modules/primitives/lib/errors.generated.ts +23 -23
- package/src/modules/primitives/lib/permissions.generated.ts +1 -1
- package/src/modules/primitives/lib/types.ts +1 -1
- package/src/modules/primitives/module.ts +1 -1
- package/src/modules/primitives/query/convertAmount.generated.ts +1 -1
- package/src/modules/primitives/query/convertAmount.test.ts +110 -77
- package/src/modules/primitives/query/convertAmount.ts +61 -47
- package/src/modules/primitives/query/convertQuantity.generated.ts +1 -1
- package/src/modules/primitives/query/convertQuantity.test.ts +99 -69
- package/src/modules/primitives/query/convertQuantity.ts +12 -10
- package/src/modules/primitives/query/getBaseCurrency.generated.ts +1 -1
- package/src/modules/primitives/query/getBaseCurrency.test.ts +10 -4
- package/src/modules/primitives/query/getBaseCurrency.ts +2 -2
- package/src/modules/primitives/query/getCurrency.generated.ts +1 -1
- package/src/modules/primitives/query/getCurrency.test.ts +17 -5
- package/src/modules/primitives/query/getCurrency.ts +2 -2
- package/src/modules/primitives/query/getUnit.generated.ts +1 -1
- package/src/modules/primitives/query/getUnit.test.ts +17 -5
- package/src/modules/primitives/query/getUnit.ts +2 -2
- package/src/modules/primitives/query/getUoMCategory.generated.ts +1 -1
- package/src/modules/primitives/query/getUoMCategory.test.ts +17 -5
- package/src/modules/primitives/query/getUoMCategory.ts +2 -2
- package/src/modules/primitives/query/listUnitsByCategory.generated.ts +1 -1
- package/src/modules/primitives/query/listUnitsByCategory.test.ts +80 -0
- package/src/modules/primitives/query/listUnitsByCategory.ts +19 -3
- package/src/modules/primitives/tailor.config.ts +6 -4
- package/src/modules/primitives/tailor.d.ts +13 -0
- package/src/modules/product-management/README.md +52 -0
- package/src/modules/product-management/command/activateProduct.generated.ts +6 -0
- package/src/modules/product-management/command/activateProduct.test.ts +40 -0
- package/src/modules/product-management/command/activateProduct.ts +42 -0
- package/src/modules/product-management/command/assignProductToCategory.generated.ts +6 -0
- package/src/modules/product-management/command/assignProductToCategory.test.ts +90 -0
- package/src/modules/product-management/command/assignProductToCategory.ts +62 -0
- package/src/modules/product-management/command/createProduct.generated.ts +6 -0
- package/src/modules/product-management/command/createProduct.test.ts +149 -0
- package/src/modules/product-management/command/createProduct.ts +73 -0
- package/src/modules/product-management/command/createProductAttribute.generated.ts +6 -0
- package/src/modules/product-management/command/createProductAttribute.test.ts +70 -0
- package/src/modules/product-management/command/createProductAttribute.ts +53 -0
- package/src/modules/product-management/command/createProductAttributeValue.generated.ts +6 -0
- package/src/modules/product-management/command/createProductAttributeValue.test.ts +68 -0
- package/src/modules/product-management/command/createProductAttributeValue.ts +63 -0
- package/src/modules/product-management/command/createProductCategory.generated.ts +6 -0
- package/src/modules/product-management/command/createProductCategory.test.ts +135 -0
- package/src/modules/product-management/command/createProductCategory.ts +82 -0
- package/src/modules/product-management/command/deactivateProduct.generated.ts +6 -0
- package/src/modules/product-management/command/deactivateProduct.test.ts +40 -0
- package/src/modules/product-management/command/deactivateProduct.ts +42 -0
- package/src/modules/product-management/command/deleteProduct.generated.ts +6 -0
- package/src/modules/product-management/command/deleteProduct.test.ts +42 -0
- package/src/modules/product-management/command/deleteProduct.ts +42 -0
- package/src/modules/product-management/command/deleteProductAttribute.generated.ts +6 -0
- package/src/modules/product-management/command/deleteProductAttribute.test.ts +49 -0
- package/src/modules/product-management/command/deleteProductAttribute.ts +45 -0
- package/src/modules/product-management/command/deleteProductAttributeValue.generated.ts +6 -0
- package/src/modules/product-management/command/deleteProductAttributeValue.test.ts +71 -0
- package/src/modules/product-management/command/deleteProductAttributeValue.ts +68 -0
- package/src/modules/product-management/command/deleteProductCategory.generated.ts +6 -0
- package/src/modules/product-management/command/deleteProductCategory.test.ts +74 -0
- package/src/modules/product-management/command/deleteProductCategory.ts +53 -0
- package/src/modules/product-management/command/generateVariants.generated.ts +6 -0
- package/src/modules/product-management/command/generateVariants.test.ts +365 -0
- package/src/modules/product-management/command/generateVariants.ts +168 -0
- package/src/modules/product-management/command/moveProductCategory.generated.ts +6 -0
- package/src/modules/product-management/command/moveProductCategory.test.ts +170 -0
- package/src/modules/product-management/command/moveProductCategory.ts +124 -0
- package/src/modules/product-management/command/reactivateProduct.generated.ts +6 -0
- package/src/modules/product-management/command/reactivateProduct.test.ts +40 -0
- package/src/modules/product-management/command/reactivateProduct.ts +42 -0
- package/src/modules/product-management/command/removeProductFromCategory.generated.ts +6 -0
- package/src/modules/product-management/command/removeProductFromCategory.test.ts +42 -0
- package/src/modules/product-management/command/removeProductFromCategory.ts +32 -0
- package/src/modules/product-management/command/setProductAttributeAssignment.generated.ts +6 -0
- package/src/modules/product-management/command/setProductAttributeAssignment.test.ts +206 -0
- package/src/modules/product-management/command/setProductAttributeAssignment.ts +102 -0
- package/src/modules/product-management/command/updateProduct.generated.ts +6 -0
- package/src/modules/product-management/command/updateProduct.test.ts +168 -0
- package/src/modules/product-management/command/updateProduct.ts +95 -0
- package/src/modules/product-management/command/updateProductAttribute.generated.ts +6 -0
- package/src/modules/product-management/command/updateProductAttribute.test.ts +101 -0
- package/src/modules/product-management/command/updateProductAttribute.ts +68 -0
- package/src/modules/product-management/command/updateProductAttributeValue.generated.ts +6 -0
- package/src/modules/product-management/command/updateProductAttributeValue.test.ts +80 -0
- package/src/modules/product-management/command/updateProductAttributeValue.ts +58 -0
- package/src/modules/product-management/command/updateProductCategory.generated.ts +6 -0
- package/src/modules/product-management/command/updateProductCategory.test.ts +80 -0
- package/src/modules/product-management/command/updateProductCategory.ts +66 -0
- package/src/modules/product-management/db/product.ts +47 -0
- package/src/modules/product-management/db/productAttribute.ts +26 -0
- package/src/modules/product-management/db/productAttributeAssignment.ts +58 -0
- package/src/modules/product-management/db/productAttributeValue.ts +39 -0
- package/src/modules/product-management/db/productCategory.ts +34 -0
- package/src/modules/product-management/db/productCategoryAssignment.ts +49 -0
- package/src/modules/product-management/db/productVariant.ts +52 -0
- package/src/modules/product-management/docs/commands/ActivateProduct.md +39 -0
- package/src/modules/product-management/docs/commands/AssignProductToCategory.md +43 -0
- package/src/modules/product-management/docs/commands/CreateProduct.md +48 -0
- package/src/modules/product-management/docs/commands/CreateProductAttribute.md +39 -0
- package/src/modules/product-management/docs/commands/CreateProductAttributeValue.md +42 -0
- package/src/modules/product-management/docs/commands/CreateProductCategory.md +54 -0
- package/src/modules/product-management/docs/commands/DeactivateProduct.md +39 -0
- package/src/modules/product-management/docs/commands/DeleteProduct.md +42 -0
- package/src/modules/product-management/docs/commands/DeleteProductAttribute.md +39 -0
- package/src/modules/product-management/docs/commands/DeleteProductAttributeValue.md +42 -0
- package/src/modules/product-management/docs/commands/DeleteProductCategory.md +43 -0
- package/src/modules/product-management/docs/commands/GenerateVariants.md +68 -0
- package/src/modules/product-management/docs/commands/MoveProductCategory.md +54 -0
- package/src/modules/product-management/docs/commands/ReactivateProduct.md +38 -0
- package/src/modules/product-management/docs/commands/RemoveProductFromCategory.md +34 -0
- package/src/modules/product-management/docs/commands/SetProductAttributeAssignment.md +62 -0
- package/src/modules/product-management/docs/commands/UpdateProduct.md +61 -0
- package/src/modules/product-management/docs/commands/UpdateProductAttribute.md +46 -0
- package/src/modules/product-management/docs/commands/UpdateProductAttributeValue.md +47 -0
- package/src/modules/product-management/docs/commands/UpdateProductCategory.md +46 -0
- package/src/modules/product-management/docs/features/attribute-management.md +48 -0
- package/src/modules/product-management/docs/features/product-category.md +71 -0
- package/src/modules/product-management/docs/features/product-lifecycle.md +66 -0
- package/src/modules/product-management/docs/features/variant-generation.md +77 -0
- package/src/modules/product-management/docs/models/Product.md +58 -0
- package/src/modules/product-management/docs/models/ProductAttribute.md +37 -0
- package/src/modules/product-management/docs/models/ProductAttributeAssignment.md +41 -0
- package/src/modules/product-management/docs/models/ProductAttributeValue.md +40 -0
- package/src/modules/product-management/docs/models/ProductCategory.md +46 -0
- package/src/modules/product-management/docs/models/ProductCategoryAssignment.md +37 -0
- package/src/modules/product-management/docs/models/ProductVariant.md +41 -0
- package/src/modules/product-management/docs/queries/CalculateCategoryDepth.md +47 -0
- package/src/modules/product-management/docs/queries/DetectCategoryCircularReference.md +51 -0
- package/src/modules/product-management/docs/queries/GetProduct.md +42 -0
- package/src/modules/product-management/docs/queries/GetProductAttribute.md +42 -0
- package/src/modules/product-management/docs/queries/GetProductAttributeAssignment.md +34 -0
- package/src/modules/product-management/docs/queries/GetProductAttributeValue.md +40 -0
- package/src/modules/product-management/docs/queries/GetProductCategory.md +42 -0
- package/src/modules/product-management/docs/queries/GetProductCategoryAssignment.md +34 -0
- package/src/modules/product-management/docs/queries/GetProductVariant.md +41 -0
- package/src/modules/product-management/docs/queries/ListAttributeAssignmentsByAttribute.md +34 -0
- package/src/modules/product-management/docs/queries/ListCategoryAssignmentsByProduct.md +35 -0
- package/src/modules/product-management/docs/queries/ListProductAttributeAssignments.md +34 -0
- package/src/modules/product-management/docs/queries/ListProductAttributeValues.md +36 -0
- package/src/modules/product-management/docs/queries/ListProductCategoryAssignments.md +34 -0
- package/src/modules/product-management/docs/queries/ListProductCategoryChildren.md +34 -0
- package/src/modules/product-management/docs/queries/ListProductVariants.md +34 -0
- package/src/modules/product-management/generated/enums.ts +9 -0
- package/src/modules/product-management/generated/kysely-tailordb.ts +100 -0
- package/src/modules/product-management/index.ts +2 -0
- package/src/modules/product-management/lib/_db_deps.ts +17 -0
- package/src/modules/product-management/lib/errors.generated.ts +152 -0
- package/src/modules/product-management/lib/permissions.generated.ts +25 -0
- package/src/modules/product-management/lib/types.ts +51 -0
- package/src/modules/product-management/module.ts +201 -0
- package/src/modules/product-management/query/calculateCategoryDepth.generated.ts +5 -0
- package/src/modules/product-management/query/calculateCategoryDepth.test.ts +72 -0
- package/src/modules/product-management/query/calculateCategoryDepth.ts +37 -0
- package/src/modules/product-management/query/detectCategoryCircularReference.generated.ts +5 -0
- package/src/modules/product-management/query/detectCategoryCircularReference.test.ts +72 -0
- package/src/modules/product-management/query/detectCategoryCircularReference.ts +44 -0
- package/src/modules/product-management/query/getProduct.generated.ts +5 -0
- package/src/modules/product-management/query/getProduct.test.ts +59 -0
- package/src/modules/product-management/query/getProduct.ts +18 -0
- package/src/modules/product-management/query/getProductAttribute.generated.ts +5 -0
- package/src/modules/product-management/query/getProductAttribute.test.ts +59 -0
- package/src/modules/product-management/query/getProductAttribute.ts +18 -0
- package/src/modules/product-management/query/getProductAttributeAssignment.generated.ts +5 -0
- package/src/modules/product-management/query/getProductAttributeAssignment.test.ts +37 -0
- package/src/modules/product-management/query/getProductAttributeAssignment.ts +18 -0
- package/src/modules/product-management/query/getProductAttributeValue.generated.ts +5 -0
- package/src/modules/product-management/query/getProductAttributeValue.test.ts +31 -0
- package/src/modules/product-management/query/getProductAttributeValue.ts +16 -0
- package/src/modules/product-management/query/getProductCategory.generated.ts +5 -0
- package/src/modules/product-management/query/getProductCategory.test.ts +59 -0
- package/src/modules/product-management/query/getProductCategory.ts +18 -0
- package/src/modules/product-management/query/getProductCategoryAssignment.generated.ts +5 -0
- package/src/modules/product-management/query/getProductCategoryAssignment.test.ts +37 -0
- package/src/modules/product-management/query/getProductCategoryAssignment.ts +18 -0
- package/src/modules/product-management/query/getProductVariant.generated.ts +5 -0
- package/src/modules/product-management/query/getProductVariant.test.ts +43 -0
- package/src/modules/product-management/query/getProductVariant.ts +20 -0
- package/src/modules/product-management/query/listAttributeAssignmentsByAttribute.generated.ts +5 -0
- package/src/modules/product-management/query/listAttributeAssignmentsByAttribute.test.ts +31 -0
- package/src/modules/product-management/query/listAttributeAssignmentsByAttribute.ts +16 -0
- package/src/modules/product-management/query/listCategoryAssignmentsByProduct.generated.ts +5 -0
- package/src/modules/product-management/query/listCategoryAssignmentsByProduct.test.ts +31 -0
- package/src/modules/product-management/query/listCategoryAssignmentsByProduct.ts +16 -0
- package/src/modules/product-management/query/listProductAttributeAssignments.generated.ts +5 -0
- package/src/modules/product-management/query/listProductAttributeAssignments.test.ts +31 -0
- package/src/modules/product-management/query/listProductAttributeAssignments.ts +16 -0
- package/src/modules/product-management/query/listProductAttributeValues.generated.ts +5 -0
- package/src/modules/product-management/query/listProductAttributeValues.test.ts +31 -0
- package/src/modules/product-management/query/listProductAttributeValues.ts +17 -0
- package/src/modules/product-management/query/listProductCategoryAssignments.generated.ts +5 -0
- package/src/modules/product-management/query/listProductCategoryAssignments.test.ts +31 -0
- package/src/modules/product-management/query/listProductCategoryAssignments.ts +16 -0
- package/src/modules/product-management/query/listProductCategoryChildren.generated.ts +5 -0
- package/src/modules/product-management/query/listProductCategoryChildren.test.ts +31 -0
- package/src/modules/product-management/query/listProductCategoryChildren.ts +16 -0
- package/src/modules/product-management/query/listProductVariants.generated.ts +5 -0
- package/src/modules/product-management/query/listProductVariants.test.ts +31 -0
- package/src/modules/product-management/query/listProductVariants.ts +16 -0
- package/src/modules/product-management/tailor.config.ts +13 -0
- package/src/modules/product-management/tailor.d.ts +13 -0
- package/src/modules/product-management/testing/fixtures.ts +151 -0
- package/src/modules/user-management/README.md +9 -3
- package/src/modules/user-management/command/activateUser.generated.ts +1 -1
- package/src/modules/user-management/command/activateUser.test.ts +12 -65
- package/src/modules/user-management/command/activateUser.ts +5 -20
- package/src/modules/user-management/command/assignPermissionToRole.generated.ts +1 -1
- package/src/modules/user-management/command/assignPermissionToRole.test.ts +25 -60
- package/src/modules/user-management/command/assignPermissionToRole.ts +5 -24
- package/src/modules/user-management/command/assignRoleToUser.generated.ts +1 -1
- package/src/modules/user-management/command/assignRoleToUser.test.ts +35 -87
- package/src/modules/user-management/command/assignRoleToUser.ts +5 -24
- package/src/modules/user-management/command/createPermission.generated.ts +1 -1
- package/src/modules/user-management/command/createPermission.test.ts +23 -33
- package/src/modules/user-management/command/createPermission.ts +4 -5
- package/src/modules/user-management/command/createRole.generated.ts +1 -1
- package/src/modules/user-management/command/createRole.test.ts +17 -27
- package/src/modules/user-management/command/createRole.ts +4 -5
- package/src/modules/user-management/command/createUser.generated.ts +1 -1
- package/src/modules/user-management/command/createUser.test.ts +31 -118
- package/src/modules/user-management/command/createUser.ts +7 -25
- package/src/modules/user-management/command/deactivateUser.generated.ts +1 -1
- package/src/modules/user-management/command/deactivateUser.test.ts +12 -65
- package/src/modules/user-management/command/deactivateUser.ts +6 -21
- package/src/modules/user-management/command/reactivateUser.generated.ts +1 -1
- package/src/modules/user-management/command/reactivateUser.test.ts +13 -66
- package/src/modules/user-management/command/reactivateUser.ts +5 -20
- package/src/modules/user-management/command/revokePermissionFromRole.generated.ts +1 -1
- package/src/modules/user-management/command/revokePermissionFromRole.test.ts +24 -62
- package/src/modules/user-management/command/revokePermissionFromRole.ts +5 -24
- package/src/modules/user-management/command/revokeRoleFromUser.generated.ts +1 -1
- package/src/modules/user-management/command/revokeRoleFromUser.test.ts +24 -60
- package/src/modules/user-management/command/revokeRoleFromUser.ts +5 -24
- package/src/modules/user-management/docs/commands/ActivateUser.md +7 -0
- package/src/modules/user-management/docs/commands/AssignPermissionToRole.md +7 -0
- package/src/modules/user-management/docs/commands/AssignRoleToUser.md +9 -0
- package/src/modules/user-management/docs/commands/CreatePermission.md +12 -0
- package/src/modules/user-management/docs/commands/CreateRole.md +9 -0
- package/src/modules/user-management/docs/commands/CreateUser.md +11 -0
- package/src/modules/user-management/docs/commands/DeactivateUser.md +7 -0
- package/src/modules/user-management/docs/commands/ReactivateUser.md +7 -0
- package/src/modules/user-management/docs/commands/RevokePermissionFromRole.md +7 -0
- package/src/modules/user-management/docs/commands/RevokeRoleFromUser.md +7 -0
- package/src/modules/user-management/index.ts +0 -30
- package/src/modules/user-management/lib/errors.generated.ts +14 -14
- package/src/modules/user-management/lib/permissions.generated.ts +1 -2
- package/src/modules/user-management/lib/recomputeUserPermissions.ts +4 -3
- package/src/modules/user-management/lib/types.ts +1 -1
- package/src/modules/user-management/module.ts +2 -7
- package/src/modules/user-management/tailor.config.ts +6 -4
- package/src/modules/user-management/tailor.d.ts +13 -0
- package/src/modules/user-management/testing/fixtures.ts +1 -20
- package/src/schemas.ts +1 -1
- package/src/{modules/shared → shared}/defineCommand.test.ts +23 -7
- package/src/{modules/shared → shared}/defineCommand.ts +19 -10
- package/src/{modules/shared/internal.ts → shared/index.ts} +9 -1
- package/src/shared/pagination.test.ts +43 -0
- package/src/shared/pagination.ts +22 -0
- package/src/{modules/shared → shared}/types.ts +13 -0
- package/src/{modules/testing → testing}/index.ts +14 -7
- package/src/testing.ts +1 -1
- package/src/util.ts +8 -0
- package/templates/config/license.config.json +4 -0
- package/templates/scaffold/app/backend/.env.example +1 -0
- package/templates/scaffold/app/backend/__dot__gitignore +4 -0
- package/templates/scaffold/app/backend/eslint.config.js +32 -0
- package/templates/scaffold/app/backend/package.json +31 -0
- package/templates/scaffold/app/backend/seed/data/AuditEvent.jsonl +0 -0
- package/templates/scaffold/app/backend/seed/data/Permission.jsonl +0 -0
- package/templates/scaffold/app/backend/seed/data/Permission.schema.ts +20 -0
- package/templates/scaffold/app/backend/seed/data/Role.jsonl +0 -0
- package/templates/scaffold/app/backend/seed/data/Role.schema.ts +20 -0
- package/templates/scaffold/app/backend/seed/data/RolePermission.jsonl +0 -0
- package/templates/scaffold/app/backend/seed/data/RolePermission.schema.ts +24 -0
- package/templates/scaffold/app/backend/seed/data/User.jsonl +1 -0
- package/templates/scaffold/app/backend/seed/data/User.schema.ts +20 -0
- package/templates/scaffold/app/backend/seed/data/UserRole.jsonl +0 -0
- package/templates/scaffold/app/backend/seed/data/UserRole.schema.ts +24 -0
- package/templates/scaffold/app/backend/seed/data/_User.jsonl +1 -0
- package/templates/scaffold/app/backend/seed/data/_User.schema.ts +30 -0
- package/templates/scaffold/app/backend/seed/exec.mjs +659 -0
- package/templates/scaffold/app/backend/src/executors/permissionCreated.ts +3 -0
- package/templates/scaffold/app/backend/src/executors/permissionDeleted.ts +3 -0
- package/templates/scaffold/app/backend/src/generated/kysely-tailordb.ts +83 -0
- package/templates/scaffold/app/backend/src/modules.ts +9 -0
- package/templates/scaffold/app/backend/src/resolvers/createUser.ts +46 -0
- package/templates/scaffold/app/backend/tailor.config.ts +68 -0
- package/templates/scaffold/app/backend/tailor.d.ts +15 -0
- package/templates/scaffold/app/backend/tsconfig.json +19 -0
- package/templates/scaffold/app/docs/actors/.gitkeep +0 -0
- package/templates/scaffold/app/docs/business-flow/.gitkeep +0 -0
- package/templates/scaffold/app/docs/resolver/.gitkeep +0 -0
- package/templates/scaffold/app/docs/screen/.gitkeep +0 -0
- package/templates/scaffold/app/frontend/.env.example +2 -0
- package/templates/scaffold/app/frontend/__dot__gitignore +3 -0
- package/templates/scaffold/app/frontend/components.json +23 -0
- package/templates/scaffold/app/frontend/eslint.config.js +48 -0
- package/templates/scaffold/app/frontend/index.html +13 -0
- package/templates/scaffold/app/frontend/package.json +53 -0
- package/templates/scaffold/app/frontend/scripts/generate-graphql.mjs +6 -0
- package/templates/scaffold/app/frontend/src/App.tsx +58 -0
- package/templates/scaffold/app/frontend/src/components/composed/empty-state.tsx +26 -0
- package/templates/scaffold/app/frontend/src/components/composed/error-fallback.tsx +28 -0
- package/templates/scaffold/app/frontend/src/components/composed/loading.tsx +13 -0
- package/templates/scaffold/app/frontend/src/components/ui/badge.tsx +39 -0
- package/templates/scaffold/app/frontend/src/components/ui/button.tsx +60 -0
- package/templates/scaffold/app/frontend/src/components/ui/card.tsx +75 -0
- package/templates/scaffold/app/frontend/src/components/ui/form.tsx +152 -0
- package/templates/scaffold/app/frontend/src/components/ui/input.tsx +21 -0
- package/templates/scaffold/app/frontend/src/components/ui/label.tsx +21 -0
- package/templates/scaffold/app/frontend/src/components/ui/spinner.tsx +16 -0
- package/templates/scaffold/app/frontend/src/components/ui/table.tsx +90 -0
- package/templates/scaffold/app/frontend/src/graphql/generated/graphql-env.d.ts +103 -0
- package/templates/scaffold/app/frontend/src/graphql/generated/schema.graphql +1235 -0
- package/templates/scaffold/app/frontend/src/graphql/index.ts +15 -0
- package/templates/scaffold/app/frontend/src/index.css +5 -0
- package/templates/scaffold/app/frontend/src/lib/auth-client.ts +17 -0
- package/templates/scaffold/app/frontend/src/lib/utils.ts +6 -0
- package/templates/scaffold/app/frontend/src/main.tsx +10 -0
- package/templates/scaffold/app/frontend/src/pages/page.tsx +20 -0
- package/templates/scaffold/app/frontend/src/pages/user-management/page.tsx +19 -0
- package/templates/scaffold/app/frontend/src/pages/user-management/profile/page.tsx +97 -0
- package/templates/scaffold/app/frontend/src/pages/user-management/user/[id]/components/user-detail.tsx +58 -0
- package/templates/scaffold/app/frontend/src/pages/user-management/user/[id]/page.tsx +51 -0
- package/templates/scaffold/app/frontend/src/pages/user-management/user/components/users-table.tsx +101 -0
- package/templates/scaffold/app/frontend/src/pages/user-management/user/create/components/create-user-form.tsx +99 -0
- package/templates/scaffold/app/frontend/src/pages/user-management/user/create/page.tsx +19 -0
- package/templates/scaffold/app/frontend/src/pages/user-management/user/page.tsx +61 -0
- package/templates/scaffold/app/frontend/src/providers/graphql-provider.tsx +21 -0
- package/templates/scaffold/app/frontend/tsconfig.app.json +35 -0
- package/templates/scaffold/app/frontend/tsconfig.json +16 -0
- package/templates/scaffold/app/frontend/tsconfig.node.json +23 -0
- package/templates/scaffold/app/frontend/vite.config.ts +23 -0
- package/templates/scaffold/module/command/.gitkeep +0 -0
- package/templates/scaffold/module/db/.gitkeep +0 -0
- package/templates/scaffold/module/executor/.gitkeep +0 -0
- package/templates/scaffold/module/generated/.gitkeep +0 -0
- package/templates/scaffold/module/index.ts +2 -0
- package/templates/scaffold/module/lib/errors.ts +1 -0
- package/templates/scaffold/module/lib/types.ts +4 -0
- package/templates/scaffold/module/module.ts +7 -0
- package/templates/scaffold/module/permissions.ts +3 -0
- package/templates/scaffold/module/query/.gitkeep +0 -0
- package/templates/scaffold/module/tailor.config.ts +13 -0
- package/templates/scaffold/module/testing/fixtures.ts +1 -0
- package/templates/workflows/erp-kit-check.yml +37 -0
- package/dist/cli.js +0 -1654
- package/skills/erp-kit-app-2-breakdown/SKILL.md +0 -88
- package/skills/erp-kit-app-3-doc-review/SKILL.md +0 -112
- package/skills/erp-kit-app-4-impl-spec/SKILL.md +0 -116
- package/skills/erp-kit-app-5-implementation/references/backend.md +0 -232
- package/skills/erp-kit-module-1-docs/SKILL.md +0 -111
- package/skills/erp-kit-module-2-feature-breakdown/SKILL.md +0 -76
- package/skills/erp-kit-module-3-doc-review/SKILL.md +0 -294
- package/skills/erp-kit-module-4-tdd/SKILL.md +0 -94
- package/skills/erp-kit-module-4-tdd/references/exports.md +0 -8
- package/skills/erp-kit-module-5-impl-review/SKILL.md +0 -410
- package/src/commands/scaffold-templates.ts +0 -65
- package/src/modules/shared/index.ts +0 -1
- package/src/modules/user-management/command/logAuditEvent.generated.ts +0 -6
- package/src/modules/user-management/command/logAuditEvent.test.ts +0 -187
- package/src/modules/user-management/command/logAuditEvent.ts +0 -56
- package/src/modules/user-management/db/auditEvent.ts +0 -47
- package/src/modules/user-management/docs/commands/LogAuditEvent.md +0 -37
- package/src/modules/user-management/docs/features/audit-trail.md +0 -80
- package/src/modules/user-management/docs/models/AuditEvent.md +0 -36
- /package/skills/{erp-kit-module-2-feature-breakdown → erp-kit-module-3-plan}/references/naming.md +0 -0
- /package/skills/{erp-kit-module-4-tdd → erp-kit-module-5-impl}/references/cross-module-dependency.md +0 -0
- /package/skills/{erp-kit-module-4-tdd → erp-kit-module-5-impl}/references/db-relations.md +0 -0
- /package/skills/{erp-kit-module-4-tdd → erp-kit-module-5-impl}/references/generated-code.md +0 -0
- /package/skills/{erp-kit-module-4-tdd → erp-kit-module-5-impl}/references/models.md +0 -0
- /package/skills/{erp-kit-module-5-impl-review → erp-kit-module-6-impl-review}/references/commands.md +0 -0
- /package/skills/{erp-kit-module-5-impl-review → erp-kit-module-6-impl-review}/references/testing.md +0 -0
- /package/src/modules/{product-management → audit}/.gitkeep +0 -0
- /package/src/{modules/shared → shared}/createContext.test.ts +0 -0
- /package/src/{modules/shared → shared}/createContext.ts +0 -0
- /package/src/{modules/shared → shared}/definePermissions.test.ts +0 -0
- /package/src/{modules/shared → shared}/definePermissions.ts +0 -0
- /package/src/{modules/shared → shared}/defineQuery.test.ts +0 -0
- /package/src/{modules/shared → shared}/defineQuery.ts +0 -0
- /package/src/{modules/shared → shared}/entityTypes.ts +0 -0
- /package/src/{modules/shared → shared}/errors.ts +0 -0
- /package/src/{modules/shared → shared}/requirePermission.test.ts +0 -0
- /package/src/{modules/shared → shared}/requirePermission.ts +0 -0
- /package/src/{modules/shared → shared}/result.ts +0 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createMockDb } from "../../../testing/index";
|
|
3
|
+
import type { CommandContext } from "../../../shared";
|
|
4
|
+
import type { Transaction } from "../generated/kysely-tailordb";
|
|
5
|
+
import { baseRootCategory, baseChildCategory, baseLeafCategory } from "../testing/fixtures";
|
|
6
|
+
import {
|
|
7
|
+
CategoryNotFoundError,
|
|
8
|
+
ParentNotFoundError,
|
|
9
|
+
CircularReferenceError,
|
|
10
|
+
MaxDepthExceededError,
|
|
11
|
+
} from "../lib/errors.generated";
|
|
12
|
+
import type { MoveProductCategoryInput } from "./moveProductCategory";
|
|
13
|
+
import { run } from "./moveProductCategory";
|
|
14
|
+
|
|
15
|
+
describe("moveProductCategory", () => {
|
|
16
|
+
const ctx: CommandContext = {
|
|
17
|
+
actorId: "test-actor",
|
|
18
|
+
permissions: ["product-management:moveProductCategory"],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const config = { maxDepth: 3 };
|
|
22
|
+
|
|
23
|
+
it("should return CategoryNotFoundError when category does not exist", async () => {
|
|
24
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
25
|
+
// getProductCategory(id) -> null
|
|
26
|
+
spies.select.mockReturnValueOnce(undefined);
|
|
27
|
+
const input: MoveProductCategoryInput = {
|
|
28
|
+
id: "non-existent",
|
|
29
|
+
newParentId: baseRootCategory.id,
|
|
30
|
+
};
|
|
31
|
+
const result = await run(db, input, ctx, config);
|
|
32
|
+
expect(result.ok).toBe(false);
|
|
33
|
+
if (!result.ok) {
|
|
34
|
+
expect(result.error).toBeInstanceOf(CategoryNotFoundError);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should return ParentNotFoundError when new parent does not exist", async () => {
|
|
39
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
40
|
+
// 1. getProductCategory(id) -> found
|
|
41
|
+
spies.select.mockReturnValueOnce(baseChildCategory);
|
|
42
|
+
// 2. getProductCategory(newParentId) -> null
|
|
43
|
+
spies.select.mockReturnValueOnce(undefined);
|
|
44
|
+
const input: MoveProductCategoryInput = {
|
|
45
|
+
id: baseChildCategory.id,
|
|
46
|
+
newParentId: "non-existent",
|
|
47
|
+
};
|
|
48
|
+
const result = await run(db, input, ctx, config);
|
|
49
|
+
expect(result.ok).toBe(false);
|
|
50
|
+
if (!result.ok) {
|
|
51
|
+
expect(result.error).toBeInstanceOf(ParentNotFoundError);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should return CircularReferenceError when move would create a cycle", async () => {
|
|
56
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
57
|
+
// 1. getProductCategory(id=category-1) -> found (root)
|
|
58
|
+
spies.select.mockReturnValueOnce(baseRootCategory);
|
|
59
|
+
// 2. getProductCategory(newParentId=category-3) -> found (leaf, child of child of root)
|
|
60
|
+
spies.select.mockReturnValueOnce(baseLeafCategory);
|
|
61
|
+
// 3. detectCategoryCircularReference walks parent chain from newParentId:
|
|
62
|
+
// input.newParentId !== input.categoryId so enters while loop
|
|
63
|
+
// 1st iteration: select parentId where id=category-3 -> { parentId: "category-2" }
|
|
64
|
+
spies.select.mockReturnValueOnce({ parentId: "category-2" });
|
|
65
|
+
// currentId=category-2, not equal to category-1, continue
|
|
66
|
+
// 2nd iteration: select parentId where id=category-2 -> { parentId: "category-1" }
|
|
67
|
+
spies.select.mockReturnValueOnce({ parentId: "category-1" });
|
|
68
|
+
// currentId=category-1, equals categoryId -> isCircular: true
|
|
69
|
+
|
|
70
|
+
const input: MoveProductCategoryInput = {
|
|
71
|
+
id: baseRootCategory.id,
|
|
72
|
+
newParentId: baseLeafCategory.id,
|
|
73
|
+
};
|
|
74
|
+
const result = await run(db, input, ctx, config);
|
|
75
|
+
expect(result.ok).toBe(false);
|
|
76
|
+
if (!result.ok) {
|
|
77
|
+
expect(result.error).toBeInstanceOf(CircularReferenceError);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("should return MaxDepthExceededError when move would exceed max depth", async () => {
|
|
82
|
+
// Use a scenario: move leaf (category-3) under a deep parent
|
|
83
|
+
const { db: db2, spies: spies2 } = createMockDb<Transaction>();
|
|
84
|
+
// 1. getProductCategory(id=category-3) -> leaf node
|
|
85
|
+
spies2.select.mockReturnValueOnce(baseLeafCategory);
|
|
86
|
+
// 2. getProductCategory(newParentId=category-2) -> child node
|
|
87
|
+
spies2.select.mockReturnValueOnce(baseChildCategory);
|
|
88
|
+
// 3. detectCategoryCircularReference: walk from category-2
|
|
89
|
+
// 1st: id=category-2 -> { parentId: "category-1" }
|
|
90
|
+
spies2.select.mockReturnValueOnce({ parentId: "category-1" });
|
|
91
|
+
// category-1 !== category-3, continue
|
|
92
|
+
// 2nd: id=category-1 -> { parentId: null }
|
|
93
|
+
spies2.select.mockReturnValueOnce({ parentId: null });
|
|
94
|
+
// currentId=null -> break -> isCircular: false
|
|
95
|
+
// 4. calculateCategoryDepth for newParentId=category-2
|
|
96
|
+
// 1st: id=category-2 -> { parentId: "category-1" }
|
|
97
|
+
spies2.select.mockReturnValueOnce({ parentId: "category-1" });
|
|
98
|
+
// 2nd: id=category-1 -> { parentId: null }
|
|
99
|
+
spies2.select.mockReturnValueOnce({ parentId: null });
|
|
100
|
+
// depth=2
|
|
101
|
+
// 5. calculateSubtreeDepth for category-3: no children
|
|
102
|
+
spies2.select.mockReturnValueOnce([]); // execute() returns array for children query
|
|
103
|
+
// subtreeDepth=1, totalDepth=2+1=3, maxDepth=2 -> exceed
|
|
104
|
+
|
|
105
|
+
const input: MoveProductCategoryInput = {
|
|
106
|
+
id: baseLeafCategory.id,
|
|
107
|
+
newParentId: baseChildCategory.id,
|
|
108
|
+
};
|
|
109
|
+
const result = await run(db2, input, ctx, { maxDepth: 2 });
|
|
110
|
+
expect(result.ok).toBe(false);
|
|
111
|
+
if (!result.ok) {
|
|
112
|
+
expect(result.error).toBeInstanceOf(MaxDepthExceededError);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should move category to new parent successfully", async () => {
|
|
117
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
118
|
+
// 1. getProductCategory(id=category-3) -> leaf
|
|
119
|
+
spies.select.mockReturnValueOnce(baseLeafCategory);
|
|
120
|
+
// 2. getProductCategory(newParentId=category-1) -> root
|
|
121
|
+
spies.select.mockReturnValueOnce(baseRootCategory);
|
|
122
|
+
// 3. detectCategoryCircularReference: walk from category-1
|
|
123
|
+
// 1st: id=category-1 -> { parentId: null }
|
|
124
|
+
spies.select.mockReturnValueOnce({ parentId: null });
|
|
125
|
+
// currentId=null -> break -> isCircular: false
|
|
126
|
+
// 4. calculateCategoryDepth for category-1
|
|
127
|
+
// 1st: id=category-1 -> { parentId: null }
|
|
128
|
+
spies.select.mockReturnValueOnce({ parentId: null });
|
|
129
|
+
// depth=1
|
|
130
|
+
// 5. calculateSubtreeDepth for category-3: no children
|
|
131
|
+
spies.select.mockReturnValueOnce([]); // children query -> empty
|
|
132
|
+
// subtreeDepth=1, totalDepth=1+1=2, maxDepth=3 -> ok
|
|
133
|
+
// 6. update returns moved category
|
|
134
|
+
const movedCategory = {
|
|
135
|
+
...baseLeafCategory,
|
|
136
|
+
parentId: baseRootCategory.id,
|
|
137
|
+
updatedAt: new Date(),
|
|
138
|
+
};
|
|
139
|
+
spies.update.mockReturnValueOnce(movedCategory);
|
|
140
|
+
|
|
141
|
+
const input: MoveProductCategoryInput = {
|
|
142
|
+
id: baseLeafCategory.id,
|
|
143
|
+
newParentId: baseRootCategory.id,
|
|
144
|
+
};
|
|
145
|
+
const result = await run(db, input, ctx, config);
|
|
146
|
+
expect(result.ok).toBe(true);
|
|
147
|
+
if (result.ok) {
|
|
148
|
+
expect(result.value.category.parentId).toBe(baseRootCategory.id);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("should promote category to root when newParentId is null", async () => {
|
|
153
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
154
|
+
// 1. getProductCategory(id=category-2) -> child
|
|
155
|
+
spies.select.mockReturnValueOnce(baseChildCategory);
|
|
156
|
+
// newParentId=null -> promote to root, update directly
|
|
157
|
+
const movedCategory = { ...baseChildCategory, parentId: null, updatedAt: new Date() };
|
|
158
|
+
spies.update.mockReturnValueOnce(movedCategory);
|
|
159
|
+
|
|
160
|
+
const input: MoveProductCategoryInput = {
|
|
161
|
+
id: baseChildCategory.id,
|
|
162
|
+
newParentId: null,
|
|
163
|
+
};
|
|
164
|
+
const result = await run(db, input, ctx, config);
|
|
165
|
+
expect(result.ok).toBe(true);
|
|
166
|
+
if (result.ok) {
|
|
167
|
+
expect(result.value.category.parentId).toBeNull();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ok, err, type CommandContext } from "../../../shared";
|
|
2
|
+
import { Transaction } from "../generated/kysely-tailordb";
|
|
3
|
+
import {
|
|
4
|
+
CategoryNotFoundError,
|
|
5
|
+
ParentNotFoundError,
|
|
6
|
+
CircularReferenceError,
|
|
7
|
+
MaxDepthExceededError,
|
|
8
|
+
} from "../lib/errors.generated";
|
|
9
|
+
import { calculateCategoryDepth } from "../query/calculateCategoryDepth.generated";
|
|
10
|
+
|
|
11
|
+
export interface MoveProductCategoryInput {
|
|
12
|
+
id: string;
|
|
13
|
+
newParentId: string | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Function: moveProductCategory
|
|
18
|
+
*
|
|
19
|
+
* Reparents a category node. Moving to null promotes to root.
|
|
20
|
+
*/
|
|
21
|
+
export async function run(
|
|
22
|
+
db: Transaction,
|
|
23
|
+
input: MoveProductCategoryInput,
|
|
24
|
+
ctx: CommandContext,
|
|
25
|
+
config: { maxDepth: number },
|
|
26
|
+
) {
|
|
27
|
+
const { maxDepth } = config;
|
|
28
|
+
const { id, newParentId } = input;
|
|
29
|
+
|
|
30
|
+
const category = await db
|
|
31
|
+
.selectFrom("ProductCategory")
|
|
32
|
+
.selectAll()
|
|
33
|
+
.where("id", "=", id)
|
|
34
|
+
.forUpdate()
|
|
35
|
+
.executeTakeFirst();
|
|
36
|
+
if (!category) {
|
|
37
|
+
return err(new CategoryNotFoundError(id));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Promote to root
|
|
41
|
+
if (newParentId === null) {
|
|
42
|
+
const moved = await db
|
|
43
|
+
.updateTable("ProductCategory")
|
|
44
|
+
.set({ parentId: null, updatedAt: new Date() })
|
|
45
|
+
.where("id", "=", id)
|
|
46
|
+
.returningAll()
|
|
47
|
+
.executeTakeFirst();
|
|
48
|
+
return ok({ category: moved! });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Check new parent exists
|
|
52
|
+
const newParent = await db
|
|
53
|
+
.selectFrom("ProductCategory")
|
|
54
|
+
.select("id")
|
|
55
|
+
.where("id", "=", newParentId)
|
|
56
|
+
.executeTakeFirst();
|
|
57
|
+
if (!newParent) {
|
|
58
|
+
return err(new ParentNotFoundError(newParentId));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Check circular reference
|
|
62
|
+
const isDescendant = await isAncestorOf(db, id, newParentId);
|
|
63
|
+
if (isDescendant) {
|
|
64
|
+
return err(new CircularReferenceError(`${id} -> ${newParentId}`));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Check depth limit: need to calculate subtree depth of moved node
|
|
68
|
+
const depthResult = await calculateCategoryDepth(db, { categoryId: newParentId }, ctx);
|
|
69
|
+
if (!depthResult.ok) return err(new ParentNotFoundError(newParentId));
|
|
70
|
+
const newParentDepth = depthResult.value.depth;
|
|
71
|
+
// Calculate subtree depth of the node being moved
|
|
72
|
+
const subtreeDepth = await calculateSubtreeDepth(db, id);
|
|
73
|
+
const totalDepth = newParentDepth + subtreeDepth;
|
|
74
|
+
|
|
75
|
+
if (totalDepth > maxDepth) {
|
|
76
|
+
return err(new MaxDepthExceededError(`${totalDepth} exceeds ${maxDepth}`));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const moved = await db
|
|
80
|
+
.updateTable("ProductCategory")
|
|
81
|
+
.set({ parentId: newParentId, updatedAt: new Date() })
|
|
82
|
+
.where("id", "=", id)
|
|
83
|
+
.returningAll()
|
|
84
|
+
.executeTakeFirst();
|
|
85
|
+
|
|
86
|
+
return ok({ category: moved! });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Checks if `ancestorId` is an ancestor of `descendantId` by walking up the tree. */
|
|
90
|
+
async function isAncestorOf(
|
|
91
|
+
db: Transaction,
|
|
92
|
+
ancestorId: string,
|
|
93
|
+
descendantId: string,
|
|
94
|
+
): Promise<boolean> {
|
|
95
|
+
let currentId: string | null = descendantId;
|
|
96
|
+
while (currentId) {
|
|
97
|
+
if (currentId === ancestorId) return true;
|
|
98
|
+
const parent = await db
|
|
99
|
+
.selectFrom("ProductCategory")
|
|
100
|
+
.select("parentId")
|
|
101
|
+
.where("id", "=", currentId)
|
|
102
|
+
.executeTakeFirst();
|
|
103
|
+
currentId = parent?.parentId ?? null;
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function calculateSubtreeDepth(db: Transaction, nodeId: string): Promise<number> {
|
|
109
|
+
const children = await db
|
|
110
|
+
.selectFrom("ProductCategory")
|
|
111
|
+
.select("id")
|
|
112
|
+
.where("parentId", "=", nodeId)
|
|
113
|
+
.execute();
|
|
114
|
+
|
|
115
|
+
if (children.length === 0) return 1;
|
|
116
|
+
|
|
117
|
+
let maxChildDepth = 0;
|
|
118
|
+
for (const child of children) {
|
|
119
|
+
const childDepth = await calculateSubtreeDepth(db, child.id);
|
|
120
|
+
if (childDepth > maxChildDepth) maxChildDepth = childDepth;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return 1 + maxChildDepth;
|
|
124
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @generated — do not edit
|
|
2
|
+
import { defineCommand } from "../../../shared";
|
|
3
|
+
import { permissions } from "../lib/permissions.generated";
|
|
4
|
+
import { run } from "./reactivateProduct";
|
|
5
|
+
|
|
6
|
+
export const reactivateProduct = defineCommand(permissions.reactivateProduct, run);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createMockDb } from "../../../testing/index";
|
|
3
|
+
import type { Transaction } from "../generated/kysely-tailordb";
|
|
4
|
+
import { InvalidStateTransitionError, ProductNotFoundError } from "../lib/errors.generated";
|
|
5
|
+
import { baseActiveProduct, baseArchivedProduct } from "../testing/fixtures";
|
|
6
|
+
import { run } from "./reactivateProduct";
|
|
7
|
+
|
|
8
|
+
describe("reactivateProduct", () => {
|
|
9
|
+
it("returns error when product not found", async () => {
|
|
10
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
11
|
+
spies.select.mockReturnValueOnce(undefined);
|
|
12
|
+
const result = await run(db, { id: "nonexistent" });
|
|
13
|
+
expect(result.ok).toBe(false);
|
|
14
|
+
if (!result.ok) {
|
|
15
|
+
expect(result.error).toBeInstanceOf(ProductNotFoundError);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("returns error when not in ARCHIVED status", async () => {
|
|
20
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
21
|
+
spies.select.mockReturnValueOnce({ ...baseActiveProduct });
|
|
22
|
+
const result = await run(db, { id: "product-2" });
|
|
23
|
+
expect(result.ok).toBe(false);
|
|
24
|
+
if (!result.ok) {
|
|
25
|
+
expect(result.error).toBeInstanceOf(InvalidStateTransitionError);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("reactivates ARCHIVED product to ACTIVE", async () => {
|
|
30
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
31
|
+
const reactivated = { ...baseArchivedProduct, status: "ACTIVE" };
|
|
32
|
+
spies.select.mockReturnValueOnce({ ...baseArchivedProduct });
|
|
33
|
+
spies.update.mockReturnValueOnce(reactivated);
|
|
34
|
+
const result = await run(db, { id: "product-3" });
|
|
35
|
+
expect(result.ok).toBe(true);
|
|
36
|
+
if (result.ok) {
|
|
37
|
+
expect(result.value.product.status).toBe("ACTIVE");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ok, err } from "../../../shared";
|
|
2
|
+
import { Transaction } from "../generated/kysely-tailordb";
|
|
3
|
+
import { ProductNotFoundError, InvalidStateTransitionError } from "../lib/errors.generated";
|
|
4
|
+
|
|
5
|
+
export interface ReactivateProductInput {
|
|
6
|
+
id: string;
|
|
7
|
+
from?: string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Function: reactivateProduct
|
|
12
|
+
*
|
|
13
|
+
* Transitions a product from ARCHIVED to ACTIVE.
|
|
14
|
+
*/
|
|
15
|
+
export async function run(db: Transaction, input: ReactivateProductInput) {
|
|
16
|
+
const { id } = input;
|
|
17
|
+
const validFrom = input.from ?? ["ARCHIVED"];
|
|
18
|
+
|
|
19
|
+
const product = await db
|
|
20
|
+
.selectFrom("Product")
|
|
21
|
+
.selectAll()
|
|
22
|
+
.where("id", "=", id)
|
|
23
|
+
.forUpdate()
|
|
24
|
+
.executeTakeFirst();
|
|
25
|
+
|
|
26
|
+
if (!product) {
|
|
27
|
+
return err(new ProductNotFoundError(id));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!validFrom.includes(product.status)) {
|
|
31
|
+
return err(new InvalidStateTransitionError(id));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const updated = await db
|
|
35
|
+
.updateTable("Product")
|
|
36
|
+
.set({ status: "ACTIVE", updatedAt: new Date() })
|
|
37
|
+
.where("id", "=", id)
|
|
38
|
+
.returningAll()
|
|
39
|
+
.executeTakeFirst();
|
|
40
|
+
|
|
41
|
+
return ok({ product: updated! });
|
|
42
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @generated — do not edit
|
|
2
|
+
import { defineCommand } from "../../../shared";
|
|
3
|
+
import { permissions } from "../lib/permissions.generated";
|
|
4
|
+
import { run } from "./removeProductFromCategory";
|
|
5
|
+
|
|
6
|
+
export const removeProductFromCategory = defineCommand(permissions.removeProductFromCategory, run);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createMockDb } from "../../../testing/index";
|
|
3
|
+
import type { Transaction } from "../generated/kysely-tailordb";
|
|
4
|
+
import { baseCategoryAssignment } from "../testing/fixtures";
|
|
5
|
+
import { AssignmentNotFoundError } from "../lib/errors.generated";
|
|
6
|
+
import type { RemoveProductFromCategoryInput } from "./removeProductFromCategory";
|
|
7
|
+
import { run } from "./removeProductFromCategory";
|
|
8
|
+
|
|
9
|
+
describe("removeProductFromCategory", () => {
|
|
10
|
+
it("should return AssignmentNotFoundError when assignment does not exist", async () => {
|
|
11
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
12
|
+
// getProductCategoryAssignment -> null
|
|
13
|
+
spies.select.mockReturnValueOnce(undefined);
|
|
14
|
+
const input: RemoveProductFromCategoryInput = {
|
|
15
|
+
productId: "non-existent",
|
|
16
|
+
categoryId: "non-existent",
|
|
17
|
+
};
|
|
18
|
+
const result = await run(db, input);
|
|
19
|
+
expect(result.ok).toBe(false);
|
|
20
|
+
if (!result.ok) {
|
|
21
|
+
expect(result.error).toBeInstanceOf(AssignmentNotFoundError);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should remove assignment successfully", async () => {
|
|
26
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
27
|
+
// getProductCategoryAssignment -> found
|
|
28
|
+
spies.select.mockReturnValueOnce(baseCategoryAssignment);
|
|
29
|
+
// delete executes
|
|
30
|
+
spies.delete.mockReturnValueOnce(undefined);
|
|
31
|
+
|
|
32
|
+
const input: RemoveProductFromCategoryInput = {
|
|
33
|
+
productId: baseCategoryAssignment.productId,
|
|
34
|
+
categoryId: baseCategoryAssignment.categoryId,
|
|
35
|
+
};
|
|
36
|
+
const result = await run(db, input);
|
|
37
|
+
expect(result.ok).toBe(true);
|
|
38
|
+
if (result.ok) {
|
|
39
|
+
expect(result.value.id).toBe(baseCategoryAssignment.id);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ok, err } from "../../../shared";
|
|
2
|
+
import { Transaction } from "../generated/kysely-tailordb";
|
|
3
|
+
import { AssignmentNotFoundError } from "../lib/errors.generated";
|
|
4
|
+
|
|
5
|
+
export interface RemoveProductFromCategoryInput {
|
|
6
|
+
productId: string;
|
|
7
|
+
categoryId: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Function: removeProductFromCategory
|
|
12
|
+
*
|
|
13
|
+
* Removes a product-category assignment.
|
|
14
|
+
*/
|
|
15
|
+
export async function run(db: Transaction, input: RemoveProductFromCategoryInput) {
|
|
16
|
+
const { productId, categoryId } = input;
|
|
17
|
+
|
|
18
|
+
const assignment = await db
|
|
19
|
+
.selectFrom("ProductCategoryAssignment")
|
|
20
|
+
.selectAll()
|
|
21
|
+
.where("productId", "=", productId)
|
|
22
|
+
.where("categoryId", "=", categoryId)
|
|
23
|
+
.forUpdate()
|
|
24
|
+
.executeTakeFirst();
|
|
25
|
+
if (!assignment) {
|
|
26
|
+
return err(new AssignmentNotFoundError(`${productId}:${categoryId}`));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await db.deleteFrom("ProductCategoryAssignment").where("id", "=", assignment.id).execute();
|
|
30
|
+
|
|
31
|
+
return ok({ id: assignment.id });
|
|
32
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @generated — do not edit
|
|
2
|
+
import { defineCommand } from "../../../shared";
|
|
3
|
+
import { permissions } from "../lib/permissions.generated";
|
|
4
|
+
import { run } from "./setProductAttributeAssignment";
|
|
5
|
+
|
|
6
|
+
export const setProductAttributeAssignment = defineCommand(permissions.setProductAttributeAssignment, run);
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createMockDb } from "../../../testing/index";
|
|
3
|
+
import { Transaction } from "../generated/kysely-tailordb";
|
|
4
|
+
import {
|
|
5
|
+
ProductNotFoundError,
|
|
6
|
+
AttributeNotFoundError,
|
|
7
|
+
ProductArchivedError,
|
|
8
|
+
AxisStructureLockedError,
|
|
9
|
+
InvalidValueError,
|
|
10
|
+
} from "../lib/errors.generated";
|
|
11
|
+
import {
|
|
12
|
+
baseDraftProduct,
|
|
13
|
+
baseActiveProduct,
|
|
14
|
+
baseArchivedProduct,
|
|
15
|
+
baseColorAttribute,
|
|
16
|
+
baseColorRed,
|
|
17
|
+
baseColorBlue,
|
|
18
|
+
baseAttributeAssignment,
|
|
19
|
+
} from "../testing/fixtures";
|
|
20
|
+
import { run } from "./setProductAttributeAssignment";
|
|
21
|
+
|
|
22
|
+
describe("setProductAttributeAssignment", () => {
|
|
23
|
+
it("returns error when product not found", async () => {
|
|
24
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
25
|
+
spies.select.mockReturnValueOnce(undefined); // product not found
|
|
26
|
+
|
|
27
|
+
const result = await run(db, {
|
|
28
|
+
productId: "nonexistent",
|
|
29
|
+
attributeId: "attr-1",
|
|
30
|
+
valueId: "value-1",
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(result.ok).toBe(false);
|
|
34
|
+
if (!result.ok) {
|
|
35
|
+
expect(result.error).toBeInstanceOf(ProductNotFoundError);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("returns error when attribute not found", async () => {
|
|
40
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
41
|
+
spies.select
|
|
42
|
+
.mockReturnValueOnce(baseDraftProduct) // product found
|
|
43
|
+
.mockReturnValueOnce(undefined); // attribute not found
|
|
44
|
+
|
|
45
|
+
const result = await run(db, {
|
|
46
|
+
productId: baseDraftProduct.id,
|
|
47
|
+
attributeId: "nonexistent",
|
|
48
|
+
valueId: "value-1",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(result.ok).toBe(false);
|
|
52
|
+
if (!result.ok) {
|
|
53
|
+
expect(result.error).toBeInstanceOf(AttributeNotFoundError);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("returns error when value not found for attribute", async () => {
|
|
58
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
59
|
+
spies.select
|
|
60
|
+
.mockReturnValueOnce(baseDraftProduct) // product found
|
|
61
|
+
.mockReturnValueOnce(baseColorAttribute) // attribute found
|
|
62
|
+
.mockReturnValueOnce(undefined); // value not found
|
|
63
|
+
|
|
64
|
+
const result = await run(db, {
|
|
65
|
+
productId: baseDraftProduct.id,
|
|
66
|
+
attributeId: baseColorAttribute.id,
|
|
67
|
+
valueId: "invalid-value-id",
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(result.ok).toBe(false);
|
|
71
|
+
if (!result.ok) {
|
|
72
|
+
expect(result.error).toBeInstanceOf(InvalidValueError);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("returns error when product is ARCHIVED", async () => {
|
|
77
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
78
|
+
spies.select
|
|
79
|
+
.mockReturnValueOnce(baseArchivedProduct) // product found (ARCHIVED)
|
|
80
|
+
.mockReturnValueOnce(baseColorAttribute) // attribute found
|
|
81
|
+
.mockReturnValueOnce(baseColorRed) // value found
|
|
82
|
+
.mockReturnValueOnce([]); // no existing assignments
|
|
83
|
+
|
|
84
|
+
const result = await run(db, {
|
|
85
|
+
productId: baseArchivedProduct.id,
|
|
86
|
+
attributeId: baseColorAttribute.id,
|
|
87
|
+
valueId: baseColorRed.id,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(result.ok).toBe(false);
|
|
91
|
+
if (!result.ok) {
|
|
92
|
+
expect(result.error).toBeInstanceOf(ProductArchivedError);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("returns existing assignment when exact triple already exists (idempotent no-op)", async () => {
|
|
97
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
98
|
+
const existingAssignment = {
|
|
99
|
+
...baseAttributeAssignment,
|
|
100
|
+
productId: baseDraftProduct.id,
|
|
101
|
+
valueId: baseColorRed.id,
|
|
102
|
+
};
|
|
103
|
+
spies.select
|
|
104
|
+
.mockReturnValueOnce(baseDraftProduct) // product found
|
|
105
|
+
.mockReturnValueOnce(baseColorAttribute) // attribute found
|
|
106
|
+
.mockReturnValueOnce(baseColorRed) // value found
|
|
107
|
+
.mockReturnValueOnce([existingAssignment]); // existing assignments with matching valueId
|
|
108
|
+
|
|
109
|
+
const result = await run(db, {
|
|
110
|
+
productId: baseDraftProduct.id,
|
|
111
|
+
attributeId: baseColorAttribute.id,
|
|
112
|
+
valueId: baseColorRed.id,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(result.ok).toBe(true);
|
|
116
|
+
if (result.ok) {
|
|
117
|
+
expect(result.value.assignment).toEqual(existingAssignment);
|
|
118
|
+
}
|
|
119
|
+
// Should not insert or update
|
|
120
|
+
expect(spies.insert).not.toHaveBeenCalled();
|
|
121
|
+
expect(spies.update).not.toHaveBeenCalled();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("returns error when adding new attribute to ACTIVE product", async () => {
|
|
125
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
126
|
+
spies.select
|
|
127
|
+
.mockReturnValueOnce(baseActiveProduct) // product found (ACTIVE)
|
|
128
|
+
.mockReturnValueOnce(baseColorAttribute) // attribute found
|
|
129
|
+
.mockReturnValueOnce(baseColorRed) // value found
|
|
130
|
+
.mockReturnValueOnce([]); // no existing assignments for this attribute
|
|
131
|
+
|
|
132
|
+
const result = await run(db, {
|
|
133
|
+
productId: baseActiveProduct.id,
|
|
134
|
+
attributeId: baseColorAttribute.id,
|
|
135
|
+
valueId: baseColorRed.id,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(result.ok).toBe(false);
|
|
139
|
+
if (!result.ok) {
|
|
140
|
+
expect(result.error).toBeInstanceOf(AxisStructureLockedError);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("creates new assignment on DRAFT product", async () => {
|
|
145
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
146
|
+
const newAssignment = {
|
|
147
|
+
...baseAttributeAssignment,
|
|
148
|
+
id: "new-assignment-id",
|
|
149
|
+
productId: baseDraftProduct.id,
|
|
150
|
+
valueId: baseColorRed.id,
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
spies.select
|
|
154
|
+
.mockReturnValueOnce(baseDraftProduct) // product found
|
|
155
|
+
.mockReturnValueOnce(baseColorAttribute) // attribute found
|
|
156
|
+
.mockReturnValueOnce(baseColorRed) // value found
|
|
157
|
+
.mockReturnValueOnce([]); // no existing assignments
|
|
158
|
+
spies.insert.mockReturnValue(newAssignment);
|
|
159
|
+
|
|
160
|
+
const result = await run(db, {
|
|
161
|
+
productId: baseDraftProduct.id,
|
|
162
|
+
attributeId: baseColorAttribute.id,
|
|
163
|
+
valueId: baseColorRed.id,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
expect(result.ok).toBe(true);
|
|
167
|
+
if (result.ok) {
|
|
168
|
+
expect(result.value.assignment.productId).toBe(baseDraftProduct.id);
|
|
169
|
+
}
|
|
170
|
+
expect(spies.insert).toHaveBeenCalled();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("adds new value to existing attribute on ACTIVE product (additive-only)", async () => {
|
|
174
|
+
const { db, spies } = createMockDb<Transaction>();
|
|
175
|
+
const existingAssignment = {
|
|
176
|
+
...baseAttributeAssignment,
|
|
177
|
+
productId: baseActiveProduct.id,
|
|
178
|
+
valueId: baseColorRed.id,
|
|
179
|
+
};
|
|
180
|
+
const newAssignment = {
|
|
181
|
+
...baseAttributeAssignment,
|
|
182
|
+
id: "assignment-2",
|
|
183
|
+
productId: baseActiveProduct.id,
|
|
184
|
+
valueId: baseColorBlue.id,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
spies.select
|
|
188
|
+
.mockReturnValueOnce(baseActiveProduct) // product found (ACTIVE)
|
|
189
|
+
.mockReturnValueOnce(baseColorAttribute) // attribute found
|
|
190
|
+
.mockReturnValueOnce(baseColorBlue) // value found (Blue)
|
|
191
|
+
.mockReturnValueOnce([existingAssignment]); // existing: Red already assigned
|
|
192
|
+
spies.insert.mockReturnValue(newAssignment);
|
|
193
|
+
|
|
194
|
+
const result = await run(db, {
|
|
195
|
+
productId: baseActiveProduct.id,
|
|
196
|
+
attributeId: baseColorAttribute.id,
|
|
197
|
+
valueId: baseColorBlue.id,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
expect(result.ok).toBe(true);
|
|
201
|
+
if (result.ok) {
|
|
202
|
+
expect(result.value.assignment.valueId).toBe(baseColorBlue.id);
|
|
203
|
+
}
|
|
204
|
+
expect(spies.insert).toHaveBeenCalled();
|
|
205
|
+
});
|
|
206
|
+
});
|