@idsoftsource/initial-process 4.2.6 → 4.2.7

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.
@@ -8,7 +8,7 @@ import * as i2 from '@angular/router';
8
8
  import { RouterModule, Router } from '@angular/router';
9
9
  import * as i1$1 from 'ngx-bootstrap/modal';
10
10
  import { ModalModule } from 'ngx-bootstrap/modal';
11
- import { catchError, throwError, shareReplay, map, Subject, takeUntil, of, firstValueFrom, tap as tap$1, Subscription, switchMap, finalize, EMPTY } from 'rxjs';
11
+ import { catchError, throwError, shareReplay, map, Subject, takeUntil, of, firstValueFrom, tap as tap$1, Subscription, switchMap, forkJoin, finalize } from 'rxjs';
12
12
  import * as i1 from '@angular/common/http';
13
13
  import { HttpClient, HttpParams, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
14
14
  import * as i9 from '@auth0/auth0-angular';
@@ -35353,6 +35353,9 @@ class UserCoverageAreaService {
35353
35353
  bulkDelete(ids) {
35354
35354
  return this.httpClient.post(`${this.baseUrl}/BulkDelete`, ids);
35355
35355
  }
35356
+ bulkUpdate(models) {
35357
+ return this.httpClient.post(`${this.baseUrl}/BulkUpdate`, models);
35358
+ }
35356
35359
  bulkInsert(models) {
35357
35360
  return this.httpClient.post(`${this.baseUrl}/CreateUserCoverageArea`, models);
35358
35361
  }
@@ -35587,7 +35590,8 @@ class Step2CoverageComponent {
35587
35590
  userId;
35588
35591
  emailId;
35589
35592
  userDetail;
35590
- existingCoverageIds = [];
35593
+ // Saved coverage row id per state, used to decide create / update / delete on save
35594
+ existingIdByState = new Map();
35591
35595
  initialCoverageSnapshot;
35592
35596
  constructor(store, usMapService, userCoverageAreaService, alertService, roleContextService, tokenService) {
35593
35597
  this.store = store;
@@ -35596,7 +35600,6 @@ class Step2CoverageComponent {
35596
35600
  this.alertService = alertService;
35597
35601
  this.roleContextService = roleContextService;
35598
35602
  this.tokenService = tokenService;
35599
- this.usMapService.getUsMapCoordinates().then((x) => this.usCoordinates = x);
35600
35603
  }
35601
35604
  // This step only ever runs inside the initial-setup wizard, so the role picked
35602
35605
  // in role-select (surfaced here as roleData, or mirrored onto the shared
@@ -35611,6 +35614,8 @@ class Step2CoverageComponent {
35611
35614
  this.userId = this.roleContextService?.tempUserContext()?.userId ?? await this.tokenService?.getUserId();
35612
35615
  this.emailId = this.roleContextService?.tempUserContext()?.email ?? await this.tokenService?.getUserEmail();
35613
35616
  this.filteredLocations = [{ label: 'Current Coverage Area', locations: [] }];
35617
+ // Prefill needs the full county list, so load coordinates before coverage
35618
+ this.usCoordinates = await this.usMapService.getUsMapCoordinates();
35614
35619
  this.getCoverage(this.userId);
35615
35620
  }
35616
35621
  toggleMap() {
@@ -35634,24 +35639,27 @@ class Step2CoverageComponent {
35634
35639
  newCoverages.push({
35635
35640
  state,
35636
35641
  isShow: true,
35637
- counties: this.usCoordinates.locations
35638
- .filter((l) => l.state?.trim() === state && l.county)
35639
- .sort((a, b) => a.county.localeCompare(b.county))
35640
- .map((l) => ({
35641
- stateCode: state,
35642
- countyName: l.county,
35643
- latitude: l.latitude,
35644
- longitude: l.longitude,
35645
- fillColor: '#E6E6E6',
35646
- strokeColor: '#fff',
35647
- checked: false
35648
- }))
35642
+ counties: this.buildStateCounties(state)
35649
35643
  });
35650
35644
  }
35651
35645
  }
35652
35646
  this.coverages = newCoverages;
35653
35647
  this.updateFilteredLocations();
35654
35648
  }
35649
+ buildStateCounties(state, savedCounties) {
35650
+ return (this.usCoordinates?.locations ?? [])
35651
+ .filter((l) => l.state?.trim() === state && l.county)
35652
+ .sort((a, b) => a.county.localeCompare(b.county))
35653
+ .map((l) => ({
35654
+ stateCode: state,
35655
+ countyName: l.county,
35656
+ latitude: l.latitude,
35657
+ longitude: l.longitude,
35658
+ fillColor: '#E6E6E6',
35659
+ strokeColor: '#fff',
35660
+ checked: savedCounties?.has(l.county.trim().toLowerCase()) ?? false
35661
+ }));
35662
+ }
35655
35663
  onChangedCounty(event, stateCode, countyName, lat, lng) {
35656
35664
  const checked = event === true || event.target.checked;
35657
35665
  const current = this.filteredLocations.find(x => x.label === 'Current Coverage Area');
@@ -35716,8 +35724,7 @@ class Step2CoverageComponent {
35716
35724
  next: (res) => {
35717
35725
  console.log(res);
35718
35726
  this.prefillCoverage(res.data);
35719
- this.existingCoverageIds = (res.data || []).map((x) => x.id);
35720
- this.syncStateCheckboxes();
35727
+ this.existingIdByState = new Map((res.data || []).map((x) => [x.state, x.id]));
35721
35728
  if (this.selectedStates.length > 0) {
35722
35729
  this.store.selectedStates.set([...this.selectedStates]);
35723
35730
  }
@@ -35725,6 +35732,15 @@ class Step2CoverageComponent {
35725
35732
  error: (err) => console.error(err)
35726
35733
  });
35727
35734
  }
35735
+ // Re-reads saved row ids without touching the user's current selection
35736
+ refreshCoverageIds() {
35737
+ this.userCoverageAreaService.getUserCoverageAreaByUserId(this.userId).subscribe({
35738
+ next: (res) => {
35739
+ this.existingIdByState = new Map((res.data || []).map((x) => [x.state, x.id]));
35740
+ },
35741
+ error: (err) => console.error(err)
35742
+ });
35743
+ }
35728
35744
  syncStateCheckboxes() {
35729
35745
  this.coverages.forEach(state => {
35730
35746
  const checkedCount = state.counties.filter((c) => c.checked).length;
@@ -35744,10 +35760,11 @@ class Step2CoverageComponent {
35744
35760
  }
35745
35761
  this.coverageSave = true;
35746
35762
  const userType = this.resolvedForUser;
35763
+ const targetUserId = this.roleContextService?.tempUserContext()?.userId ?? '';
35747
35764
  const entries = this.coverages.map(s => ({
35748
35765
  forUser: userType,
35749
35766
  targetProviderId: this.providerId,
35750
- targetUserId: this.roleContextService?.tempUserContext()?.userId ?? '',
35767
+ targetUserId,
35751
35768
  providerName: this.providerName,
35752
35769
  userName: this.userDetail?.firstName + ' ' + this.userDetail?.lastName,
35753
35770
  state: s.state,
@@ -35760,44 +35777,61 @@ class Step2CoverageComponent {
35760
35777
  stateName: this.states.find((x) => x.stateCode === s.state)?.stateName,
35761
35778
  stateCode: s.state
35762
35779
  }))
35763
- }))
35764
- .filter(x => x.counties.length > 0);
35765
- if (this.existingCoverageIds.length < 0) {
35766
- this.userCoverageAreaService
35767
- .bulkDelete(this.existingCoverageIds)
35768
- .pipe(finalize(() => (this.coverageSave = false)))
35769
- .subscribe({
35770
- next: () => {
35771
- console.log('Bulk delete success');
35772
- this.initialCoverageSnapshot = JSON.stringify([]);
35773
- this.store.nextStep();
35774
- },
35775
- error: (err) => {
35776
- console.error('Bulk delete failed', err);
35777
- this.alertService.error(err?.error?.message || err?.message || 'Bulk delete failed');
35778
- }
35779
- });
35780
- return;
35780
+ }));
35781
+ const toCreate = [];
35782
+ const toUpdate = [];
35783
+ const toDeleteIds = [];
35784
+ for (const e of entries) {
35785
+ const id = this.existingIdByState.get(e.state);
35786
+ if (e.counties.length === 0) {
35787
+ if (id)
35788
+ toDeleteIds.push(id);
35789
+ }
35790
+ else if (id) {
35791
+ toUpdate.push({ ...e, id, userId: this.userId, providerId: this.providerId });
35792
+ }
35793
+ else {
35794
+ toCreate.push(e);
35795
+ }
35781
35796
  }
35782
- if (entries.length === 0) {
35797
+ // States removed from the dropdown entirely
35798
+ this.existingIdByState.forEach((id, state) => {
35799
+ if (!entries.some(e => e.state === state))
35800
+ toDeleteIds.push(id);
35801
+ });
35802
+ const calls = [];
35803
+ if (toCreate.length)
35804
+ calls.push(this.userCoverageAreaService.bulkInsert(toCreate));
35805
+ if (toUpdate.length)
35806
+ calls.push(this.userCoverageAreaService.bulkUpdate(toUpdate));
35807
+ if (toDeleteIds.length)
35808
+ calls.push(this.userCoverageAreaService.bulkDelete(toDeleteIds));
35809
+ if (!calls.length) {
35783
35810
  this.coverageSave = false;
35784
35811
  this.store.nextStep();
35785
35812
  return;
35786
35813
  }
35787
- this.userCoverageAreaService
35788
- .bulkInsert(entries)
35789
- .pipe(finalize(() => (this.coverageSave = false)), catchError(err => {
35790
- console.error('Coverage save error:', err);
35791
- this.alertService.error(err?.error?.message || err?.message || 'Save failed');
35792
- return EMPTY;
35793
- }))
35794
- .subscribe((result) => {
35795
- if (result?.failed) {
35796
- this.alertService.warning(result?.message || result?.failures?.[0]?.message);
35797
- return;
35814
+ forkJoin(calls)
35815
+ .pipe(finalize(() => (this.coverageSave = false)))
35816
+ .subscribe({
35817
+ next: (results) => {
35818
+ const failed = results.find(r => r?.failed);
35819
+ if (failed) {
35820
+ this.alertService.warning(failed?.message || failed?.failures?.[0]?.message);
35821
+ // Partial success is possible, so refresh ids to avoid duplicate inserts on retry
35822
+ this.refreshCoverageIds();
35823
+ return;
35824
+ }
35825
+ // Refresh ids so newly created rows are updated (not re-inserted) next time
35826
+ this.refreshCoverageIds();
35827
+ this.initialCoverageSnapshot = JSON.stringify(this.buildCoveragePayload());
35828
+ this.store.nextStep();
35829
+ },
35830
+ error: (err) => {
35831
+ console.error('Coverage save error:', err);
35832
+ this.alertService.error(err?.error?.message || err?.message || 'Save failed');
35833
+ this.refreshCoverageIds();
35798
35834
  }
35799
- this.initialCoverageSnapshot = JSON.stringify(entries);
35800
- this.store.nextStep();
35801
35835
  });
35802
35836
  }
35803
35837
  previousStep() {
@@ -35808,20 +35842,15 @@ class Step2CoverageComponent {
35808
35842
  this.selectedStates = [];
35809
35843
  data.forEach(item => {
35810
35844
  this.selectedStates.push(item.state);
35845
+ const savedCounties = new Set((item.counties || []).map((c) => c.county?.trim().toLowerCase()));
35846
+ // Show every county in the state, checking only the saved ones
35811
35847
  this.coverages.push({
35812
35848
  state: item.state,
35813
35849
  isShow: true,
35814
- counties: item.counties.map((c) => ({
35815
- stateCode: item.state,
35816
- countyName: c.county,
35817
- latitude: c.latitude,
35818
- longitude: c.longitude,
35819
- checked: true,
35820
- fillColor: '#002b49',
35821
- strokeColor: '#fff'
35822
- }))
35850
+ counties: this.buildStateCounties(item.state, savedCounties)
35823
35851
  });
35824
35852
  });
35853
+ this.syncStateCheckboxes();
35825
35854
  this.updateFilteredLocations();
35826
35855
  this.initialCoverageSnapshot = JSON.stringify(this.buildCoveragePayload());
35827
35856
  }