@idsoftsource/initial-process 3.3.1 → 3.3.3

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.
@@ -3389,6 +3389,8 @@ class PreviewComponent {
3389
3389
  try {
3390
3390
  const payload = {
3391
3391
  forUser: ForUser.ForProducer,
3392
+ targetUserId: this.effectiveTargetUserId,
3393
+ targetProviderId: this.effectiveTargetProviderId,
3392
3394
  professionName: name,
3393
3395
  notes: '',
3394
3396
  year: null,
@@ -3440,15 +3442,68 @@ class PreviewComponent {
3440
3442
  professionTypeServerIds = {};
3441
3443
  professionSavedSnapshots = {};
3442
3444
  professionSelections = {};
3445
+ normalizeProfessionTypeId(id) {
3446
+ if (id == null)
3447
+ return null;
3448
+ const normalized = String(id).trim();
3449
+ return normalized || null;
3450
+ }
3451
+ resolveProfessionTypeIdFromSavedItem(item) {
3452
+ const fromProfessionId = this.normalizeProfessionTypeId(item?.professionId);
3453
+ if (fromProfessionId && this.professionTypes.some((p) => this.normalizeProfessionTypeId(p.id) === fromProfessionId)) {
3454
+ return fromProfessionId;
3455
+ }
3456
+ const name = (item?.professionName || '').trim().toLowerCase();
3457
+ if (!name)
3458
+ return fromProfessionId;
3459
+ const match = this.professionTypes.find((p) => (p.professionName || '').trim().toLowerCase() === name);
3460
+ return this.normalizeProfessionTypeId(match?.id) ?? fromProfessionId;
3461
+ }
3462
+ isProfessionTypeSaved(id) {
3463
+ const typeId = this.normalizeProfessionTypeId(id);
3464
+ return !!typeId && this.savedProfessionTypeIds.has(typeId);
3465
+ }
3466
+ markProfessionSelectionSaved(id, serverRecordId) {
3467
+ const typeId = this.normalizeProfessionTypeId(id);
3468
+ if (!typeId)
3469
+ return;
3470
+ this.savedProfessionTypeIds.add(typeId);
3471
+ const sel = this.professionSelections[id] ?? this.professionSelections[typeId];
3472
+ if (sel) {
3473
+ this.professionSavedSnapshots[typeId] = {
3474
+ starRating: sel.starRating ?? 0,
3475
+ year: sel.year ?? null,
3476
+ profileVisibility: !!sel.profileVisibility,
3477
+ notes: sel.notes ?? '',
3478
+ };
3479
+ }
3480
+ if (serverRecordId) {
3481
+ this.professionTypeServerIds[typeId] = serverRecordId;
3482
+ }
3483
+ }
3484
+ markProfessionsCreated(newIds, res) {
3485
+ const createdRecords = Array.isArray(res)
3486
+ ? res
3487
+ : (Array.isArray(res?.data) ? res.data : (Array.isArray(res?.value) ? res.value : null));
3488
+ newIds.forEach((id, index) => {
3489
+ if (this.isManualProfessionType(id))
3490
+ return;
3491
+ const serverRecordId = this.getEntityId(createdRecords?.[index]) ?? (index === 0 ? this.getCreatedId(res) : null);
3492
+ this.markProfessionSelectionSaved(id, serverRecordId);
3493
+ });
3494
+ }
3443
3495
  applySavedProfessionsToTable() {
3444
3496
  this.professionTypeServerIds = {};
3445
3497
  this.professionSavedSnapshots = {};
3498
+ const savedTypeIds = new Set();
3446
3499
  (this.userProfessionOptions ?? []).forEach((item) => {
3447
- const typeId = item?.professionId;
3500
+ const typeId = this.resolveProfessionTypeIdFromSavedItem(item);
3448
3501
  if (!typeId)
3449
3502
  return;
3450
- this.savedProfessionTypeIds.add(typeId);
3451
- this.professionTypeServerIds[typeId] = item.id;
3503
+ savedTypeIds.add(typeId);
3504
+ const serverId = this.getEntityId(item);
3505
+ if (serverId)
3506
+ this.professionTypeServerIds[typeId] = serverId;
3452
3507
  const snapshot = {
3453
3508
  starRating: item.starRating ?? 0,
3454
3509
  year: item.year ?? null,
@@ -3458,10 +3513,14 @@ class PreviewComponent {
3458
3513
  this.professionSavedSnapshots[typeId] = snapshot;
3459
3514
  this.professionSelections[typeId] = { selected: true, ...snapshot };
3460
3515
  });
3516
+ this.savedProfessionTypeIds = savedTypeIds;
3461
3517
  }
3462
3518
  hasProfessionRowChanged(id) {
3463
- const snap = this.professionSavedSnapshots[id];
3464
- const sel = this.professionSelections[id];
3519
+ const typeId = this.normalizeProfessionTypeId(id);
3520
+ if (!typeId)
3521
+ return false;
3522
+ const snap = this.professionSavedSnapshots[typeId];
3523
+ const sel = this.professionSelections[id] ?? this.professionSelections[typeId];
3465
3524
  if (!snap || !sel)
3466
3525
  return false;
3467
3526
  return snap.starRating !== (sel.starRating ?? 0)
@@ -3507,8 +3566,8 @@ class PreviewComponent {
3507
3566
  }
3508
3567
  get professionSubmitLabel() {
3509
3568
  const selectedIds = Object.keys(this.professionSelections).filter(id => this.professionSelections[id].selected);
3510
- const hasNew = selectedIds.some(id => !this.savedProfessionTypeIds.has(id) && this.isManualRowReady(id));
3511
- const hasChanged = selectedIds.some(id => this.savedProfessionTypeIds.has(id) && this.hasProfessionRowChanged(id));
3569
+ const hasNew = selectedIds.some(id => !this.isProfessionTypeSaved(id) && this.isManualRowReady(id));
3570
+ const hasChanged = selectedIds.some(id => this.isProfessionTypeSaved(id) && this.hasProfessionRowChanged(id));
3512
3571
  if (hasNew && hasChanged)
3513
3572
  return 'Save Changes';
3514
3573
  if (hasChanged)
@@ -3516,14 +3575,14 @@ class PreviewComponent {
3516
3575
  return 'Save Profession';
3517
3576
  }
3518
3577
  isProfessionSaved(id) {
3519
- return this.savedProfessionTypeIds.has(id);
3578
+ return this.isProfessionTypeSaved(id);
3520
3579
  }
3521
3580
  get selectedProfessionCount() {
3522
3581
  return Object.keys(this.professionSelections).filter(id => {
3523
3582
  const sel = this.professionSelections[id];
3524
3583
  if (!sel.selected)
3525
3584
  return false;
3526
- if (!this.savedProfessionTypeIds.has(id))
3585
+ if (!this.isProfessionTypeSaved(id))
3527
3586
  return this.isManualRowReady(id);
3528
3587
  return this.hasProfessionRowChanged(id);
3529
3588
  }).length;
@@ -3584,8 +3643,10 @@ class PreviewComponent {
3584
3643
  buildNewProfessionCreatePayload(id) {
3585
3644
  const profType = this.professionTypes.find((p) => p.id === id) || {};
3586
3645
  const sel = this.professionSelections[id];
3587
- return {
3646
+ const payload = {
3588
3647
  forUser: ForUser.ForProducer,
3648
+ targetUserId: this.effectiveTargetUserId,
3649
+ targetProviderId: this.effectiveTargetProviderId,
3589
3650
  professionName: profType.professionName,
3590
3651
  notes: sel.notes ?? '',
3591
3652
  year: sel.year ?? null,
@@ -3595,11 +3656,15 @@ class PreviewComponent {
3595
3656
  professionGroup: profType.professionGroup ?? '',
3596
3657
  residentialCommercial: profType.residentialCommercial ?? '',
3597
3658
  };
3659
+ if (!profType.isManual) {
3660
+ payload.professionId = id;
3661
+ }
3662
+ return payload;
3598
3663
  }
3599
3664
  async submitProfessions() {
3600
3665
  const allSelectedIds = Object.keys(this.professionSelections).filter(id => this.professionSelections[id].selected);
3601
- const newIds = allSelectedIds.filter(id => !this.savedProfessionTypeIds.has(id) && this.isManualRowReady(id));
3602
- const changedSavedIds = allSelectedIds.filter(id => this.savedProfessionTypeIds.has(id) && this.hasProfessionRowChanged(id));
3666
+ const newIds = allSelectedIds.filter(id => !this.isProfessionTypeSaved(id) && this.isManualRowReady(id));
3667
+ const changedSavedIds = allSelectedIds.filter(id => this.isProfessionTypeSaved(id) && this.hasProfessionRowChanged(id));
3603
3668
  if ((!newIds.length && !changedSavedIds.length) || this.isSavingProfessionsTable)
3604
3669
  return;
3605
3670
  this.isSavingProfessionsTable = true;
@@ -3611,9 +3676,17 @@ class PreviewComponent {
3611
3676
  console.error('Unable to create user profession(s)', res.failures);
3612
3677
  return;
3613
3678
  }
3679
+ this.markProfessionsCreated(newIds, res);
3680
+ const manualIds = newIds.filter(id => this.isManualProfessionType(id));
3681
+ if (manualIds.length) {
3682
+ const manualIdSet = new Set(manualIds);
3683
+ this.professionTypes = this.professionTypes.filter((p) => !manualIdSet.has(p.id));
3684
+ manualIds.forEach(id => delete this.professionSelections[id]);
3685
+ }
3614
3686
  }
3615
3687
  for (const id of changedSavedIds) {
3616
- const payload = { ...this.buildProfessionPayload(id), id: this.professionTypeServerIds[id] };
3688
+ const typeId = this.normalizeProfessionTypeId(id);
3689
+ const payload = { ...this.buildProfessionPayload(id), id: typeId ? this.professionTypeServerIds[typeId] : undefined };
3617
3690
  const res = await firstValueFrom(this.userProfessionService.updateUserProfession(payload));
3618
3691
  if (res?.failed) {
3619
3692
  console.error('Unable to update user profession', res.failures);
@@ -4210,6 +4283,7 @@ class PreviewComponent {
4210
4283
  pageSize: 100,
4211
4284
  filter: includeForUser ? `forUser=${ForUser.ForProducer}` : ``,
4212
4285
  targetUserId: this.effectiveTargetUserId,
4286
+ targetProviderId: this.effectiveTargetProviderId ?? undefined,
4213
4287
  orderBy,
4214
4288
  };
4215
4289
  }
@@ -4218,6 +4292,7 @@ class PreviewComponent {
4218
4292
  page: 1,
4219
4293
  pageSize: 100,
4220
4294
  targetUserId: this.effectiveTargetUserId,
4295
+ targetProviderId: this.effectiveTargetProviderId ?? undefined,
4221
4296
  orderBy,
4222
4297
  };
4223
4298
  }