@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
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Item, ItemTaxonomyAssignment, Schema, TaxonomyNode } from "../lib/types";
|
|
2
|
+
|
|
3
|
+
// Item fixtures
|
|
4
|
+
export const baseDraftItem = {
|
|
5
|
+
id: "item-1",
|
|
6
|
+
sku: "SKU-001",
|
|
7
|
+
name: "Draft Widget",
|
|
8
|
+
barcode: null,
|
|
9
|
+
unitId: "unit-kg",
|
|
10
|
+
status: "DRAFT",
|
|
11
|
+
createdAt: new Date("2024-01-01T00:00:00.000Z"),
|
|
12
|
+
updatedAt: null,
|
|
13
|
+
} as const satisfies Item<Schema>;
|
|
14
|
+
|
|
15
|
+
export const baseActiveItem = {
|
|
16
|
+
id: "item-2",
|
|
17
|
+
sku: "SKU-002",
|
|
18
|
+
name: "Active Widget",
|
|
19
|
+
barcode: "BAR-002",
|
|
20
|
+
unitId: "unit-kg",
|
|
21
|
+
status: "ACTIVE",
|
|
22
|
+
createdAt: new Date("2024-01-01T00:00:00.000Z"),
|
|
23
|
+
updatedAt: null,
|
|
24
|
+
} as const satisfies Item<Schema>;
|
|
25
|
+
|
|
26
|
+
export const baseInactiveItem = {
|
|
27
|
+
id: "item-3",
|
|
28
|
+
sku: "SKU-003",
|
|
29
|
+
name: "Inactive Widget",
|
|
30
|
+
barcode: "BAR-003",
|
|
31
|
+
unitId: "unit-kg",
|
|
32
|
+
status: "INACTIVE",
|
|
33
|
+
createdAt: new Date("2024-01-01T00:00:00.000Z"),
|
|
34
|
+
updatedAt: null,
|
|
35
|
+
} as const satisfies Item<Schema>;
|
|
36
|
+
|
|
37
|
+
// TaxonomyNode fixtures
|
|
38
|
+
export const baseRootNode = {
|
|
39
|
+
id: "node-1",
|
|
40
|
+
code: "ELECTRONICS",
|
|
41
|
+
name: "Electronics",
|
|
42
|
+
parentId: null,
|
|
43
|
+
createdAt: new Date("2024-01-01T00:00:00.000Z"),
|
|
44
|
+
updatedAt: null,
|
|
45
|
+
} as const satisfies TaxonomyNode<Schema>;
|
|
46
|
+
|
|
47
|
+
export const baseChildNode = {
|
|
48
|
+
id: "node-2",
|
|
49
|
+
code: "SMARTPHONES",
|
|
50
|
+
name: "Smartphones",
|
|
51
|
+
parentId: "node-1",
|
|
52
|
+
createdAt: new Date("2024-01-01T00:00:00.000Z"),
|
|
53
|
+
updatedAt: null,
|
|
54
|
+
} as const satisfies TaxonomyNode<Schema>;
|
|
55
|
+
|
|
56
|
+
export const baseLeafNode = {
|
|
57
|
+
id: "node-3",
|
|
58
|
+
code: "ANDROID",
|
|
59
|
+
name: "Android Phones",
|
|
60
|
+
parentId: "node-2",
|
|
61
|
+
createdAt: new Date("2024-01-01T00:00:00.000Z"),
|
|
62
|
+
updatedAt: null,
|
|
63
|
+
} as const satisfies TaxonomyNode<Schema>;
|
|
64
|
+
|
|
65
|
+
export const secondRootNode = {
|
|
66
|
+
id: "node-4",
|
|
67
|
+
code: "GIFTS",
|
|
68
|
+
name: "Gift Ideas",
|
|
69
|
+
parentId: null,
|
|
70
|
+
createdAt: new Date("2024-01-01T00:00:00.000Z"),
|
|
71
|
+
updatedAt: null,
|
|
72
|
+
} as const satisfies TaxonomyNode<Schema>;
|
|
73
|
+
|
|
74
|
+
// ItemTaxonomyAssignment fixtures
|
|
75
|
+
export const baseAssignment = {
|
|
76
|
+
id: "assignment-1",
|
|
77
|
+
itemId: "item-2",
|
|
78
|
+
taxonomyNodeId: "node-2",
|
|
79
|
+
createdAt: new Date("2024-01-01T00:00:00.000Z"),
|
|
80
|
+
updatedAt: null,
|
|
81
|
+
} as const satisfies ItemTaxonomyAssignment<Schema>;
|
|
@@ -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 "./activateCategory";
|
|
5
|
+
|
|
6
|
+
export const activateCategory = defineCommand(permissions.activateCategory, run);
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
createMockDb,
|
|
4
|
-
testNotFound,
|
|
5
|
-
testPermissionDenied,
|
|
6
|
-
testIdempotent,
|
|
7
|
-
} from "../../testing/index";
|
|
2
|
+
import { createMockDb, testNotFound, testIdempotent } from "../../testing/index";
|
|
8
3
|
import { type CommandContext } from "../../shared/internal";
|
|
9
4
|
import { DB } from "../generated/kysely-tailordb";
|
|
10
|
-
import {
|
|
5
|
+
import { UomCategoryNotFoundError } from "../lib/errors.generated";
|
|
11
6
|
import { baseUoMCategory } from "../testing/fixtures";
|
|
12
|
-
import {
|
|
7
|
+
import { run } from "./activateCategory";
|
|
13
8
|
|
|
14
9
|
describe("activateCategory", () => {
|
|
15
10
|
const ctx: CommandContext = {
|
|
@@ -24,23 +19,12 @@ describe("activateCategory", () => {
|
|
|
24
19
|
|
|
25
20
|
it(
|
|
26
21
|
"throws when category doesn't exist",
|
|
27
|
-
testNotFound(
|
|
28
|
-
activateCategory,
|
|
29
|
-
{ categoryId: "nonexistent-category" },
|
|
30
|
-
ctx,
|
|
31
|
-
UoMCategoryNotFoundError,
|
|
32
|
-
),
|
|
22
|
+
testNotFound(run, { categoryId: "nonexistent-category" }, ctx, UomCategoryNotFoundError),
|
|
33
23
|
);
|
|
34
24
|
|
|
35
25
|
it(
|
|
36
26
|
"returns category unchanged when already active",
|
|
37
|
-
testIdempotent(
|
|
38
|
-
activateCategory,
|
|
39
|
-
{ categoryId: baseUoMCategory.id },
|
|
40
|
-
ctx,
|
|
41
|
-
baseUoMCategory,
|
|
42
|
-
"category",
|
|
43
|
-
),
|
|
27
|
+
testIdempotent(run, { categoryId: baseUoMCategory.id }, ctx, baseUoMCategory, "uoMCategory"),
|
|
44
28
|
);
|
|
45
29
|
|
|
46
30
|
// Success cases
|
|
@@ -55,7 +39,7 @@ describe("activateCategory", () => {
|
|
|
55
39
|
spies.select.mockReturnValue(inactiveCategory);
|
|
56
40
|
spies.update.mockReturnValue(activatedCategory);
|
|
57
41
|
|
|
58
|
-
const result = await
|
|
42
|
+
const result = await run(
|
|
59
43
|
db,
|
|
60
44
|
{
|
|
61
45
|
categoryId: inactiveCategory.id,
|
|
@@ -63,13 +47,11 @@ describe("activateCategory", () => {
|
|
|
63
47
|
ctx,
|
|
64
48
|
);
|
|
65
49
|
|
|
66
|
-
expect(result.
|
|
67
|
-
|
|
50
|
+
expect(result.ok).toBe(true);
|
|
51
|
+
if (result.ok) {
|
|
52
|
+
expect(result.value.uoMCategory.isActive).toBe(true);
|
|
53
|
+
expect(result.value.uoMCategory.updatedAt).not.toBeNull();
|
|
54
|
+
}
|
|
68
55
|
expect(spies.update).toHaveBeenCalled();
|
|
69
56
|
});
|
|
70
|
-
|
|
71
|
-
it(
|
|
72
|
-
"throws when permission is missing",
|
|
73
|
-
testPermissionDenied(activateCategory, { categoryId: "cat-1" }),
|
|
74
|
-
);
|
|
75
57
|
});
|
|
@@ -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 {
|
|
4
|
-
import {
|
|
3
|
+
import { UomCategoryNotFoundError } from "../lib/errors.generated";
|
|
4
|
+
import { getUoMCategory } from "../query/getUoMCategory.generated";
|
|
5
5
|
|
|
6
6
|
export interface ActivateCategoryInput {
|
|
7
7
|
categoryId: string;
|
|
@@ -13,38 +13,31 @@ export interface ActivateCategoryInput {
|
|
|
13
13
|
* Re-enables a previously deactivated UoM category, making it and its units
|
|
14
14
|
* available for new product assignments and transactions.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// 1. Find category by ID
|
|
20
|
-
const category = await db
|
|
21
|
-
.selectFrom("UoMCategory")
|
|
22
|
-
.selectAll()
|
|
23
|
-
.where("id", "=", input.categoryId)
|
|
24
|
-
.executeTakeFirst();
|
|
16
|
+
export async function run(db: DB, input: ActivateCategoryInput, ctx: CommandContext) {
|
|
17
|
+
// 1. Find category by ID
|
|
18
|
+
const { uoMCategory } = await getUoMCategory(db, { id: input.categoryId }, ctx);
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
// 2. If not found, throw error
|
|
21
|
+
if (!uoMCategory) {
|
|
22
|
+
return err(new UomCategoryNotFoundError(input.categoryId));
|
|
23
|
+
}
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
// 3. If already active, return category (idempotent)
|
|
26
|
+
if (uoMCategory.isActive) {
|
|
27
|
+
return ok({ uoMCategory });
|
|
28
|
+
}
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
// 4. Update isActive = true
|
|
31
|
+
const updatedCategory = await db
|
|
32
|
+
.updateTable("UoMCategory")
|
|
33
|
+
.set({
|
|
34
|
+
isActive: true,
|
|
35
|
+
updatedAt: new Date(),
|
|
36
|
+
})
|
|
37
|
+
.where("id", "=", input.categoryId)
|
|
38
|
+
.returningAll()
|
|
39
|
+
.executeTakeFirst();
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
);
|
|
41
|
+
// 5. Return updated category
|
|
42
|
+
return ok({ uoMCategory: updatedCategory! });
|
|
43
|
+
}
|
|
@@ -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 "./activateCurrency";
|
|
5
|
+
|
|
6
|
+
export const activateCurrency = defineCommand(permissions.activateCurrency, run);
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
createMockDb,
|
|
4
|
-
testNotFound,
|
|
5
|
-
testPermissionDenied,
|
|
6
|
-
testIdempotent,
|
|
7
|
-
} from "../../testing/index";
|
|
2
|
+
import { createMockDb, testNotFound, testIdempotent } from "../../testing/index";
|
|
8
3
|
import { type CommandContext } from "../../shared/internal";
|
|
9
4
|
import { DB } from "../generated/kysely-tailordb";
|
|
10
|
-
import { CurrencyNotFoundError } from "../lib/errors";
|
|
5
|
+
import { CurrencyNotFoundError } from "../lib/errors.generated";
|
|
11
6
|
import { baseCurrencyUSD, inactiveCurrency } from "../testing/fixtures";
|
|
12
|
-
import {
|
|
7
|
+
import { run } from "./activateCurrency";
|
|
13
8
|
|
|
14
9
|
describe("activateCurrency", () => {
|
|
15
10
|
const ctx: CommandContext = {
|
|
@@ -19,23 +14,12 @@ describe("activateCurrency", () => {
|
|
|
19
14
|
|
|
20
15
|
it(
|
|
21
16
|
"throws when currency doesn't exist",
|
|
22
|
-
testNotFound(
|
|
23
|
-
activateCurrency,
|
|
24
|
-
{ currencyId: "nonexistent-currency" },
|
|
25
|
-
ctx,
|
|
26
|
-
CurrencyNotFoundError,
|
|
27
|
-
),
|
|
17
|
+
testNotFound(run, { currencyId: "nonexistent-currency" }, ctx, CurrencyNotFoundError),
|
|
28
18
|
);
|
|
29
19
|
|
|
30
20
|
it(
|
|
31
21
|
"returns currency unchanged when already active",
|
|
32
|
-
testIdempotent(
|
|
33
|
-
activateCurrency,
|
|
34
|
-
{ currencyId: baseCurrencyUSD.id },
|
|
35
|
-
ctx,
|
|
36
|
-
baseCurrencyUSD,
|
|
37
|
-
"currency",
|
|
38
|
-
),
|
|
22
|
+
testIdempotent(run, { currencyId: baseCurrencyUSD.id }, ctx, baseCurrencyUSD, "currency"),
|
|
39
23
|
);
|
|
40
24
|
|
|
41
25
|
// Success cases
|
|
@@ -50,7 +34,7 @@ describe("activateCurrency", () => {
|
|
|
50
34
|
spies.select.mockReturnValue(inactiveCurrency);
|
|
51
35
|
spies.update.mockReturnValue(activatedCurrency);
|
|
52
36
|
|
|
53
|
-
const result = await
|
|
37
|
+
const result = await run(
|
|
54
38
|
db,
|
|
55
39
|
{
|
|
56
40
|
currencyId: inactiveCurrency.id,
|
|
@@ -58,13 +42,11 @@ describe("activateCurrency", () => {
|
|
|
58
42
|
ctx,
|
|
59
43
|
);
|
|
60
44
|
|
|
61
|
-
expect(result.
|
|
62
|
-
|
|
45
|
+
expect(result.ok).toBe(true);
|
|
46
|
+
if (result.ok) {
|
|
47
|
+
expect(result.value.currency.isActive).toBe(true);
|
|
48
|
+
expect(result.value.currency.updatedAt).not.toBeNull();
|
|
49
|
+
}
|
|
63
50
|
expect(spies.update).toHaveBeenCalled();
|
|
64
51
|
});
|
|
65
|
-
|
|
66
|
-
it(
|
|
67
|
-
"throws when permission is missing",
|
|
68
|
-
testPermissionDenied(activateCurrency, { currencyId: "cur-1" }),
|
|
69
|
-
);
|
|
70
52
|
});
|
|
@@ -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 { CurrencyNotFoundError } from "../lib/errors";
|
|
4
|
-
import {
|
|
3
|
+
import { CurrencyNotFoundError } from "../lib/errors.generated";
|
|
4
|
+
import { getCurrency } from "../query/getCurrency.generated";
|
|
5
5
|
|
|
6
6
|
export interface ActivateCurrencyInput {
|
|
7
7
|
currencyId: string;
|
|
@@ -13,38 +13,31 @@ export interface ActivateCurrencyInput {
|
|
|
13
13
|
* Re-enables a previously deactivated currency, making it available
|
|
14
14
|
* for new transactions.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// 1. Find currency by ID
|
|
20
|
-
const currency = await db
|
|
21
|
-
.selectFrom("Currency")
|
|
22
|
-
.selectAll()
|
|
23
|
-
.where("id", "=", input.currencyId)
|
|
24
|
-
.executeTakeFirst();
|
|
16
|
+
export async function run(db: DB, input: ActivateCurrencyInput, ctx: CommandContext) {
|
|
17
|
+
// 1. Find currency by ID
|
|
18
|
+
const { currency } = await getCurrency(db, { id: input.currencyId }, ctx);
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
// 2. If not found, throw error
|
|
21
|
+
if (!currency) {
|
|
22
|
+
return err(new CurrencyNotFoundError(input.currencyId));
|
|
23
|
+
}
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
// 3. If already active, return currency (idempotent)
|
|
26
|
+
if (currency.isActive) {
|
|
27
|
+
return ok({ currency });
|
|
28
|
+
}
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
// 4. Update isActive = true
|
|
31
|
+
const updatedCurrency = await db
|
|
32
|
+
.updateTable("Currency")
|
|
33
|
+
.set({
|
|
34
|
+
isActive: true,
|
|
35
|
+
updatedAt: new Date(),
|
|
36
|
+
})
|
|
37
|
+
.where("id", "=", input.currencyId)
|
|
38
|
+
.returningAll()
|
|
39
|
+
.executeTakeFirst();
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
);
|
|
41
|
+
// 5. Return updated currency
|
|
42
|
+
return ok({ currency: updatedCurrency! });
|
|
43
|
+
}
|
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
createMockDb,
|
|
4
|
-
testNotFound,
|
|
5
|
-
testPermissionDenied,
|
|
6
|
-
testIdempotent,
|
|
7
|
-
} from "../../testing/index";
|
|
2
|
+
import { createMockDb, testNotFound, testIdempotent } from "../../testing/index";
|
|
8
3
|
import { type CommandContext } from "../../shared/internal";
|
|
9
4
|
import { DB } from "../generated/kysely-tailordb";
|
|
10
|
-
import { UnitNotFoundError } from "../lib/errors";
|
|
5
|
+
import { UnitNotFoundError } from "../lib/errors.generated";
|
|
11
6
|
import { baseUnitKg, inactiveUnit } from "../testing/fixtures";
|
|
12
|
-
import {
|
|
7
|
+
import { run } from "./activateUnit";
|
|
13
8
|
|
|
14
9
|
describe("activateUnit", () => {
|
|
15
10
|
const ctx: CommandContext = { actorId: "test-actor", permissions: ["primitives:activateUnit"] };
|
|
16
11
|
|
|
17
12
|
it(
|
|
18
13
|
"throws when unit doesn't exist",
|
|
19
|
-
testNotFound(
|
|
14
|
+
testNotFound(run, { unitId: "nonexistent-unit" }, ctx, UnitNotFoundError),
|
|
20
15
|
);
|
|
21
16
|
|
|
22
17
|
it(
|
|
23
18
|
"returns unit unchanged when already active",
|
|
24
|
-
testIdempotent(
|
|
19
|
+
testIdempotent(run, { unitId: baseUnitKg.id }, ctx, baseUnitKg, "unit"),
|
|
25
20
|
);
|
|
26
21
|
|
|
27
22
|
// Success cases
|
|
@@ -36,7 +31,7 @@ describe("activateUnit", () => {
|
|
|
36
31
|
spies.select.mockReturnValue(inactiveUnit);
|
|
37
32
|
spies.update.mockReturnValue(activatedUnit);
|
|
38
33
|
|
|
39
|
-
const result = await
|
|
34
|
+
const result = await run(
|
|
40
35
|
db,
|
|
41
36
|
{
|
|
42
37
|
unitId: inactiveUnit.id,
|
|
@@ -44,10 +39,11 @@ describe("activateUnit", () => {
|
|
|
44
39
|
ctx,
|
|
45
40
|
);
|
|
46
41
|
|
|
47
|
-
expect(result.
|
|
48
|
-
|
|
42
|
+
expect(result.ok).toBe(true);
|
|
43
|
+
if (result.ok) {
|
|
44
|
+
expect(result.value.unit.isActive).toBe(true);
|
|
45
|
+
expect(result.value.unit.updatedAt).not.toBeNull();
|
|
46
|
+
}
|
|
49
47
|
expect(spies.update).toHaveBeenCalled();
|
|
50
48
|
});
|
|
51
|
-
|
|
52
|
-
it("throws when permission is missing", testPermissionDenied(activateUnit, { unitId: "unit-1" }));
|
|
53
49
|
});
|
|
@@ -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 { UnitNotFoundError } from "../lib/errors";
|
|
4
|
-
import {
|
|
3
|
+
import { UnitNotFoundError } from "../lib/errors.generated";
|
|
4
|
+
import { getUnit } from "../query/getUnit.generated";
|
|
5
5
|
|
|
6
6
|
export interface ActivateUnitInput {
|
|
7
7
|
unitId: string;
|
|
@@ -13,38 +13,31 @@ export interface ActivateUnitInput {
|
|
|
13
13
|
* Re-enables a previously deactivated unit of measure, making it available
|
|
14
14
|
* for new product assignments and quantity conversions.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// 1. Find unit by ID
|
|
20
|
-
const unit = await db
|
|
21
|
-
.selectFrom("Unit")
|
|
22
|
-
.selectAll()
|
|
23
|
-
.where("id", "=", input.unitId)
|
|
24
|
-
.executeTakeFirst();
|
|
16
|
+
export async function run(db: DB, input: ActivateUnitInput, ctx: CommandContext) {
|
|
17
|
+
// 1. Find unit by ID
|
|
18
|
+
const { unit } = await getUnit(db, { id: input.unitId }, ctx);
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
// 2. If not found, throw error
|
|
21
|
+
if (!unit) {
|
|
22
|
+
return err(new UnitNotFoundError(input.unitId));
|
|
23
|
+
}
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
// 3. If already active, return unit (idempotent)
|
|
26
|
+
if (unit.isActive) {
|
|
27
|
+
return ok({ unit });
|
|
28
|
+
}
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
// 4. Update isActive = true
|
|
31
|
+
const updatedUnit = await db
|
|
32
|
+
.updateTable("Unit")
|
|
33
|
+
.set({
|
|
34
|
+
isActive: true,
|
|
35
|
+
updatedAt: new Date(),
|
|
36
|
+
})
|
|
37
|
+
.where("id", "=", input.unitId)
|
|
38
|
+
.returningAll()
|
|
39
|
+
.executeTakeFirst();
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
);
|
|
41
|
+
// 5. Return updated unit
|
|
42
|
+
return ok({ unit: updatedUnit! });
|
|
43
|
+
}
|
|
@@ -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 "./createCategory";
|
|
5
|
+
|
|
6
|
+
export const createCategory = defineCommand(permissions.createCategory, run);
|
|
@@ -1,12 +1,10 @@
|
|
|
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
|
-
import { DuplicateCategoryNameError } from "../lib/errors";
|
|
5
|
+
import { DuplicateCategoryNameError } from "../lib/errors.generated";
|
|
6
6
|
import { baseUoMCategory, baseUnitKg } from "../testing/fixtures";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
const createCategory = makeCreateCategory();
|
|
7
|
+
import { run } from "./createCategory";
|
|
10
8
|
|
|
11
9
|
describe("createCategory", () => {
|
|
12
10
|
const ctx: CommandContext = { actorId: "test-actor", permissions: ["primitives:createCategory"] };
|
|
@@ -16,20 +14,23 @@ describe("createCategory", () => {
|
|
|
16
14
|
const { db, spies } = createMockDb<DB>();
|
|
17
15
|
spies.select.mockReturnValue(baseUoMCategory);
|
|
18
16
|
|
|
19
|
-
await
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
roundingPrecision: 2,
|
|
28
|
-
},
|
|
17
|
+
const result = await run(
|
|
18
|
+
db,
|
|
19
|
+
{
|
|
20
|
+
name: baseUoMCategory.name,
|
|
21
|
+
referenceUnit: {
|
|
22
|
+
name: "Kilogram",
|
|
23
|
+
symbol: "kg",
|
|
24
|
+
roundingPrecision: 2,
|
|
29
25
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
26
|
+
},
|
|
27
|
+
ctx,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
expect(result.ok).toBe(false);
|
|
31
|
+
if (!result.ok) {
|
|
32
|
+
expect(result.error).toBeInstanceOf(DuplicateCategoryNameError);
|
|
33
|
+
}
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
// Success cases
|
|
@@ -50,7 +51,7 @@ describe("createCategory", () => {
|
|
|
50
51
|
spies.insert.mockReturnValueOnce(createdCategory).mockReturnValueOnce(createdUnit);
|
|
51
52
|
spies.update.mockReturnValue({ ...createdCategory, referenceUnitId: "new-unit-id" });
|
|
52
53
|
|
|
53
|
-
const result = await
|
|
54
|
+
const result = await run(
|
|
54
55
|
db,
|
|
55
56
|
{
|
|
56
57
|
name: "Weight",
|
|
@@ -64,29 +65,16 @@ describe("createCategory", () => {
|
|
|
64
65
|
ctx,
|
|
65
66
|
);
|
|
66
67
|
|
|
67
|
-
expect(result.
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
expect(result.ok).toBe(true);
|
|
69
|
+
if (result.ok) {
|
|
70
|
+
expect(result.value.uoMCategory.name).toBe("Weight");
|
|
71
|
+
expect(result.value.uoMCategory.isActive).toBe(true);
|
|
72
|
+
expect(result.value.referenceUnit.conversionFactor).toBe(1.0);
|
|
73
|
+
}
|
|
70
74
|
expect(spies.insert).toHaveBeenCalled();
|
|
71
75
|
});
|
|
72
76
|
|
|
73
|
-
it("throws when permission is missing", async () => {
|
|
74
|
-
const { db } = createMockDb<DB>();
|
|
75
|
-
const denied: CommandContext = { actorId: "test-actor", permissions: [] };
|
|
76
|
-
await expect(
|
|
77
|
-
createCategory(
|
|
78
|
-
db,
|
|
79
|
-
{ name: "Test", referenceUnit: { name: "Unit", symbol: "u", roundingPrecision: 2 } },
|
|
80
|
-
denied,
|
|
81
|
-
),
|
|
82
|
-
).rejects.toBeInstanceOf(InsufficientPermissionError);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
77
|
it("passes custom fields through to insert", async () => {
|
|
86
|
-
const createCategoryWithFields = makeCreateCategory<
|
|
87
|
-
{ priority: number },
|
|
88
|
-
{ tolerance: number }
|
|
89
|
-
>();
|
|
90
78
|
const { db, spies } = createMockDb<DB>();
|
|
91
79
|
const createdCategory = {
|
|
92
80
|
...baseUoMCategory,
|
|
@@ -103,7 +91,7 @@ describe("createCategory", () => {
|
|
|
103
91
|
spies.insert.mockReturnValueOnce(createdCategory).mockReturnValueOnce(createdUnit);
|
|
104
92
|
spies.update.mockReturnValue({ ...createdCategory, referenceUnitId: "new-unit-id" });
|
|
105
93
|
|
|
106
|
-
await
|
|
94
|
+
await run(
|
|
107
95
|
db,
|
|
108
96
|
{
|
|
109
97
|
name: "Weight",
|