@open-mercato/core 0.4.5-develop-0f0e676c72 → 0.4.5-develop-e694581d9f

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.
Files changed (113) hide show
  1. package/dist/generated/entities/customer_deal/index.js +4 -0
  2. package/dist/generated/entities/customer_deal/index.js.map +2 -2
  3. package/dist/generated/entities/customer_pipeline/index.js +17 -0
  4. package/dist/generated/entities/customer_pipeline/index.js.map +7 -0
  5. package/dist/generated/entities/customer_pipeline_stage/index.js +19 -0
  6. package/dist/generated/entities/customer_pipeline_stage/index.js.map +7 -0
  7. package/dist/generated/entities.ids.generated.js +2 -0
  8. package/dist/generated/entities.ids.generated.js.map +2 -2
  9. package/dist/generated/entity-fields-registry.js +4 -0
  10. package/dist/generated/entity-fields-registry.js.map +2 -2
  11. package/dist/modules/customers/acl.js +2 -0
  12. package/dist/modules/customers/acl.js.map +2 -2
  13. package/dist/modules/customers/api/deals/[id]/route.js +4 -0
  14. package/dist/modules/customers/api/deals/[id]/route.js.map +2 -2
  15. package/dist/modules/customers/api/deals/route.js +12 -0
  16. package/dist/modules/customers/api/deals/route.js.map +2 -2
  17. package/dist/modules/customers/api/dictionaries/[kind]/route.js +20 -1
  18. package/dist/modules/customers/api/dictionaries/[kind]/route.js.map +2 -2
  19. package/dist/modules/customers/api/pipeline-stages/reorder/route.js +69 -0
  20. package/dist/modules/customers/api/pipeline-stages/reorder/route.js.map +7 -0
  21. package/dist/modules/customers/api/pipeline-stages/route.js +275 -0
  22. package/dist/modules/customers/api/pipeline-stages/route.js.map +7 -0
  23. package/dist/modules/customers/api/pipelines/route.js +245 -0
  24. package/dist/modules/customers/api/pipelines/route.js.map +7 -0
  25. package/dist/modules/customers/backend/config/customers/page.js +2 -0
  26. package/dist/modules/customers/backend/config/customers/page.js.map +2 -2
  27. package/dist/modules/customers/backend/config/customers/pipeline-stages/page.js +439 -0
  28. package/dist/modules/customers/backend/config/customers/pipeline-stages/page.js.map +7 -0
  29. package/dist/modules/customers/backend/config/customers/pipeline-stages/page.meta.js +17 -0
  30. package/dist/modules/customers/backend/config/customers/pipeline-stages/page.meta.js.map +7 -0
  31. package/dist/modules/customers/backend/customers/deals/[id]/page.js +19 -1
  32. package/dist/modules/customers/backend/customers/deals/[id]/page.js.map +2 -2
  33. package/dist/modules/customers/backend/customers/deals/page.js +35 -1
  34. package/dist/modules/customers/backend/customers/deals/page.js.map +2 -2
  35. package/dist/modules/customers/backend/customers/deals/pipeline/page.js +102 -74
  36. package/dist/modules/customers/backend/customers/deals/pipeline/page.js.map +2 -2
  37. package/dist/modules/customers/cli.js +28 -2
  38. package/dist/modules/customers/cli.js.map +2 -2
  39. package/dist/modules/customers/commands/deals.js +34 -2
  40. package/dist/modules/customers/commands/deals.js.map +2 -2
  41. package/dist/modules/customers/commands/index.js +2 -0
  42. package/dist/modules/customers/commands/index.js.map +2 -2
  43. package/dist/modules/customers/commands/pipeline-stages.js +126 -0
  44. package/dist/modules/customers/commands/pipeline-stages.js.map +7 -0
  45. package/dist/modules/customers/commands/pipelines.js +87 -0
  46. package/dist/modules/customers/commands/pipelines.js.map +7 -0
  47. package/dist/modules/customers/components/DictionarySettings.js +0 -5
  48. package/dist/modules/customers/components/DictionarySettings.js.map +2 -2
  49. package/dist/modules/customers/components/PipelineSettings.js +474 -0
  50. package/dist/modules/customers/components/PipelineSettings.js.map +7 -0
  51. package/dist/modules/customers/components/detail/DealForm.js +84 -12
  52. package/dist/modules/customers/components/detail/DealForm.js.map +2 -2
  53. package/dist/modules/customers/data/entities.js +78 -0
  54. package/dist/modules/customers/data/entities.js.map +2 -2
  55. package/dist/modules/customers/data/validators.js +44 -0
  56. package/dist/modules/customers/data/validators.js.map +2 -2
  57. package/dist/modules/customers/migrations/Migration20260218191730.js +77 -0
  58. package/dist/modules/customers/migrations/Migration20260218191730.js.map +7 -0
  59. package/dist/modules/customers/setup.js +7 -3
  60. package/dist/modules/customers/setup.js.map +2 -2
  61. package/dist/modules/translations/api/[entityType]/[entityId]/route.js +46 -44
  62. package/dist/modules/translations/api/[entityType]/[entityId]/route.js.map +2 -2
  63. package/dist/modules/translations/api/context.js +10 -1
  64. package/dist/modules/translations/api/context.js.map +2 -2
  65. package/dist/modules/translations/commands/index.js +2 -0
  66. package/dist/modules/translations/commands/index.js.map +7 -0
  67. package/dist/modules/translations/commands/translations.js +160 -0
  68. package/dist/modules/translations/commands/translations.js.map +7 -0
  69. package/dist/modules/translations/index.js +1 -0
  70. package/dist/modules/translations/index.js.map +2 -2
  71. package/dist/modules/workflows/migrations/Migration20260222205305.js +14 -0
  72. package/dist/modules/workflows/migrations/Migration20260222205305.js.map +7 -0
  73. package/generated/entities/customer_deal/index.ts +2 -0
  74. package/generated/entities/customer_pipeline/index.ts +7 -0
  75. package/generated/entities/customer_pipeline_stage/index.ts +8 -0
  76. package/generated/entities.ids.generated.ts +2 -0
  77. package/generated/entity-fields-registry.ts +4 -0
  78. package/package.json +2 -2
  79. package/src/modules/customers/acl.ts +2 -0
  80. package/src/modules/customers/api/deals/[id]/route.ts +4 -0
  81. package/src/modules/customers/api/deals/route.ts +12 -0
  82. package/src/modules/customers/api/dictionaries/[kind]/route.ts +21 -1
  83. package/src/modules/customers/api/pipeline-stages/reorder/route.ts +71 -0
  84. package/src/modules/customers/api/pipeline-stages/route.ts +296 -0
  85. package/src/modules/customers/api/pipelines/route.ts +261 -0
  86. package/src/modules/customers/backend/config/customers/page.tsx +2 -0
  87. package/src/modules/customers/backend/config/customers/pipeline-stages/page.meta.ts +13 -0
  88. package/src/modules/customers/backend/config/customers/pipeline-stages/page.tsx +512 -0
  89. package/src/modules/customers/backend/customers/deals/[id]/page.tsx +21 -1
  90. package/src/modules/customers/backend/customers/deals/page.tsx +33 -1
  91. package/src/modules/customers/backend/customers/deals/pipeline/page.tsx +119 -79
  92. package/src/modules/customers/cli.ts +29 -1
  93. package/src/modules/customers/commands/deals.ts +44 -1
  94. package/src/modules/customers/commands/index.ts +2 -0
  95. package/src/modules/customers/commands/pipeline-stages.ts +156 -0
  96. package/src/modules/customers/commands/pipelines.ts +105 -0
  97. package/src/modules/customers/components/DictionarySettings.tsx +0 -5
  98. package/src/modules/customers/components/PipelineSettings.tsx +570 -0
  99. package/src/modules/customers/components/detail/DealForm.tsx +89 -11
  100. package/src/modules/customers/data/entities.ts +64 -0
  101. package/src/modules/customers/data/validators.ts +57 -0
  102. package/src/modules/customers/i18n/de.json +4 -0
  103. package/src/modules/customers/i18n/en.json +4 -0
  104. package/src/modules/customers/i18n/es.json +4 -0
  105. package/src/modules/customers/i18n/pl.json +5 -1
  106. package/src/modules/customers/migrations/Migration20260218191730.ts +84 -0
  107. package/src/modules/customers/setup.ts +5 -1
  108. package/src/modules/translations/api/[entityType]/[entityId]/route.ts +65 -60
  109. package/src/modules/translations/api/context.ts +12 -0
  110. package/src/modules/translations/commands/index.ts +1 -0
  111. package/src/modules/translations/commands/translations.ts +253 -0
  112. package/src/modules/translations/index.ts +1 -0
  113. package/src/modules/workflows/migrations/Migration20260222205305.ts +13 -0
@@ -0,0 +1,105 @@
1
+ import { registerCommand } from '@open-mercato/shared/lib/commands'
2
+ import type { CommandHandler } from '@open-mercato/shared/lib/commands'
3
+ import type { EntityManager } from '@mikro-orm/postgresql'
4
+ import { CustomerPipeline, CustomerDeal } from '../data/entities'
5
+ import {
6
+ pipelineCreateSchema,
7
+ pipelineUpdateSchema,
8
+ pipelineDeleteSchema,
9
+ type PipelineCreateInput,
10
+ type PipelineUpdateInput,
11
+ type PipelineDeleteInput,
12
+ } from '../data/validators'
13
+ import { ensureOrganizationScope, ensureTenantScope } from './shared'
14
+ import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
15
+
16
+ const createPipelineCommand: CommandHandler<PipelineCreateInput, { pipelineId: string }> = {
17
+ id: 'customers.pipelines.create',
18
+ async execute(rawInput, ctx) {
19
+ const parsed = pipelineCreateSchema.parse(rawInput)
20
+ ensureTenantScope(ctx, parsed.tenantId)
21
+ ensureOrganizationScope(ctx, parsed.organizationId)
22
+
23
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
24
+
25
+ if (parsed.isDefault) {
26
+ await em.nativeUpdate(
27
+ CustomerPipeline,
28
+ { organizationId: parsed.organizationId, tenantId: parsed.tenantId, isDefault: true },
29
+ { isDefault: false }
30
+ )
31
+ }
32
+
33
+ const pipeline = em.create(CustomerPipeline, {
34
+ organizationId: parsed.organizationId,
35
+ tenantId: parsed.tenantId,
36
+ name: parsed.name,
37
+ isDefault: parsed.isDefault ?? false,
38
+ createdAt: new Date(),
39
+ updatedAt: new Date(),
40
+ })
41
+ em.persist(pipeline)
42
+ await em.flush()
43
+
44
+ return { pipelineId: pipeline.id }
45
+ },
46
+ }
47
+
48
+ const updatePipelineCommand: CommandHandler<PipelineUpdateInput, void> = {
49
+ id: 'customers.pipelines.update',
50
+ async execute(rawInput, ctx) {
51
+ const parsed = pipelineUpdateSchema.parse(rawInput)
52
+
53
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
54
+ const pipeline = await em.findOne(CustomerPipeline, { id: parsed.id })
55
+ if (!pipeline) throw new CrudHttpError(404, { error: 'Pipeline not found' })
56
+
57
+ ensureTenantScope(ctx, pipeline.tenantId)
58
+ ensureOrganizationScope(ctx, pipeline.organizationId)
59
+
60
+ if (parsed.isDefault && !pipeline.isDefault) {
61
+ await em.nativeUpdate(
62
+ CustomerPipeline,
63
+ { organizationId: pipeline.organizationId, tenantId: pipeline.tenantId, isDefault: true },
64
+ { isDefault: false }
65
+ )
66
+ }
67
+
68
+ if (parsed.name !== undefined) pipeline.name = parsed.name
69
+ if (parsed.isDefault !== undefined) pipeline.isDefault = parsed.isDefault
70
+ pipeline.updatedAt = new Date()
71
+
72
+ await em.flush()
73
+ },
74
+ }
75
+
76
+ const deletePipelineCommand: CommandHandler<PipelineDeleteInput, void> = {
77
+ id: 'customers.pipelines.delete',
78
+ async execute(rawInput, ctx) {
79
+ const parsed = pipelineDeleteSchema.parse(rawInput)
80
+
81
+ const em = (ctx.container.resolve('em') as EntityManager).fork()
82
+ const pipeline = await em.findOne(CustomerPipeline, { id: parsed.id })
83
+ if (!pipeline) throw new CrudHttpError(404, { error: 'Pipeline not found' })
84
+
85
+ ensureTenantScope(ctx, pipeline.tenantId)
86
+ ensureOrganizationScope(ctx, pipeline.organizationId)
87
+
88
+ const activeDealsCount = await em.count(CustomerDeal, {
89
+ pipelineId: parsed.id,
90
+ deletedAt: null,
91
+ })
92
+ if (activeDealsCount > 0) {
93
+ throw new CrudHttpError(409, { error: 'Cannot delete pipeline with active deals' })
94
+ }
95
+
96
+ em.remove(pipeline)
97
+ await em.flush()
98
+ },
99
+ }
100
+
101
+ registerCommand(createPipelineCommand)
102
+ registerCommand(updatePipelineCommand)
103
+ registerCommand(deletePipelineCommand)
104
+
105
+ export { createPipelineCommand, updatePipelineCommand, deletePipelineCommand }
@@ -54,11 +54,6 @@ export default function DictionarySettings() {
54
54
  title: t('customers.config.dictionaries.sections.dealStatuses.title', 'Deal statuses'),
55
55
  description: t('customers.config.dictionaries.sections.dealStatuses.description', 'Manage the statuses available for deals.'),
56
56
  },
57
- {
58
- kind: 'pipeline-stages',
59
- title: t('customers.config.dictionaries.sections.pipelineStages.title', 'Pipeline stages'),
60
- description: t('customers.config.dictionaries.sections.pipelineStages.description', 'Define the stages used in your deal pipeline.'),
61
- },
62
57
  {
63
58
  kind: 'job-titles',
64
59
  title: t('customers.config.dictionaries.sections.jobTitles.title', 'Job titles'),