@@ -31,7 +31,6 @@ import {DsbMitgliedDTO} from '@verwaltung/types/datatransfer/dsb-mitglied-dto.cl
3131import { MannschaftsmitgliedDataProviderService } from '@verwaltung/services/mannschaftsmitglied-data-provider.service' ;
3232import { MannschaftsmitgliedDTO } from '@verwaltung/types/datatransfer/mannschaftsmitglied-dto.class' ;
3333import { VersionedDataObject } from '@shared/data-provider/models/versioned-data-object.interface' ;
34- import { DsbMannschaftDTO } from '@verwaltung/types/datatransfer/dsb-mannschaft-dto.class' ;
3534import { MannschaftsMitgliedDO } from '@verwaltung/types/mannschaftsmitglied-do.class' ;
3635import { environment } from '@environment' ;
3736import {
@@ -59,7 +58,7 @@ const NOTIFICATION_UPDATE_MANNSCHAFT_FAILURE = 'mannschaft_detail_update_failure
5958const NOTIFICATION_DELETE_MITGLIED = 'mannschaft_mitglied_delete' ;
6059const NOTIFICATION_DELETE_MITGLIED_DEADLINE_FAILURE = 'mannschaft_mitglied_delete_deadline_failure' ;
6160const NOTIFICATION_DELETE_MITGLIED_EXISTING_RESULTS_FAILURE = 'mannschaft_mitglied_delete_existing_results_failure' ;
62- const NOTIFICATION_WARING_MANNSCHAFT = 'duplicate_mannschaft' ;
61+ const NOTIFICATION_DUPLICATE_MANNSCHAFT = 'duplicate_mannschaft' ;
6362const NOTIFICATION_NO_LICENSE = 'no_license_found' ;
6463const NOTIFICATION_LIGA_NOT_LOADED = 'liga_not_loaded' ;
6564
@@ -81,16 +80,13 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
8180 public currentVeranstaltung : VeranstaltungDO = new VeranstaltungDO ( ) ;
8281 public ligen : Array < VeranstaltungDO > = [ ] ;
8382 public loadingVeranstaltungen = true ;
84- public mannschaften : Array < DsbMannschaftDO > = [ ] ;
8583 public ActionButtonColors = ActionButtonColors ;
8684
8785
8886 // maps the MannschaftsMitgliedDO with the DSBMitgliedId
8987 private currentMannschaftsMitglied : MannschaftsMitgliedDO = new MannschaftsMitgliedDO ( ) ;
9088 private members : Map < number , MannschaftsMitgliedDO > = new Map < number , MannschaftsMitgliedDO > ( ) ;
91- private duplicateMannschaftsNrNotification : Notification ;
9289 private deleteNotification : Notification ;
93- private duplicateSubscription ;
9490 private deleteSubscription ;
9591 private dsbmitglied : DsbMitgliedDO = new DsbMitgliedDO ( ) ;
9692
@@ -106,7 +102,6 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
106102 constructor ( private mannschaftProvider : DsbMannschaftDataProviderService ,
107103 private vereinProvider : VereinDataProviderService ,
108104 private veranstaltungProvider : VeranstaltungDataProviderService ,
109- private mannschaftsDataProvider : DsbMannschaftDataProviderService ,
110105 private dsbMitgliedProvider : DsbMitgliedDataProviderService ,
111106 private mannschaftMitgliedProvider : MannschaftsmitgliedDataProviderService ,
112107 private downloadService : DownloadButtonResourceProviderService ,
@@ -126,7 +121,6 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
126121
127122 this . loadVereinById ( Number . parseInt ( this . route . snapshot . url [ 1 ] . path , 10 ) ) ;
128123 this . loadVeranstaltungen ( ) ;
129- this . loadMannschaften ( Number . parseInt ( this . route . snapshot . url [ 1 ] . path , 10 ) ) ;
130124
131125 this . notificationService . discardNotification ( ) ;
132126
@@ -143,30 +137,6 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
143137 }
144138 }
145139 } ) ;
146-
147- // This Notification shows up, if a duplicate mannschaftsnummer is detected.
148- // It gets subscribed once in ngOnInit and gets unsubscribed in ngOnDestroy
149- this . duplicateMannschaftsNrNotification = {
150- id : NOTIFICATION_WARING_MANNSCHAFT ,
151- title : 'MANAGEMENT.VEREIN_DETAIL.NOTIFICATION.DUPLICATE.TITLE' ,
152- description : 'MANAGEMENT.VEREIN_DETAIL.NOTIFICATION.DUPLICATE.DESCRIPTION' ,
153- severity : NotificationSeverity . QUESTION ,
154- origin : NotificationOrigin . USER ,
155- type : NotificationType . YES_NO ,
156- userAction : NotificationUserAction . PENDING
157- } ;
158-
159- console . log ( 'subscribe notification' ) ;
160- this . duplicateSubscription = this . notificationService . observeNotification ( NOTIFICATION_WARING_MANNSCHAFT )
161- . subscribe ( ( myNotification ) => {
162- if ( myNotification . userAction === NotificationUserAction . ACCEPTED ) {
163- this . saveLoading = true ;
164- this . saveMannschaft ( ) ;
165- }
166- if ( myNotification . userAction === NotificationUserAction . DECLINED ) {
167- this . saveLoading = false ;
168- }
169- } ) ;
170140 }
171141
172142 /** When a MouseOver-Event is triggered, it will call this inMouseOver-function.
@@ -183,7 +153,6 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
183153
184154
185155 ngOnDestroy ( ) {
186- this . duplicateSubscription . unsubscribe ( ) ;
187156 if ( this . deleteSubscription != null ) {
188157 this . deleteSubscription . unsubscribe ( ) ;
189158 }
@@ -240,7 +209,13 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
240209
241210 this . notificationService . showNotification ( notification ) ;
242211 }
243- } , ( response : BogenligaResponse < DsbMitgliedDO > ) => {
212+ } , ( response : any ) => {
213+ if ( this . isDuplicateMannschaftError ( response ) ) {
214+ this . showDuplicateMannschaftNotification ( ) ;
215+ this . saveLoading = false ;
216+ return ;
217+ }
218+
244219 console . log ( 'Failed: ' + response ) ;
245220 const notification : Notification = {
246221 id : NOTIFICATION_UPDATE_MANNSCHAFT_FAILURE ,
@@ -670,38 +645,6 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
670645 this . notificationService . showNotification ( notification ) ;
671646 }
672647
673- // private checkIfDuplicateMannschaftsNr(mannschaftsNr: Number): Boolean {
674- private loadMannschaften ( vereinsId : number ) {
675- this . mannschaftsDataProvider . findAllByVereinsId ( vereinsId )
676- . then ( ( response : BogenligaResponse < DsbMannschaftDTO [ ] > ) => this . handleLoadMannschaftenSuccess ( response ) )
677- . catch ( ( response : BogenligaResponse < DsbMannschaftDTO [ ] > ) => this . handleLoadMannschaftenFailure ( response ) ) ;
678- }
679-
680- private handleLoadMannschaftenSuccess ( response : BogenligaResponse < DsbMannschaftDTO [ ] > ) : void {
681- this . mannschaften = [ ] ;
682- this . mannschaften = response . payload ;
683- }
684-
685- private existsMannschaftsNummer ( mannschaftsnummer : string ) : boolean {
686-
687- for ( const mannschaft of this . mannschaften ) {
688- if ( parseInt ( mannschaft . nummer , 10 ) === parseInt ( mannschaftsnummer , 10 ) &&
689- ( typeof mannschaft . sportjahr === 'undefined' ) ) {
690- this . notificationService . showNotification ( this . duplicateMannschaftsNrNotification ) ;
691- this . mannschaften = [ ] ;
692- return true ;
693- }
694- }
695- return false ;
696- }
697-
698-
699- private handleLoadMannschaftenFailure ( response : BogenligaResponse < DsbMannschaftDTO [ ] > ) : void {
700- this . mannschaften = [ ] ;
701- this . loading = false ;
702- }
703-
704-
705648 private saveMannschaft ( ) : void {
706649 console . log ( 'Saving mannschaft: ' , this . currentMannschaft ) ;
707650
@@ -731,7 +674,13 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
731674
732675 this . notificationService . showNotification ( notification ) ;
733676 }
734- } , ( response : BogenligaResponse < DsbMitgliedDO > ) => {
677+ } , ( response : any ) => {
678+ if ( this . isDuplicateMannschaftError ( response ) ) {
679+ this . showDuplicateMannschaftNotification ( ) ;
680+ this . saveLoading = false ;
681+ return ;
682+ }
683+
735684 console . log ( response . payload ) ;
736685 console . log ( 'Failed' ) ;
737686 const notification : Notification = {
@@ -756,6 +705,25 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
756705 } ) ;
757706 }
758707
708+ private isDuplicateMannschaftError ( response : any ) : boolean {
709+ return response ?. error ?. status === 409
710+ || response ?. error ?. error ?. errorCode === 'ENTITY_CONFLICT_ERROR' ;
711+ }
712+
713+ private showDuplicateMannschaftNotification ( ) : void {
714+ const notification : Notification = {
715+ id : NOTIFICATION_DUPLICATE_MANNSCHAFT ,
716+ title : 'MANAGEMENT.VEREIN_DETAIL.NOTIFICATION.DUPLICATE.TITLE' ,
717+ description : 'MANAGEMENT.VEREIN_DETAIL.NOTIFICATION.DUPLICATE.DESCRIPTION' ,
718+ severity : NotificationSeverity . ERROR ,
719+ origin : NotificationOrigin . USER ,
720+ type : NotificationType . OK ,
721+ userAction : NotificationUserAction . PENDING
722+ } ;
723+
724+ this . notificationService . showNotification ( notification ) ;
725+ }
726+
759727 public onDownload ( versionedDataObject : VersionedDataObject ) : void {
760728 const downloadUrl = new UriBuilder ( )
761729 . fromPath ( environment . backendBaseUrl )
0 commit comments