@acorex-platform/module-person-core-client 0.0.15

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.
@@ -0,0 +1,148 @@
1
+ import { AXToastService } from '@acorex/components/toast';
2
+ import { AXTranslationService } from '@acorex/core/translation';
3
+ import * as i0 from '@angular/core';
4
+ import { inject, Injectable } from '@angular/core';
5
+ import { AXPEntityDataSelectorService, AXPEntityFormBuilderService, AXPEntityDefinitionRegistryService } from '@acorex-platform/framework-client/layout/entity';
6
+ import { resolveContactAssignmentPartyContext, RootConfig, buildContactAssignmentPersonSnapshot } from '@acorex-platform/module-person-core-client/contracts';
7
+
8
+ //#region ---- Imports ----
9
+ //#endregion
10
+ //#region ---- Command ----
11
+ class AXMContactAssignmentAssignExistingPersonCommand {
12
+ constructor() {
13
+ this.entityDataSelector = inject(AXPEntityDataSelectorService);
14
+ this.entityForm = inject(AXPEntityFormBuilderService);
15
+ this.entityService = inject(AXPEntityDefinitionRegistryService);
16
+ this.toastService = inject(AXToastService);
17
+ this.translationService = inject(AXTranslationService);
18
+ }
19
+ async execute(input) {
20
+ const { entity, data, options, hostContext } = (input?.__context__ ?? input ?? {});
21
+ const processData = {
22
+ ...(hostContext ?? {}),
23
+ ...(data ?? {}),
24
+ ...(options?.process?.data ?? {}),
25
+ };
26
+ const locale = this.translationService.getActiveLang?.() ?? 'en-US';
27
+ const partyContext = resolveContactAssignmentPartyContext(processData, locale);
28
+ if (!partyContext.partyId) {
29
+ return {
30
+ success: false,
31
+ message: {
32
+ text: await this.translationService.translateAsync('@person-core:contact-assignments.messages.missing-party-context'),
33
+ },
34
+ };
35
+ }
36
+ const [moduleName, entityName] = (entity || '').split('.');
37
+ if (!moduleName || !entityName) {
38
+ return {
39
+ success: false,
40
+ message: {
41
+ text: await this.translationService.translateAsync('@general:messages.entity.invalid-identifier'),
42
+ },
43
+ };
44
+ }
45
+ const personEntity = await this.entityService.resolve(RootConfig.module.name, RootConfig.entities.person.name);
46
+ if (!personEntity) {
47
+ return {
48
+ success: false,
49
+ message: {
50
+ text: await this.translationService.translateAsync('@general:messages.entity.invalid-identifier'),
51
+ },
52
+ };
53
+ }
54
+ const selectorTitle = await this.translationService.translateAsync('@person-core:contact-assignments.actions.assign-existing-person.selector-title');
55
+ const selectorResult = await this.entityDataSelector.open({
56
+ entity: personEntity,
57
+ title: selectorTitle,
58
+ allowMultiple: false,
59
+ columns: ['fullName', 'phones', 'emails'],
60
+ });
61
+ if (!selectorResult?.items?.length) {
62
+ return { success: false };
63
+ }
64
+ const selectedPerson = selectorResult.items[0];
65
+ const personId = selectedPerson.id ?? selectedPerson._id;
66
+ const personSnapshot = buildContactAssignmentPersonSnapshot(selectedPerson, personId);
67
+ const formTitle = await this.translationService.translateAsync('@person-core:contact-assignments.actions.assign-existing-person.form-title', { params: { partyTitle: partyContext.partyTitle } });
68
+ const result = await this.entityForm
69
+ .entity(`${moduleName}.${entityName}`)
70
+ .create({
71
+ partyId: partyContext.partyId,
72
+ personId,
73
+ person: personSnapshot,
74
+ })
75
+ .include('roleId', 'notes')
76
+ .title(formTitle)
77
+ .actions((actions) => {
78
+ actions.cancel('@general:actions.cancel.title');
79
+ actions.submit('@general:actions.create.title');
80
+ })
81
+ .onAction(async (dialogRef) => {
82
+ if (dialogRef.action() === 'cancel') {
83
+ return { success: false };
84
+ }
85
+ const contactAssignmentEntity = await this.entityService.resolve(moduleName, entityName);
86
+ const createFn = contactAssignmentEntity?.commands?.create?.execute;
87
+ if (!createFn) {
88
+ const msg = await this.translationService.translateAsync('@general:messages.entity.create-command-unavailable');
89
+ this.toastService.show({
90
+ color: 'danger',
91
+ title: await this.translationService.translateAsync('@general:messages.generic.error.title'),
92
+ content: msg,
93
+ });
94
+ throw new Error(msg);
95
+ }
96
+ dialogRef.setLoading(true);
97
+ try {
98
+ const context = dialogRef.context();
99
+ const createResult = await createFn({
100
+ ...context,
101
+ partyId: partyContext.partyId,
102
+ personId,
103
+ person: personSnapshot,
104
+ });
105
+ if (createResult?.data ?? createResult) {
106
+ return {
107
+ success: true,
108
+ data: createResult?.data ?? createResult,
109
+ message: {
110
+ text: await this.translationService.translateAsync('@general:messages.generic.success.description'),
111
+ },
112
+ };
113
+ }
114
+ return {
115
+ success: false,
116
+ message: {
117
+ text: await this.translationService.translateAsync('@general:messages.entity.create-failed'),
118
+ },
119
+ };
120
+ }
121
+ catch (error) {
122
+ const errorMsg = error instanceof Error
123
+ ? error.message
124
+ : await this.translationService.translateAsync('@general:messages.entity.create-failed');
125
+ this.toastService.show({
126
+ color: 'danger',
127
+ title: await this.translationService.translateAsync('@general:messages.generic.error.title'),
128
+ content: errorMsg,
129
+ });
130
+ throw error;
131
+ }
132
+ finally {
133
+ dialogRef.setLoading(false);
134
+ }
135
+ })
136
+ .show();
137
+ return result;
138
+ }
139
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: AXMContactAssignmentAssignExistingPersonCommand, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
140
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: AXMContactAssignmentAssignExistingPersonCommand, providedIn: 'root' }); }
141
+ }
142
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: AXMContactAssignmentAssignExistingPersonCommand, decorators: [{
143
+ type: Injectable,
144
+ args: [{ providedIn: 'root' }]
145
+ }] });
146
+
147
+ export { AXMContactAssignmentAssignExistingPersonCommand };
148
+ //# sourceMappingURL=acorex-platform-module-person-core-client-assign-existing-person-to-party.command-DO3Z5pPU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acorex-platform-module-person-core-client-assign-existing-person-to-party.command-DO3Z5pPU.mjs","sources":["../../../../libs/modules/person-core/client/src/lib/commands/assign-existing-person-to-party.command.ts"],"sourcesContent":["//#region ---- Imports ----\n\nimport { AXToastService } from '@acorex/components/toast';\nimport { AXTranslationService } from '@acorex/core/translation';\nimport { AXPExecuteCommandResult } from '@acorex-platform/framework-shared/core';\nimport { inject, Injectable } from '@angular/core';\nimport {\n AXPEntityDataSelectorService,\n AXPEntityDefinitionRegistryService,\n AXPEntityFormBuilderService,\n} from '@acorex-platform/framework-client/layout/entity';\n\nimport { RootConfig, buildContactAssignmentPersonSnapshot, resolveContactAssignmentPartyContext } from '@acorex-platform/module-person-core-client/contracts';\nimport { AXPCommand } from '@acorex-platform/framework-shared/runtime';\n\n//#endregion\n\n//#region ---- Command ----\n\n@Injectable({ providedIn: 'root' })\nexport class AXMContactAssignmentAssignExistingPersonCommand implements AXPCommand<any, any> {\n private readonly entityDataSelector = inject(AXPEntityDataSelectorService);\n private readonly entityForm = inject(AXPEntityFormBuilderService);\n private readonly entityService = inject(AXPEntityDefinitionRegistryService);\n private readonly toastService = inject(AXToastService);\n private readonly translationService = inject(AXTranslationService);\n\n async execute(input: any): Promise<AXPExecuteCommandResult<any>> {\n const { entity, data, options, hostContext } = (input?.__context__ ?? input ?? {}) as {\n entity: string;\n data: Record<string, unknown>;\n hostContext?: Record<string, unknown>;\n options: { process?: { data?: Record<string, unknown> } };\n };\n\n const processData = {\n ...(hostContext ?? {}),\n ...(data ?? {}),\n ...(options?.process?.data ?? {}),\n };\n const locale = this.translationService.getActiveLang?.() ?? 'en-US';\n const partyContext = resolveContactAssignmentPartyContext(processData, locale);\n\n if (!partyContext.partyId) {\n return {\n success: false,\n message: {\n text: await this.translationService.translateAsync(\n '@person-core:contact-assignments.messages.missing-party-context',\n ),\n },\n };\n }\n\n const [moduleName, entityName] = (entity || '').split('.');\n if (!moduleName || !entityName) {\n return {\n success: false,\n message: {\n text: await this.translationService.translateAsync('@general:messages.entity.invalid-identifier'),\n },\n };\n }\n\n const personEntity = await this.entityService.resolve(\n RootConfig.module.name,\n RootConfig.entities.person.name,\n );\n if (!personEntity) {\n return {\n success: false,\n message: {\n text: await this.translationService.translateAsync('@general:messages.entity.invalid-identifier'),\n },\n };\n }\n\n const selectorTitle = await this.translationService.translateAsync(\n '@person-core:contact-assignments.actions.assign-existing-person.selector-title',\n );\n const selectorResult = await this.entityDataSelector.open({\n entity: personEntity,\n title: selectorTitle,\n allowMultiple: false,\n columns: ['fullName', 'phones', 'emails'],\n });\n\n if (!selectorResult?.items?.length) {\n return { success: false };\n }\n\n const selectedPerson = selectorResult.items[0];\n const personId = selectedPerson.id ?? selectedPerson._id;\n const personSnapshot = buildContactAssignmentPersonSnapshot(\n selectedPerson as Record<string, unknown>,\n personId as string,\n );\n\n const formTitle = await this.translationService.translateAsync(\n '@person-core:contact-assignments.actions.assign-existing-person.form-title',\n { params: { partyTitle: partyContext.partyTitle } },\n );\n\n const result = await this.entityForm\n .entity(`${moduleName}.${entityName}`)\n .create({\n partyId: partyContext.partyId,\n personId,\n person: personSnapshot,\n })\n .include('roleId', 'notes')\n .title(formTitle)\n .actions((actions) => {\n actions.cancel('@general:actions.cancel.title');\n actions.submit('@general:actions.create.title');\n })\n .onAction<AXPExecuteCommandResult<any>>(async (dialogRef) => {\n if (dialogRef.action() === 'cancel') {\n return { success: false };\n }\n\n const contactAssignmentEntity = await this.entityService.resolve(moduleName, entityName);\n const createFn = contactAssignmentEntity?.commands?.create?.execute as\n | ((payload: unknown) => Promise<AXPExecuteCommandResult<any>>)\n | undefined;\n\n if (!createFn) {\n const msg = await this.translationService.translateAsync(\n '@general:messages.entity.create-command-unavailable',\n );\n this.toastService.show({\n color: 'danger',\n title: await this.translationService.translateAsync('@general:messages.generic.error.title'),\n content: msg,\n });\n throw new Error(msg);\n }\n\n dialogRef.setLoading(true);\n try {\n const context = dialogRef.context();\n const createResult = await createFn({\n ...context,\n partyId: partyContext.partyId,\n personId,\n person: personSnapshot,\n });\n if (createResult?.data ?? createResult) {\n return {\n success: true,\n data: createResult?.data ?? createResult,\n message: {\n text: await this.translationService.translateAsync('@general:messages.generic.success.description'),\n },\n };\n }\n return {\n success: false,\n message: {\n text: await this.translationService.translateAsync('@general:messages.entity.create-failed'),\n },\n };\n } catch (error: unknown) {\n const errorMsg =\n error instanceof Error\n ? error.message\n : await this.translationService.translateAsync('@general:messages.entity.create-failed');\n this.toastService.show({\n color: 'danger',\n title: await this.translationService.translateAsync('@general:messages.generic.error.title'),\n content: errorMsg,\n });\n throw error;\n } finally {\n dialogRef.setLoading(false);\n }\n })\n .show();\n\n return result as unknown as AXPExecuteCommandResult<any>;\n }\n}\n\n//#endregion\n"],"names":[],"mappings":";;;;;;;AAAA;AAeA;AAEA;MAGa,+CAA+C,CAAA;AAD5D,IAAA,WAAA,GAAA;AAEmB,QAAA,IAAA,CAAA,kBAAkB,GAAG,MAAM,CAAC,4BAA4B,CAAC;AACzD,QAAA,IAAA,CAAA,UAAU,GAAG,MAAM,CAAC,2BAA2B,CAAC;AAChD,QAAA,IAAA,CAAA,aAAa,GAAG,MAAM,CAAC,kCAAkC,CAAC;AAC1D,QAAA,IAAA,CAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC;AACrC,QAAA,IAAA,CAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC;AA4JnE,IAAA;IA1JC,MAAM,OAAO,CAAC,KAAU,EAAA;AACtB,QAAA,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,KAAK,EAAE,WAAW,IAAI,KAAK,IAAI,EAAE,CAKhF;AAED,QAAA,MAAM,WAAW,GAAG;AAClB,YAAA,IAAI,WAAW,IAAI,EAAE,CAAC;AACtB,YAAA,IAAI,IAAI,IAAI,EAAE,CAAC;YACf,IAAI,OAAO,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC;SAClC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,aAAa,IAAI,IAAI,OAAO;QACnE,MAAM,YAAY,GAAG,oCAAoC,CAAC,WAAW,EAAE,MAAM,CAAC;AAE9E,QAAA,IAAI,CAAC,YAAY,CAAC,OAAO,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