@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.
- package/dist/generated/entities/customer_deal/index.js +4 -0
- package/dist/generated/entities/customer_deal/index.js.map +2 -2
- package/dist/generated/entities/customer_pipeline/index.js +17 -0
- package/dist/generated/entities/customer_pipeline/index.js.map +7 -0
- package/dist/generated/entities/customer_pipeline_stage/index.js +19 -0
- package/dist/generated/entities/customer_pipeline_stage/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +2 -0
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +4 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/customers/acl.js +2 -0
- package/dist/modules/customers/acl.js.map +2 -2
- package/dist/modules/customers/api/deals/[id]/route.js +4 -0
- package/dist/modules/customers/api/deals/[id]/route.js.map +2 -2
- package/dist/modules/customers/api/deals/route.js +12 -0
- package/dist/modules/customers/api/deals/route.js.map +2 -2
- package/dist/modules/customers/api/dictionaries/[kind]/route.js +20 -1
- package/dist/modules/customers/api/dictionaries/[kind]/route.js.map +2 -2
- package/dist/modules/customers/api/pipeline-stages/reorder/route.js +69 -0
- package/dist/modules/customers/api/pipeline-stages/reorder/route.js.map +7 -0
- package/dist/modules/customers/api/pipeline-stages/route.js +275 -0
- package/dist/modules/customers/api/pipeline-stages/route.js.map +7 -0
- package/dist/modules/customers/api/pipelines/route.js +245 -0
- package/dist/modules/customers/api/pipelines/route.js.map +7 -0
- package/dist/modules/customers/backend/config/customers/page.js +2 -0
- package/dist/modules/customers/backend/config/customers/page.js.map +2 -2
- package/dist/modules/customers/backend/config/customers/pipeline-stages/page.js +439 -0
- package/dist/modules/customers/backend/config/customers/pipeline-stages/page.js.map +7 -0
- package/dist/modules/customers/backend/config/customers/pipeline-stages/page.meta.js +17 -0
- package/dist/modules/customers/backend/config/customers/pipeline-stages/page.meta.js.map +7 -0
- package/dist/modules/customers/backend/customers/deals/[id]/page.js +19 -1
- package/dist/modules/customers/backend/customers/deals/[id]/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/page.js +35 -1
- package/dist/modules/customers/backend/customers/deals/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/pipeline/page.js +102 -74
- package/dist/modules/customers/backend/customers/deals/pipeline/page.js.map +2 -2
- package/dist/modules/customers/cli.js +28 -2
- package/dist/modules/customers/cli.js.map +2 -2
- package/dist/modules/customers/commands/deals.js +34 -2
- package/dist/modules/customers/commands/deals.js.map +2 -2
- package/dist/modules/customers/commands/index.js +2 -0
- package/dist/modules/customers/commands/index.js.map +2 -2
- package/dist/modules/customers/commands/pipeline-stages.js +126 -0
- package/dist/modules/customers/commands/pipeline-stages.js.map +7 -0
- package/dist/modules/customers/commands/pipelines.js +87 -0
- package/dist/modules/customers/commands/pipelines.js.map +7 -0
- package/dist/modules/customers/components/DictionarySettings.js +0 -5
- package/dist/modules/customers/components/DictionarySettings.js.map +2 -2
- package/dist/modules/customers/components/PipelineSettings.js +474 -0
- package/dist/modules/customers/components/PipelineSettings.js.map +7 -0
- package/dist/modules/customers/components/detail/DealForm.js +84 -12
- package/dist/modules/customers/components/detail/DealForm.js.map +2 -2
- package/dist/modules/customers/data/entities.js +78 -0
- package/dist/modules/customers/data/entities.js.map +2 -2
- package/dist/modules/customers/data/validators.js +44 -0
- package/dist/modules/customers/data/validators.js.map +2 -2
- package/dist/modules/customers/migrations/Migration20260218191730.js +77 -0
- package/dist/modules/customers/migrations/Migration20260218191730.js.map +7 -0
- package/dist/modules/customers/setup.js +7 -3
- package/dist/modules/customers/setup.js.map +2 -2
- package/dist/modules/translations/api/[entityType]/[entityId]/route.js +46 -44
- package/dist/modules/translations/api/[entityType]/[entityId]/route.js.map +2 -2
- package/dist/modules/translations/api/context.js +10 -1
- package/dist/modules/translations/api/context.js.map +2 -2
- package/dist/modules/translations/commands/index.js +2 -0
- package/dist/modules/translations/commands/index.js.map +7 -0
- package/dist/modules/translations/commands/translations.js +160 -0
- package/dist/modules/translations/commands/translations.js.map +7 -0
- package/dist/modules/translations/index.js +1 -0
- package/dist/modules/translations/index.js.map +2 -2
- package/dist/modules/workflows/migrations/Migration20260222205305.js +14 -0
- package/dist/modules/workflows/migrations/Migration20260222205305.js.map +7 -0
- package/generated/entities/customer_deal/index.ts +2 -0
- package/generated/entities/customer_pipeline/index.ts +7 -0
- package/generated/entities/customer_pipeline_stage/index.ts +8 -0
- package/generated/entities.ids.generated.ts +2 -0
- package/generated/entity-fields-registry.ts +4 -0
- package/package.json +2 -2
- package/src/modules/customers/acl.ts +2 -0
- package/src/modules/customers/api/deals/[id]/route.ts +4 -0
- package/src/modules/customers/api/deals/route.ts +12 -0
- package/src/modules/customers/api/dictionaries/[kind]/route.ts +21 -1
- package/src/modules/customers/api/pipeline-stages/reorder/route.ts +71 -0
- package/src/modules/customers/api/pipeline-stages/route.ts +296 -0
- package/src/modules/customers/api/pipelines/route.ts +261 -0
- package/src/modules/customers/backend/config/customers/page.tsx +2 -0
- package/src/modules/customers/backend/config/customers/pipeline-stages/page.meta.ts +13 -0
- package/src/modules/customers/backend/config/customers/pipeline-stages/page.tsx +512 -0
- package/src/modules/customers/backend/customers/deals/[id]/page.tsx +21 -1
- package/src/modules/customers/backend/customers/deals/page.tsx +33 -1
- package/src/modules/customers/backend/customers/deals/pipeline/page.tsx +119 -79
- package/src/modules/customers/cli.ts +29 -1
- package/src/modules/customers/commands/deals.ts +44 -1
- package/src/modules/customers/commands/index.ts +2 -0
- package/src/modules/customers/commands/pipeline-stages.ts +156 -0
- package/src/modules/customers/commands/pipelines.ts +105 -0
- package/src/modules/customers/components/DictionarySettings.tsx +0 -5
- package/src/modules/customers/components/PipelineSettings.tsx +570 -0
- package/src/modules/customers/components/detail/DealForm.tsx +89 -11
- package/src/modules/customers/data/entities.ts +64 -0
- package/src/modules/customers/data/validators.ts +57 -0
- package/src/modules/customers/i18n/de.json +4 -0
- package/src/modules/customers/i18n/en.json +4 -0
- package/src/modules/customers/i18n/es.json +4 -0
- package/src/modules/customers/i18n/pl.json +5 -1
- package/src/modules/customers/migrations/Migration20260218191730.ts +84 -0
- package/src/modules/customers/setup.ts +5 -1
- package/src/modules/translations/api/[entityType]/[entityId]/route.ts +65 -60
- package/src/modules/translations/api/context.ts +12 -0
- package/src/modules/translations/commands/index.ts +1 -0
- package/src/modules/translations/commands/translations.ts +253 -0
- package/src/modules/translations/index.ts +1 -0
- 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'),
|