1+ import { CrudHttpClient } from "../../../../core/components/requests/crud-http-client" ;
2+ import { environmentDev } from "../../../../../../environments/environment-dev" ;
3+ import { environment } from "../../../../../../environments/environment" ;
4+ import { PacifistaPaymentResponseDTO } from "../../shop/payment/dtos/responses/PacifistaPaymentResponseDTO" ;
5+ import { catchError , Observable , throwError } from "rxjs" ;
6+ import { HttpClient , HttpErrorResponse } from "@angular/common/http" ;
7+
8+ export class PacifistaWebUserLinkService extends CrudHttpClient < PacifistaWebUserLinkService > {
9+
10+ publicUrl : string ;
11+
12+ constructor ( protected http : HttpClient , production : boolean ) {
13+ super (
14+ http ,
15+ production ? environment . pacifistaApiUrl : environmentDev . pacifistaApiUrl ,
16+ "web/user/link"
17+ ) ;
18+ this . publicUrl = super . domain + super . path + '/public' ;
19+ }
20+
21+ linkUser ( minecraftUsername : string ) : Observable < PacifistaWebUserLinkService > {
22+ return this . httpClient . post < PacifistaPaymentResponseDTO > ( this . publicUrl + "/link" , minecraftUsername , { headers : super . getHeaders ( ) } )
23+ . pipe (
24+ catchError ( ( error : HttpErrorResponse ) => {
25+ return throwError ( ( ) => this . buildErrorDto ( error ) ) ;
26+ } )
27+ ) ;
28+ }
29+
30+ unlinkUser ( ) {
31+ return this . httpClient . post ( this . publicUrl + "/unlink" , null , { headers : super . getHeaders ( ) } )
32+ . pipe (
33+ catchError ( ( error : HttpErrorResponse ) => {
34+ return throwError ( ( ) => this . buildErrorDto ( error ) ) ;
35+ } )
36+ ) ;
37+ }
38+
39+ getCurrentUserLink ( ) : Observable < PacifistaPaymentResponseDTO > {
40+ return this . httpClient . get < PacifistaPaymentResponseDTO > ( this . publicUrl + "/linked" , { headers : super . getHeaders ( ) } )
41+ . pipe (
42+ catchError ( ( error : HttpErrorResponse ) => {
43+ return throwError ( ( ) => this . buildErrorDto ( error ) ) ;
44+ } )
45+ ) ;
46+ }
47+
48+ }
0 commit comments