@tailor-platform/erp-kit 0.1.1 → 0.2.0
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 +12 -0
- package/README.md +158 -62
- package/dist/cli.js +1010 -270
- package/package.json +11 -8
- package/schemas/module/command.yml +1 -0
- package/schemas/module/model.yml +14 -0
- package/schemas/module/query.yml +53 -0
- package/skills/{app-compose-1-requirement-analysis → erp-kit-app-1-requirements}/SKILL.md +2 -2
- package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/SKILL.md +3 -3
- package/skills/{app-compose-3-doc-review → erp-kit-app-3-doc-review}/SKILL.md +2 -2
- package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/SKILL.md +3 -3
- package/skills/{app-compose-5-design-mock-review → erp-kit-app-5-design-review}/SKILL.md +4 -4
- package/skills/{app-compose-6-implementation-spec → erp-kit-app-6-impl-spec}/SKILL.md +3 -3
- package/skills/{mock-scenario → erp-kit-mock-scenario}/SKILL.md +1 -1
- package/skills/{1-module-docs → erp-kit-module-1-docs}/SKILL.md +2 -2
- package/skills/{2-module-feature-breakdown → erp-kit-module-2-feature-breakdown}/SKILL.md +13 -9
- package/skills/erp-kit-module-2-feature-breakdown/references/naming.md +59 -0
- package/skills/{3-module-doc-review → erp-kit-module-3-doc-review}/SKILL.md +83 -25
- package/skills/erp-kit-module-4-tdd/SKILL.md +94 -0
- package/skills/erp-kit-module-4-tdd/references/cross-module-dependency.md +133 -0
- package/skills/{4-module-tdd-implementation → erp-kit-module-4-tdd}/references/db-relations.md +5 -1
- package/skills/{4-module-tdd-implementation → erp-kit-module-4-tdd}/references/exports.md +1 -1
- package/skills/erp-kit-module-4-tdd/references/generated-code.md +32 -0
- package/skills/{5-module-implementation-review → erp-kit-module-5-impl-review}/SKILL.md +46 -44
- package/skills/erp-kit-module-5-impl-review/references/commands.md +62 -0
- package/skills/erp-kit-module-5-impl-review/references/errors.md +10 -0
- package/skills/{5-module-implementation-review → erp-kit-module-5-impl-review}/references/testing.md +1 -1
- package/skills/erp-kit-module-shared/SKILL.md +16 -0
- package/skills/erp-kit-module-shared/references/commands.md +203 -0
- package/skills/erp-kit-module-shared/references/errors.md +35 -0
- package/skills/erp-kit-module-shared/references/queries.md +168 -0
- package/skills/erp-kit-module-shared/references/structure.md +36 -0
- package/skills/{3-module-doc-review → erp-kit-module-shared}/references/testing.md +4 -3
- package/skills/erp-kit-update/SKILL.md +64 -0
- package/src/cli.doc.test.ts +65 -0
- package/src/cli.ts +3 -117
- package/src/commands/app/index.ts +74 -0
- package/src/commands/check.test.ts +3 -2
- package/src/commands/check.ts +3 -2
- package/src/commands/index.ts +73 -0
- package/src/commands/init.test.ts +22 -5
- package/src/commands/init.ts +25 -16
- package/src/commands/license.ts +193 -0
- package/src/commands/mock/index.ts +2 -2
- package/src/commands/mock/start.ts +1 -1
- package/src/commands/mock/validate.test.ts +1 -1
- package/src/commands/module/generate.ts +35 -0
- package/src/commands/module/index.ts +87 -0
- package/src/commands/module/list.test.ts +57 -0
- package/src/commands/module/list.ts +64 -0
- package/src/commands/scaffold-templates.ts +65 -0
- package/src/commands/scaffold.test.ts +97 -2
- package/src/commands/scaffold.ts +24 -3
- package/src/commands/sync-check.test.ts +88 -1
- package/src/commands/sync-check.ts +41 -2
- package/src/generator/generate-code.test.ts +200 -0
- package/src/generator/generate-code.ts +260 -0
- package/src/generator/parse-command-doc.test.ts +159 -0
- package/src/generator/parse-command-doc.ts +116 -0
- package/src/integration.test.ts +6 -8
- package/src/module.ts +10 -9
- package/src/modules/item-management/README.md +38 -0
- package/src/modules/item-management/command/activateItem.generated.ts +6 -0
- package/src/modules/item-management/command/activateItem.test.ts +76 -0
- package/src/modules/item-management/command/activateItem.ts +42 -0
- package/src/modules/item-management/command/assignItemToTaxonomy.generated.ts +6 -0
- package/src/modules/item-management/command/assignItemToTaxonomy.test.ts +88 -0
- package/src/modules/item-management/command/assignItemToTaxonomy.ts +63 -0
- package/src/modules/item-management/command/createItem.generated.ts +6 -0
- package/src/modules/item-management/command/createItem.test.ts +152 -0
- package/src/modules/item-management/command/createItem.ts +72 -0
- package/src/modules/item-management/command/createTaxonomyNode.generated.ts +6 -0
- package/src/modules/item-management/command/createTaxonomyNode.test.ts +126 -0
- package/src/modules/item-management/command/createTaxonomyNode.ts +70 -0
- package/src/modules/item-management/command/deactivateItem.generated.ts +6 -0
- package/src/modules/item-management/command/deactivateItem.test.ts +76 -0
- package/src/modules/item-management/command/deactivateItem.ts +42 -0
- package/src/modules/item-management/command/deleteItem.generated.ts +6 -0
- package/src/modules/item-management/command/deleteItem.test.ts +61 -0
- package/src/modules/item-management/command/deleteItem.ts +38 -0
- package/src/modules/item-management/command/deleteTaxonomyNode.generated.ts +6 -0
- package/src/modules/item-management/command/deleteTaxonomyNode.test.ts +73 -0
- package/src/modules/item-management/command/deleteTaxonomyNode.ts +50 -0
- package/src/modules/item-management/command/moveTaxonomyNode.generated.ts +6 -0
- package/src/modules/item-management/command/moveTaxonomyNode.test.ts +136 -0
- package/src/modules/item-management/command/moveTaxonomyNode.ts +85 -0
- package/src/modules/item-management/command/reactivateItem.generated.ts +6 -0
- package/src/modules/item-management/command/reactivateItem.test.ts +76 -0
- package/src/modules/item-management/command/reactivateItem.ts +42 -0
- package/src/modules/item-management/command/removeItemFromTaxonomy.generated.ts +6 -0
- package/src/modules/item-management/command/removeItemFromTaxonomy.test.ts +43 -0
- package/src/modules/item-management/command/removeItemFromTaxonomy.ts +30 -0
- package/src/modules/item-management/command/updateItem.generated.ts +6 -0
- package/src/modules/item-management/command/updateItem.test.ts +178 -0
- package/src/modules/item-management/command/updateItem.ts +103 -0
- package/src/modules/item-management/command/updateTaxonomyNode.generated.ts +6 -0
- package/src/modules/item-management/command/updateTaxonomyNode.test.ts +88 -0
- package/src/modules/item-management/command/updateTaxonomyNode.ts +62 -0
- package/src/modules/item-management/db/item.ts +47 -0
- package/src/modules/item-management/db/itemTaxonomyAssignment.ts +49 -0
- package/src/modules/item-management/db/taxonomyNode.ts +34 -0
- package/src/modules/item-management/docs/commands/ActivateItem.md +32 -0
- package/src/modules/item-management/docs/commands/AssignItemToTaxonomy.md +38 -0
- package/src/modules/item-management/docs/commands/CreateItem.md +44 -0
- package/src/modules/item-management/docs/commands/CreateTaxonomyNode.md +44 -0
- package/src/modules/item-management/docs/commands/DeactivateItem.md +34 -0
- package/src/modules/item-management/docs/commands/DeleteItem.md +35 -0
- package/src/modules/item-management/docs/commands/DeleteTaxonomyNode.md +39 -0
- package/src/modules/item-management/docs/commands/MoveTaxonomyNode.md +45 -0
- package/src/modules/item-management/docs/commands/ReactivateItem.md +34 -0
- package/src/modules/item-management/docs/commands/RemoveItemFromTaxonomy.md +30 -0
- package/src/modules/item-management/docs/commands/UpdateItem.md +55 -0
- package/src/modules/item-management/docs/commands/UpdateTaxonomyNode.md +36 -0
- package/src/modules/item-management/docs/features/item-lifecycle.md +60 -0
- package/src/modules/item-management/docs/features/item-taxonomy.md +65 -0
- package/src/modules/item-management/docs/models/ItemTaxonomyAssignment.md +36 -0
- package/src/modules/item-management/docs/models/TaxonomyNode.md +47 -0
- package/src/modules/item-management/docs/models/item.md +59 -0
- package/src/modules/item-management/docs/queries/CalculateNodeDepth.md +36 -0
- package/src/modules/item-management/docs/queries/CalculateSubtreeDepth.md +40 -0
- package/src/modules/item-management/docs/queries/DetectCircularReference.md +41 -0
- package/src/modules/item-management/docs/queries/GetItem.md +38 -0
- package/src/modules/item-management/docs/queries/GetItemTaxonomyAssignment.md +29 -0
- package/src/modules/item-management/docs/queries/GetTaxonomyNode.md +35 -0
- package/src/modules/item-management/docs/queries/GetTaxonomyNodeAssignments.md +29 -0
- package/src/modules/item-management/docs/queries/GetTaxonomyNodeChildren.md +29 -0
- package/src/modules/item-management/generated/enums.ts +9 -0
- package/src/modules/item-management/generated/kysely-tailordb.ts +62 -0
- package/src/modules/item-management/index.ts +53 -0
- package/src/modules/item-management/lib/_db_deps.ts +13 -0
- package/src/modules/item-management/lib/errors.generated.ts +117 -0
- package/src/modules/item-management/lib/permissions.generated.ts +17 -0
- package/src/modules/item-management/lib/types.ts +19 -0
- package/src/modules/item-management/module.ts +97 -0
- package/src/modules/item-management/query/calculateNodeDepth.generated.ts +5 -0
- package/src/modules/item-management/query/calculateNodeDepth.test.ts +56 -0
- package/src/modules/item-management/query/calculateNodeDepth.ts +28 -0
- package/src/modules/item-management/query/calculateSubtreeDepth.generated.ts +5 -0
- package/src/modules/item-management/query/calculateSubtreeDepth.test.ts +75 -0
- package/src/modules/item-management/query/calculateSubtreeDepth.ts +29 -0
- package/src/modules/item-management/query/detectCircularReference.generated.ts +5 -0
- package/src/modules/item-management/query/detectCircularReference.test.ts +61 -0
- package/src/modules/item-management/query/detectCircularReference.ts +32 -0
- package/src/modules/item-management/query/getItem.generated.ts +5 -0
- package/src/modules/item-management/query/getItem.test.ts +67 -0
- package/src/modules/item-management/query/getItem.ts +20 -0
- package/src/modules/item-management/query/getItemTaxonomyAssignment.generated.ts +5 -0
- package/src/modules/item-management/query/getItemTaxonomyAssignment.test.ts +25 -0
- package/src/modules/item-management/query/getItemTaxonomyAssignment.ts +18 -0
- package/src/modules/item-management/query/getTaxonomyNode.generated.ts +5 -0
- package/src/modules/item-management/query/getTaxonomyNode.test.ts +47 -0
- package/src/modules/item-management/query/getTaxonomyNode.ts +18 -0
- package/src/modules/item-management/query/getTaxonomyNodeAssignments.generated.ts +5 -0
- package/src/modules/item-management/query/getTaxonomyNodeAssignments.test.ts +25 -0
- package/src/modules/item-management/query/getTaxonomyNodeAssignments.ts +16 -0
- package/src/modules/item-management/query/getTaxonomyNodeChildren.generated.ts +5 -0
- package/src/modules/item-management/query/getTaxonomyNodeChildren.test.ts +34 -0
- package/src/modules/item-management/query/getTaxonomyNodeChildren.ts +16 -0
- package/src/modules/item-management/tailor.config.ts +11 -0
- package/src/modules/item-management/testing/fixtures.ts +81 -0
- package/src/modules/primitives/command/activateCategory.generated.ts +6 -0
- package/src/modules/primitives/command/activateCategory.test.ts +11 -29
- package/src/modules/primitives/command/activateCategory.ts +27 -34
- package/src/modules/primitives/command/activateCurrency.generated.ts +6 -0
- package/src/modules/primitives/command/activateCurrency.test.ts +11 -29
- package/src/modules/primitives/command/activateCurrency.ts +27 -34
- package/src/modules/primitives/command/activateUnit.generated.ts +6 -0
- package/src/modules/primitives/command/activateUnit.test.ts +11 -15
- package/src/modules/primitives/command/activateUnit.ts +27 -34
- package/src/modules/primitives/command/createCategory.generated.ts +6 -0
- package/src/modules/primitives/command/createCategory.test.ts +27 -39
- package/src/modules/primitives/command/createCategory.ts +53 -62
- package/src/modules/primitives/command/createCurrency.generated.ts +6 -0
- package/src/modules/primitives/command/createCurrency.test.ts +78 -71
- package/src/modules/primitives/command/createCurrency.ts +43 -48
- package/src/modules/primitives/command/createExchangeRate.generated.ts +6 -0
- package/src/modules/primitives/command/createExchangeRate.test.ts +101 -100
- package/src/modules/primitives/command/createExchangeRate.ts +50 -59
- package/src/modules/primitives/command/createUnit.generated.ts +6 -0
- package/src/modules/primitives/command/createUnit.test.ts +92 -95
- package/src/modules/primitives/command/createUnit.ts +54 -57
- package/src/modules/primitives/command/deactivateCategory.generated.ts +6 -0
- package/src/modules/primitives/command/deactivateCategory.test.ts +27 -28
- package/src/modules/primitives/command/deactivateCategory.ts +43 -50
- package/src/modules/primitives/command/deactivateCurrency.generated.ts +6 -0
- package/src/modules/primitives/command/deactivateCurrency.test.ts +23 -38
- package/src/modules/primitives/command/deactivateCurrency.ts +31 -38
- package/src/modules/primitives/command/deactivateUnit.generated.ts +6 -0
- package/src/modules/primitives/command/deactivateUnit.test.ts +27 -23
- package/src/modules/primitives/command/deactivateUnit.ts +39 -49
- package/src/modules/primitives/command/setBaseCurrency.generated.ts +6 -0
- package/src/modules/primitives/command/setBaseCurrency.test.ts +40 -33
- package/src/modules/primitives/command/setBaseCurrency.ts +43 -50
- package/src/modules/primitives/command/setReferenceUnit.generated.ts +6 -0
- package/src/modules/primitives/command/setReferenceUnit.test.ts +39 -35
- package/src/modules/primitives/command/setReferenceUnit.ts +46 -59
- package/src/modules/primitives/db/unit.ts +13 -3
- package/src/modules/primitives/docs/commands/ActivateCategory.md +1 -2
- package/src/modules/primitives/docs/commands/ActivateCurrency.md +1 -2
- package/src/modules/primitives/docs/commands/ActivateUnit.md +1 -2
- package/src/modules/primitives/docs/commands/CreateCategory.md +1 -4
- package/src/modules/primitives/docs/commands/CreateCurrency.md +3 -4
- package/src/modules/primitives/docs/commands/CreateExchangeRate.md +4 -5
- package/src/modules/primitives/docs/commands/CreateUnit.md +5 -5
- package/src/modules/primitives/docs/commands/DeactivateCategory.md +2 -3
- package/src/modules/primitives/docs/commands/DeactivateCurrency.md +2 -3
- package/src/modules/primitives/docs/commands/DeactivateUnit.md +2 -3
- package/src/modules/primitives/docs/commands/SetBaseCurrency.md +2 -3
- package/src/modules/primitives/docs/commands/SetReferenceUnit.md +2 -3
- package/src/modules/primitives/docs/models/Currency.md +4 -0
- package/src/modules/primitives/docs/models/ExchangeRate.md +4 -1
- package/src/modules/primitives/docs/models/Unit.md +4 -1
- package/src/modules/primitives/docs/models/UoMCategory.md +2 -0
- package/src/modules/primitives/docs/{commands → queries}/ConvertAmount.md +3 -5
- package/src/modules/primitives/docs/{commands → queries}/ConvertQuantity.md +3 -5
- package/src/modules/primitives/docs/queries/GetBaseCurrency.md +32 -0
- package/src/modules/primitives/docs/queries/GetCurrency.md +36 -0
- package/src/modules/primitives/docs/queries/GetUnit.md +36 -0
- package/src/modules/primitives/docs/queries/GetUoMCategory.md +36 -0
- package/src/modules/primitives/docs/queries/ListUnitsByCategory.md +26 -0
- package/src/modules/primitives/generated/kysely-tailordb.ts +24 -45
- package/src/modules/primitives/index.ts +17 -6
- package/src/modules/primitives/lib/errors.generated.ts +112 -0
- package/src/modules/primitives/{permissions.ts → lib/permissions.generated.ts} +9 -10
- package/src/modules/primitives/module.ts +39 -27
- package/src/modules/primitives/query/convertAmount.generated.ts +5 -0
- package/src/modules/primitives/{command → query}/convertAmount.test.ts +4 -21
- package/src/modules/primitives/query/convertAmount.ts +121 -0
- package/src/modules/primitives/query/convertQuantity.generated.ts +5 -0
- package/src/modules/primitives/{command → query}/convertQuantity.test.ts +8 -15
- package/src/modules/primitives/query/convertQuantity.ts +63 -0
- package/src/modules/primitives/query/getBaseCurrency.generated.ts +5 -0
- package/src/modules/primitives/query/getBaseCurrency.test.ts +28 -0
- package/src/modules/primitives/query/getBaseCurrency.ts +16 -0
- package/src/modules/primitives/query/getCurrency.generated.ts +5 -0
- package/src/modules/primitives/query/getCurrency.test.ts +47 -0
- package/src/modules/primitives/query/getCurrency.ts +18 -0
- package/src/modules/primitives/query/getUnit.generated.ts +5 -0
- package/src/modules/primitives/query/getUnit.test.ts +47 -0
- package/src/modules/primitives/query/getUnit.ts +18 -0
- package/src/modules/primitives/query/getUoMCategory.generated.ts +5 -0
- package/src/modules/primitives/query/getUoMCategory.test.ts +47 -0
- package/src/modules/primitives/query/getUoMCategory.ts +18 -0
- package/src/modules/primitives/query/listUnitsByCategory.generated.ts +5 -0
- package/src/modules/primitives/query/listUnitsByCategory.ts +16 -0
- package/src/modules/primitives/tailor.config.ts +3 -3
- package/src/modules/shared/defineCommand.test.ts +23 -10
- package/src/modules/shared/defineCommand.ts +23 -10
- package/src/modules/shared/defineQuery.test.ts +28 -0
- package/src/modules/shared/defineQuery.ts +16 -0
- package/src/modules/shared/internal.ts +3 -1
- package/src/modules/shared/requirePermission.test.ts +22 -21
- package/src/modules/shared/requirePermission.ts +8 -2
- package/src/modules/shared/result.ts +12 -0
- package/src/modules/shared/types.ts +8 -0
- package/src/modules/testing/index.ts +36 -11
- package/src/modules/user-management/command/activateUser.generated.ts +6 -0
- package/src/modules/user-management/command/activateUser.test.ts +27 -27
- package/src/modules/user-management/command/activateUser.ts +40 -48
- package/src/modules/user-management/command/assignPermissionToRole.generated.ts +6 -0
- package/src/modules/user-management/command/assignPermissionToRole.test.ts +42 -43
- package/src/modules/user-management/command/assignPermissionToRole.ts +59 -62
- package/src/modules/user-management/command/assignRoleToUser.generated.ts +6 -0
- package/src/modules/user-management/command/assignRoleToUser.test.ts +70 -63
- package/src/modules/user-management/command/assignRoleToUser.ts +63 -66
- package/src/modules/user-management/command/createPermission.generated.ts +6 -0
- package/src/modules/user-management/command/createPermission.test.ts +45 -38
- package/src/modules/user-management/command/createPermission.ts +42 -46
- package/src/modules/user-management/command/createRole.generated.ts +6 -0
- package/src/modules/user-management/command/createRole.test.ts +30 -29
- package/src/modules/user-management/command/createRole.ts +33 -33
- package/src/modules/user-management/command/createUser.generated.ts +6 -0
- package/src/modules/user-management/command/createUser.test.ts +64 -42
- package/src/modules/user-management/command/createUser.ts +54 -56
- package/src/modules/user-management/command/deactivateUser.generated.ts +6 -0
- package/src/modules/user-management/command/deactivateUser.test.ts +27 -27
- package/src/modules/user-management/command/deactivateUser.ts +40 -48
- package/src/modules/user-management/command/logAuditEvent.generated.ts +6 -0
- package/src/modules/user-management/command/logAuditEvent.test.ts +50 -42
- package/src/modules/user-management/command/logAuditEvent.ts +25 -28
- package/src/modules/user-management/command/reactivateUser.generated.ts +6 -0
- package/src/modules/user-management/command/reactivateUser.test.ts +31 -27
- package/src/modules/user-management/command/reactivateUser.ts +40 -48
- package/src/modules/user-management/command/revokePermissionFromRole.generated.ts +6 -0
- package/src/modules/user-management/command/revokePermissionFromRole.test.ts +52 -51
- package/src/modules/user-management/command/revokePermissionFromRole.ts +60 -57
- package/src/modules/user-management/command/revokeRoleFromUser.generated.ts +6 -0
- package/src/modules/user-management/command/revokeRoleFromUser.test.ts +53 -48
- package/src/modules/user-management/command/revokeRoleFromUser.ts +58 -57
- package/src/modules/user-management/docs/commands/CreatePermission.md +2 -2
- package/src/modules/user-management/docs/commands/CreateRole.md +1 -1
- package/src/modules/user-management/docs/models/AuditEvent.md +2 -0
- package/src/modules/user-management/docs/models/Permission.md +2 -0
- package/src/modules/user-management/docs/models/Role.md +2 -0
- package/src/modules/user-management/docs/models/RolePermission.md +2 -0
- package/src/modules/user-management/docs/models/User.md +2 -0
- package/src/modules/user-management/docs/models/UserRole.md +2 -0
- package/src/modules/user-management/generated/enums.ts +11 -11
- package/src/modules/user-management/generated/kysely-tailordb.ts +27 -56
- package/src/modules/user-management/index.ts +2 -2
- package/src/modules/user-management/lib/errors.generated.ts +67 -0
- package/src/modules/user-management/{permissions.ts → lib/permissions.generated.ts} +8 -7
- package/src/modules/user-management/module.ts +22 -22
- package/src/modules/user-management/tailor.config.ts +3 -3
- package/src/schemas.ts +2 -1
- package/skills/1-module-docs/references/structure.md +0 -22
- package/skills/2-module-feature-breakdown/references/commands.md +0 -48
- package/skills/2-module-feature-breakdown/references/structure.md +0 -22
- package/skills/3-module-doc-review/references/commands.md +0 -54
- package/skills/3-module-doc-review/references/models.md +0 -29
- package/skills/4-module-tdd-implementation/SKILL.md +0 -74
- package/skills/4-module-tdd-implementation/references/commands.md +0 -45
- package/skills/4-module-tdd-implementation/references/errors.md +0 -7
- package/skills/4-module-tdd-implementation/references/models.md +0 -30
- package/skills/4-module-tdd-implementation/references/structure.md +0 -22
- package/skills/4-module-tdd-implementation/references/testing.md +0 -37
- package/skills/5-module-implementation-review/references/commands.md +0 -45
- package/skills/5-module-implementation-review/references/errors.md +0 -7
- package/skills/5-module-implementation-review/references/exports.md +0 -8
- package/skills/5-module-implementation-review/references/models.md +0 -30
- package/src/modules/primitives/command/convertAmount.ts +0 -126
- package/src/modules/primitives/command/convertQuantity.ts +0 -73
- package/src/modules/primitives/lib/errors.ts +0 -138
- package/src/modules/user-management/lib/errors.ts +0 -81
- /package/skills/{app-compose-1-requirement-analysis → erp-kit-app-1-requirements}/references/structure.md +0 -0
- /package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/references/screen-detailview.md +0 -0
- /package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/references/screen-form.md +0 -0
- /package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/references/screen-listview.md +0 -0
- /package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/references/structure.md +0 -0
- /package/skills/{app-compose-3-doc-review → erp-kit-app-3-doc-review}/references/structure.md +0 -0
- /package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/references/component.md +0 -0
- /package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/references/screen-detailview.md +0 -0
- /package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/references/screen-form.md +0 -0
- /package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/references/screen-listview.md +0 -0
- /package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/references/structure.md +0 -0
- /package/skills/{app-compose-5-design-mock-review → erp-kit-app-5-design-review}/references/component.md +0 -0
- /package/skills/{app-compose-5-design-mock-review → erp-kit-app-5-design-review}/references/screen-detailview.md +0 -0
- /package/skills/{app-compose-5-design-mock-review → erp-kit-app-5-design-review}/references/screen-form.md +0 -0
- /package/skills/{app-compose-5-design-mock-review → erp-kit-app-5-design-review}/references/screen-listview.md +0 -0
- /package/skills/{app-compose-6-implementation-spec → erp-kit-app-6-impl-spec}/references/auth.md +0 -0
- /package/skills/{app-compose-6-implementation-spec → erp-kit-app-6-impl-spec}/references/structure.md +0 -0
- /package/skills/{2-module-feature-breakdown → erp-kit-module-4-tdd}/references/models.md +0 -0
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { createMockDb } from "../../testing/index";
|
|
3
|
-
import {
|
|
3
|
+
import { type CommandContext } from "../../shared/internal";
|
|
4
4
|
import { DB } from "../generated/kysely-tailordb";
|
|
5
5
|
import {
|
|
6
6
|
CategoryNotActiveError,
|
|
7
7
|
DuplicateUnitSymbolError,
|
|
8
8
|
InvalidConversionFactorError,
|
|
9
9
|
InvalidRoundingPrecisionError,
|
|
10
|
-
|
|
11
|
-
} from "../lib/errors";
|
|
10
|
+
UomCategoryNotFoundError,
|
|
11
|
+
} from "../lib/errors.generated";
|
|
12
12
|
import { baseUoMCategory, baseUnitKg } from "../testing/fixtures";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
const createUnit = makeCreateUnit();
|
|
13
|
+
import { run } from "./createUnit";
|
|
16
14
|
|
|
17
15
|
describe("createUnit", () => {
|
|
18
16
|
const ctx: CommandContext = { actorId: "test-actor", permissions: ["primitives:createUnit"] };
|
|
@@ -27,38 +25,44 @@ describe("createUnit", () => {
|
|
|
27
25
|
const { db, spies } = createMockDb<DB>();
|
|
28
26
|
spies.select.mockReturnValue(undefined);
|
|
29
27
|
|
|
30
|
-
await
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
).
|
|
28
|
+
const result = await run(
|
|
29
|
+
db,
|
|
30
|
+
{
|
|
31
|
+
categoryId: "nonexistent-category",
|
|
32
|
+
name: "Ounce",
|
|
33
|
+
symbol: "oz",
|
|
34
|
+
conversionFactor: 0.0283495,
|
|
35
|
+
roundingPrecision: 2,
|
|
36
|
+
},
|
|
37
|
+
ctx,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
expect(result.ok).toBe(false);
|
|
41
|
+
if (!result.ok) {
|
|
42
|
+
expect(result.error).toBeInstanceOf(UomCategoryNotFoundError);
|
|
43
|
+
}
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
it("throws when category is inactive", async () => {
|
|
46
47
|
const { db, spies } = createMockDb<DB>();
|
|
47
48
|
spies.select.mockReturnValue(inactiveCategory);
|
|
48
49
|
|
|
49
|
-
await
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
).
|
|
50
|
+
const result = await run(
|
|
51
|
+
db,
|
|
52
|
+
{
|
|
53
|
+
categoryId: inactiveCategory.id,
|
|
54
|
+
name: "Ounce",
|
|
55
|
+
symbol: "oz",
|
|
56
|
+
conversionFactor: 0.0283495,
|
|
57
|
+
roundingPrecision: 2,
|
|
58
|
+
},
|
|
59
|
+
ctx,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(result.ok).toBe(false);
|
|
63
|
+
if (!result.ok) {
|
|
64
|
+
expect(result.error).toBeInstanceOf(CategoryNotActiveError);
|
|
65
|
+
}
|
|
62
66
|
});
|
|
63
67
|
|
|
64
68
|
it("throws when symbol already exists in category", async () => {
|
|
@@ -67,19 +71,22 @@ describe("createUnit", () => {
|
|
|
67
71
|
.mockReturnValueOnce(baseUoMCategory) // Category lookup
|
|
68
72
|
.mockReturnValueOnce(baseUnitKg); // Existing unit with same symbol
|
|
69
73
|
|
|
70
|
-
await
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
).
|
|
74
|
+
const result = await run(
|
|
75
|
+
db,
|
|
76
|
+
{
|
|
77
|
+
categoryId: baseUoMCategory.id,
|
|
78
|
+
name: "Kilogram Duplicate",
|
|
79
|
+
symbol: "kg",
|
|
80
|
+
conversionFactor: 1.0,
|
|
81
|
+
roundingPrecision: 2,
|
|
82
|
+
},
|
|
83
|
+
ctx,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(result.ok).toBe(false);
|
|
87
|
+
if (!result.ok) {
|
|
88
|
+
expect(result.error).toBeInstanceOf(DuplicateUnitSymbolError);
|
|
89
|
+
}
|
|
83
90
|
});
|
|
84
91
|
|
|
85
92
|
it("throws when conversion factor is not positive", async () => {
|
|
@@ -88,19 +95,22 @@ describe("createUnit", () => {
|
|
|
88
95
|
.mockReturnValueOnce(baseUoMCategory) // Category lookup
|
|
89
96
|
.mockReturnValueOnce(undefined); // No duplicate symbol
|
|
90
97
|
|
|
91
|
-
await
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
).
|
|
98
|
+
const result = await run(
|
|
99
|
+
db,
|
|
100
|
+
{
|
|
101
|
+
categoryId: baseUoMCategory.id,
|
|
102
|
+
name: "Invalid Unit",
|
|
103
|
+
symbol: "inv",
|
|
104
|
+
conversionFactor: 0,
|
|
105
|
+
roundingPrecision: 2,
|
|
106
|
+
},
|
|
107
|
+
ctx,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
expect(result.ok).toBe(false);
|
|
111
|
+
if (!result.ok) {
|
|
112
|
+
expect(result.error).toBeInstanceOf(InvalidConversionFactorError);
|
|
113
|
+
}
|
|
104
114
|
});
|
|
105
115
|
|
|
106
116
|
it("throws when rounding precision is negative", async () => {
|
|
@@ -109,19 +119,22 @@ describe("createUnit", () => {
|
|
|
109
119
|
.mockReturnValueOnce(baseUoMCategory) // Category lookup
|
|
110
120
|
.mockReturnValueOnce(undefined); // No duplicate symbol
|
|
111
121
|
|
|
112
|
-
await
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
).
|
|
122
|
+
const result = await run(
|
|
123
|
+
db,
|
|
124
|
+
{
|
|
125
|
+
categoryId: baseUoMCategory.id,
|
|
126
|
+
name: "Invalid Unit",
|
|
127
|
+
symbol: "inv",
|
|
128
|
+
conversionFactor: 1.0,
|
|
129
|
+
roundingPrecision: -1,
|
|
130
|
+
},
|
|
131
|
+
ctx,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect(result.ok).toBe(false);
|
|
135
|
+
if (!result.ok) {
|
|
136
|
+
expect(result.error).toBeInstanceOf(InvalidRoundingPrecisionError);
|
|
137
|
+
}
|
|
125
138
|
});
|
|
126
139
|
|
|
127
140
|
// Success cases
|
|
@@ -144,7 +157,7 @@ describe("createUnit", () => {
|
|
|
144
157
|
.mockReturnValueOnce(undefined); // No duplicate symbol
|
|
145
158
|
spies.insert.mockReturnValue(createdUnit);
|
|
146
159
|
|
|
147
|
-
const result = await
|
|
160
|
+
const result = await run(
|
|
148
161
|
db,
|
|
149
162
|
{
|
|
150
163
|
categoryId: baseUoMCategory.id,
|
|
@@ -156,32 +169,16 @@ describe("createUnit", () => {
|
|
|
156
169
|
ctx,
|
|
157
170
|
);
|
|
158
171
|
|
|
159
|
-
expect(result.
|
|
160
|
-
|
|
161
|
-
|
|
172
|
+
expect(result.ok).toBe(true);
|
|
173
|
+
if (result.ok) {
|
|
174
|
+
expect(result.value.unit.name).toBe("Ounce");
|
|
175
|
+
expect(result.value.unit.symbol).toBe("oz");
|
|
176
|
+
expect(result.value.unit.isActive).toBe(true);
|
|
177
|
+
}
|
|
162
178
|
expect(spies.insert).toHaveBeenCalled();
|
|
163
179
|
});
|
|
164
180
|
|
|
165
|
-
it("throws when permission is missing", async () => {
|
|
166
|
-
const { db } = createMockDb<DB>();
|
|
167
|
-
const denied: CommandContext = { actorId: "test-actor", permissions: [] };
|
|
168
|
-
await expect(
|
|
169
|
-
createUnit(
|
|
170
|
-
db,
|
|
171
|
-
{
|
|
172
|
-
categoryId: "cat-1",
|
|
173
|
-
name: "Test",
|
|
174
|
-
symbol: "t",
|
|
175
|
-
conversionFactor: 1,
|
|
176
|
-
roundingPrecision: 2,
|
|
177
|
-
},
|
|
178
|
-
denied,
|
|
179
|
-
),
|
|
180
|
-
).rejects.toBeInstanceOf(InsufficientPermissionError);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
181
|
it("passes custom fields through to insert", async () => {
|
|
184
|
-
const createUnitWithFields = makeCreateUnit<{ displayOrder: number }>();
|
|
185
182
|
const { db, spies } = createMockDb<DB>();
|
|
186
183
|
const createdUnit = {
|
|
187
184
|
...baseUnitKg,
|
|
@@ -196,7 +193,7 @@ describe("createUnit", () => {
|
|
|
196
193
|
.mockReturnValueOnce(undefined); // No duplicate symbol
|
|
197
194
|
spies.insert.mockReturnValue(createdUnit);
|
|
198
195
|
|
|
199
|
-
await
|
|
196
|
+
await run(
|
|
200
197
|
db,
|
|
201
198
|
{
|
|
202
199
|
categoryId: baseUoMCategory.id,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ok, err, type CommandContext } from "../../shared/internal";
|
|
2
2
|
import { DB } from "../generated/kysely-tailordb";
|
|
3
3
|
import {
|
|
4
4
|
CategoryNotActiveError,
|
|
5
5
|
DuplicateUnitSymbolError,
|
|
6
6
|
InvalidConversionFactorError,
|
|
7
7
|
InvalidRoundingPrecisionError,
|
|
8
|
-
|
|
9
|
-
} from "../lib/errors";
|
|
10
|
-
import {
|
|
8
|
+
UomCategoryNotFoundError,
|
|
9
|
+
} from "../lib/errors.generated";
|
|
10
|
+
import { getUoMCategory } from "../query/getUoMCategory.generated";
|
|
11
11
|
|
|
12
12
|
interface CreateUnitInput {
|
|
13
13
|
categoryId: string;
|
|
@@ -23,66 +23,63 @@ interface CreateUnitInput {
|
|
|
23
23
|
* Adds a new unit of measure to an existing category with its symbol,
|
|
24
24
|
* display name, and conversion factor relative to the reference unit.
|
|
25
25
|
*/
|
|
26
|
-
export function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
export async function run<CF extends Record<string, unknown>>(
|
|
27
|
+
db: DB,
|
|
28
|
+
input: CreateUnitInput & CF,
|
|
29
|
+
ctx: CommandContext,
|
|
30
|
+
) {
|
|
31
|
+
const { categoryId, name, symbol, conversionFactor, roundingPrecision, ...customFields } = input;
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.selectFrom("UoMCategory")
|
|
34
|
-
.selectAll()
|
|
35
|
-
.where("id", "=", categoryId)
|
|
36
|
-
.executeTakeFirst();
|
|
33
|
+
// 1. Check category exists
|
|
34
|
+
const { uoMCategory } = await getUoMCategory(db, { id: categoryId }, ctx);
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
if (!uoMCategory) {
|
|
37
|
+
return err(new UomCategoryNotFoundError(categoryId));
|
|
38
|
+
}
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
// 2. Check category is active
|
|
41
|
+
if (!uoMCategory.isActive) {
|
|
42
|
+
return err(new CategoryNotActiveError(categoryId));
|
|
43
|
+
}
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
// 3. Check symbol uniqueness within category
|
|
46
|
+
const existingUnit = await db
|
|
47
|
+
.selectFrom("Unit")
|
|
48
|
+
.selectAll()
|
|
49
|
+
.where("categoryId", "=", categoryId)
|
|
50
|
+
.where("symbol", "=", symbol)
|
|
51
|
+
.executeTakeFirst();
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
if (existingUnit) {
|
|
54
|
+
return err(new DuplicateUnitSymbolError(`${symbol} in ${categoryId}`));
|
|
55
|
+
}
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
// 4. Validate conversion factor
|
|
58
|
+
if (conversionFactor <= 0) {
|
|
59
|
+
return err(new InvalidConversionFactorError(String(conversionFactor)));
|
|
60
|
+
}
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
// 5. Validate rounding precision
|
|
63
|
+
if (roundingPrecision < 0) {
|
|
64
|
+
return err(new InvalidRoundingPrecisionError(String(roundingPrecision)));
|
|
65
|
+
}
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
// 6. Create unit
|
|
68
|
+
const unit = await db
|
|
69
|
+
.insertInto("Unit")
|
|
70
|
+
.values({
|
|
71
|
+
...(customFields as Record<string, unknown>),
|
|
72
|
+
name,
|
|
73
|
+
symbol,
|
|
74
|
+
categoryId,
|
|
75
|
+
conversionFactor,
|
|
76
|
+
roundingPrecision,
|
|
77
|
+
isActive: true,
|
|
78
|
+
createdAt: new Date(),
|
|
79
|
+
updatedAt: null,
|
|
80
|
+
})
|
|
81
|
+
.returningAll()
|
|
82
|
+
.executeTakeFirst();
|
|
85
83
|
|
|
86
|
-
|
|
87
|
-
});
|
|
84
|
+
return ok({ unit: unit! });
|
|
88
85
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @generated — do not edit
|
|
2
|
+
import { defineCommand } from "../../shared/internal";
|
|
3
|
+
import { permissions } from "../lib/permissions.generated";
|
|
4
|
+
import { run } from "./deactivateCategory";
|
|
5
|
+
|
|
6
|
+
export const deactivateCategory = defineCommand(permissions.deactivateCategory, run);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { createMockDb, testNotFound
|
|
2
|
+
import { createMockDb, testNotFound } from "../../testing/index";
|
|
3
3
|
import { type CommandContext } from "../../shared/internal";
|
|
4
4
|
import { DB } from "../generated/kysely-tailordb";
|
|
5
|
-
import { CategoryHasActiveUnitsError,
|
|
5
|
+
import { CategoryHasActiveUnitsError, UomCategoryNotFoundError } from "../lib/errors.generated";
|
|
6
6
|
import { baseUoMCategory, baseUnitKg } from "../testing/fixtures";
|
|
7
|
-
import {
|
|
7
|
+
import { run } from "./deactivateCategory";
|
|
8
8
|
|
|
9
9
|
describe("deactivateCategory", () => {
|
|
10
10
|
const ctx: CommandContext = {
|
|
@@ -19,12 +19,7 @@ describe("deactivateCategory", () => {
|
|
|
19
19
|
|
|
20
20
|
it(
|
|
21
21
|
"throws when category doesn't exist",
|
|
22
|
-
testNotFound(
|
|
23
|
-
deactivateCategory,
|
|
24
|
-
{ categoryId: "nonexistent-category" },
|
|
25
|
-
ctx,
|
|
26
|
-
UoMCategoryNotFoundError,
|
|
27
|
-
),
|
|
22
|
+
testNotFound(run, { categoryId: "nonexistent-category" }, ctx, UomCategoryNotFoundError),
|
|
28
23
|
);
|
|
29
24
|
|
|
30
25
|
it("throws when category has active units", async () => {
|
|
@@ -33,15 +28,18 @@ describe("deactivateCategory", () => {
|
|
|
33
28
|
.mockReturnValueOnce(baseUoMCategory) // Category lookup
|
|
34
29
|
.mockReturnValueOnce([baseUnitKg]); // Active units check
|
|
35
30
|
|
|
36
|
-
await
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
).
|
|
31
|
+
const result = await run(
|
|
32
|
+
db,
|
|
33
|
+
{
|
|
34
|
+
categoryId: baseUoMCategory.id,
|
|
35
|
+
},
|
|
36
|
+
ctx,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(result.ok).toBe(false);
|
|
40
|
+
if (!result.ok) {
|
|
41
|
+
expect(result.error).toBeInstanceOf(CategoryHasActiveUnitsError);
|
|
42
|
+
}
|
|
45
43
|
});
|
|
46
44
|
|
|
47
45
|
// Idempotent case needs multi-mock setup, kept inline
|
|
@@ -51,7 +49,7 @@ describe("deactivateCategory", () => {
|
|
|
51
49
|
.mockReturnValueOnce(inactiveCategory) // Category lookup
|
|
52
50
|
.mockReturnValueOnce([]); // No active units
|
|
53
51
|
|
|
54
|
-
const result = await
|
|
52
|
+
const result = await run(
|
|
55
53
|
db,
|
|
56
54
|
{
|
|
57
55
|
categoryId: inactiveCategory.id,
|
|
@@ -59,7 +57,10 @@ describe("deactivateCategory", () => {
|
|
|
59
57
|
ctx,
|
|
60
58
|
);
|
|
61
59
|
|
|
62
|
-
expect(result.
|
|
60
|
+
expect(result.ok).toBe(true);
|
|
61
|
+
if (result.ok) {
|
|
62
|
+
expect(result.value.uoMCategory).toEqual(inactiveCategory);
|
|
63
|
+
}
|
|
63
64
|
expect(spies.update).not.toHaveBeenCalled();
|
|
64
65
|
});
|
|
65
66
|
|
|
@@ -77,7 +78,7 @@ describe("deactivateCategory", () => {
|
|
|
77
78
|
.mockReturnValueOnce([]); // No active units
|
|
78
79
|
spies.update.mockReturnValue(deactivatedCategory);
|
|
79
80
|
|
|
80
|
-
const result = await
|
|
81
|
+
const result = await run(
|
|
81
82
|
db,
|
|
82
83
|
{
|
|
83
84
|
categoryId: baseUoMCategory.id,
|
|
@@ -85,13 +86,11 @@ describe("deactivateCategory", () => {
|
|
|
85
86
|
ctx,
|
|
86
87
|
);
|
|
87
88
|
|
|
88
|
-
expect(result.
|
|
89
|
-
|
|
89
|
+
expect(result.ok).toBe(true);
|
|
90
|
+
if (result.ok) {
|
|
91
|
+
expect(result.value.uoMCategory.isActive).toBe(false);
|
|
92
|
+
expect(result.value.uoMCategory.updatedAt).not.toBeNull();
|
|
93
|
+
}
|
|
90
94
|
expect(spies.update).toHaveBeenCalled();
|
|
91
95
|
});
|
|
92
|
-
|
|
93
|
-
it(
|
|
94
|
-
"throws when permission is missing",
|
|
95
|
-
testPermissionDenied(deactivateCategory, { categoryId: "cat-1" }),
|
|
96
|
-
);
|
|
97
96
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ok, err, type CommandContext } from "../../shared/internal";
|
|
2
2
|
import { DB } from "../generated/kysely-tailordb";
|
|
3
|
-
import { CategoryHasActiveUnitsError,
|
|
4
|
-
import {
|
|
3
|
+
import { CategoryHasActiveUnitsError, UomCategoryNotFoundError } from "../lib/errors.generated";
|
|
4
|
+
import { getUoMCategory } from "../query/getUoMCategory.generated";
|
|
5
5
|
|
|
6
6
|
export interface DeactivateCategoryInput {
|
|
7
7
|
categoryId: string;
|
|
@@ -13,50 +13,43 @@ export interface DeactivateCategoryInput {
|
|
|
13
13
|
* Disables a UoM category from being used in new product assignments
|
|
14
14
|
* while preserving historical data. All units must be deactivated first.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.returningAll()
|
|
57
|
-
.executeTakeFirst();
|
|
58
|
-
|
|
59
|
-
// 6. Return updated category
|
|
60
|
-
return { category: updatedCategory! };
|
|
61
|
-
},
|
|
62
|
-
);
|
|
16
|
+
export async function run(db: DB, input: DeactivateCategoryInput, ctx: CommandContext) {
|
|
17
|
+
// 1. Find category by ID
|
|
18
|
+
const { uoMCategory } = await getUoMCategory(db, { id: input.categoryId }, ctx);
|
|
19
|
+
|
|
20
|
+
// 2. If not found, throw error
|
|
21
|
+
if (!uoMCategory) {
|
|
22
|
+
return err(new UomCategoryNotFoundError(input.categoryId));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Active units must be deactivated before their category
|
|
26
|
+
const activeUnits = await db
|
|
27
|
+
.selectFrom("Unit")
|
|
28
|
+
.selectAll()
|
|
29
|
+
.where("categoryId", "=", input.categoryId)
|
|
30
|
+
.where("isActive", "=", true)
|
|
31
|
+
.execute();
|
|
32
|
+
|
|
33
|
+
if (activeUnits.length > 0) {
|
|
34
|
+
return err(new CategoryHasActiveUnitsError(input.categoryId));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 4. If already inactive, return category (idempotent)
|
|
38
|
+
if (!uoMCategory.isActive) {
|
|
39
|
+
return ok({ uoMCategory });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 5. Update isActive = false
|
|
43
|
+
const updatedCategory = await db
|
|
44
|
+
.updateTable("UoMCategory")
|
|
45
|
+
.set({
|
|
46
|
+
isActive: false,
|
|
47
|
+
updatedAt: new Date(),
|
|
48
|
+
})
|
|
49
|
+
.where("id", "=", input.categoryId)
|
|
50
|
+
.returningAll()
|
|
51
|
+
.executeTakeFirst();
|
|
52
|
+
|
|
53
|
+
// 6. Return updated category
|
|
54
|
+
return ok({ uoMCategory: updatedCategory! });
|
|
55
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @generated — do not edit
|
|
2
|
+
import { defineCommand } from "../../shared/internal";
|
|
3
|
+
import { permissions } from "../lib/permissions.generated";
|
|
4
|
+
import { run } from "./deactivateCurrency";
|
|
5
|
+
|
|
6
|
+
export const deactivateCurrency = defineCommand(permissions.deactivateCurrency, run);
|