@@ -2,7 +2,7 @@ import { HttpClient, HttpErrorResponse } from '@angular/common/http';
22import { Injectable , inject } from '@angular/core' ;
33import { Observable , catchError , map , of } from 'rxjs' ;
44import { environment } from '../../../environments/environment' ;
5- import { AuthService } from '../auth' ;
5+ import { BYPASS_AUTHORIZATION_CONTEXT } from '../auth' ;
66import {
77 FeedbackArchiveRequestDto ,
88 FeedbackRequestAgainDto ,
@@ -31,72 +31,66 @@ import {
3131export class FeedbackService {
3232 private httpClient = inject ( HttpClient ) ;
3333
34- private authService = inject ( AuthService ) ;
35-
3634 private apiBaseUrl = environment . apiBaseUrl ;
3735
3836 // ----- Request feedback and give requested feedback -----
3937
4038 // The cookie `app-locale-id` must be provided (using the `withCredentials` option)
4139 // so that the server can determine the language to be used in the emails.
4240 request ( dto : FeedbackRequestDto ) : Observable < { error : boolean ; message ?: 'invalid_email' } > {
43- return this . authService . withBearerIdToken ( ( headers ) =>
44- this . httpClient . post < void > ( `${ this . apiBaseUrl } /feedback/request` , dto , { headers, withCredentials : true } ) . pipe (
45- map ( ( ) => ( { error : false } ) ) ,
46- catchError ( ( { error } : HttpErrorResponse ) => of ( { error : true , message : error ?. message } ) ) ,
47- ) ,
41+ return this . httpClient . post < void > ( `${ this . apiBaseUrl } /feedback/request` , dto , { withCredentials : true } ) . pipe (
42+ map ( ( ) => ( { error : false } ) ) ,
43+ catchError ( ( { error } : HttpErrorResponse ) => of ( { error : true , message : error ?. message } ) ) ,
4844 ) ;
4945 }
5046
5147 // The cookie `app-locale-id` must be provided (using the `withCredentials` option)
5248 // so that the server can determine the language to be used in the emails.
5349 requestAgain ( feedbackId : string ) {
54- return this . authService . withBearerIdToken ( ( headers ) =>
55- this . httpClient . post < void > (
56- `${ this . apiBaseUrl } /feedback/request-again` ,
57- { feedbackId } satisfies FeedbackRequestAgainDto ,
58- { headers, withCredentials : true } ,
59- ) ,
50+ return this . httpClient . post < void > (
51+ `${ this . apiBaseUrl } /feedback/request-again` ,
52+ { feedbackId } satisfies FeedbackRequestAgainDto ,
53+ { withCredentials : true } ,
6054 ) ;
6155 }
6256
6357 archiveRequest ( feedbackId : string ) : Observable < { error : boolean ; message ?: 'Forbidden' } > {
64- return this . authService . withBearerIdToken ( ( headers ) =>
65- this . httpClient
66- . post < void > ( `${ this . apiBaseUrl } /feedback/archive-request` , { feedbackId } satisfies FeedbackArchiveRequestDto , {
67- headers,
68- } )
69- . pipe (
70- map ( ( ) => ( { error : false } ) ) ,
71- catchError ( ( { error } : HttpErrorResponse ) => {
72- const isForbidden = ( error ?. message as 'Bad Request' | 'Forbidden' ) === 'Forbidden' ;
73- return of ( { error : true , message : isForbidden ? ( 'Forbidden' as const ) : undefined } ) ;
74- } ) ,
75- ) ,
76- ) ;
58+ return this . httpClient
59+ . post < void > ( `${ this . apiBaseUrl } /feedback/archive-request` , { feedbackId } satisfies FeedbackArchiveRequestDto )
60+ . pipe (
61+ map ( ( ) => ( { error : false } ) ) ,
62+ catchError ( ( { error } : HttpErrorResponse ) => {
63+ const isForbidden = ( error ?. message as 'Bad Request' | 'Forbidden' ) === 'Forbidden' ;
64+ return of ( { error : true , message : isForbidden ? ( 'Forbidden' as const ) : undefined } ) ;
65+ } ) ,
66+ ) ;
7767 }
7868
7969 checkRequest ( token : string ) {
8070 return this . httpClient . get < { request : FeedbackRequest ; draft ?: FeedbackRequestDraft } > (
8171 `${ this . apiBaseUrl } /feedback/check-request/${ token } ` ,
72+ { context : BYPASS_AUTHORIZATION_CONTEXT } ,
8273 ) ;
8374 }
8475
8576 revealRequestTokenId ( feedbackId : string ) {
86- return this . authService . withBearerIdToken ( ( headers ) =>
87- this . httpClient . get < TokenObject > ( `${ this . apiBaseUrl } /feedback/reveal-request-token/${ feedbackId } ` , { headers } ) ,
88- ) ;
77+ return this . httpClient . get < TokenObject > ( `${ this . apiBaseUrl } /feedback/reveal-request-token/${ feedbackId } ` ) ;
8978 }
9079
9180 giveRequestedDraft ( dto : GiveRequestedFeedbackDto ) {
92- return this . httpClient . post < void > ( `${ this . apiBaseUrl } /feedback/give-requested/draft` , dto ) ;
81+ return this . httpClient . post < void > ( `${ this . apiBaseUrl } /feedback/give-requested/draft` , dto , {
82+ context : BYPASS_AUTHORIZATION_CONTEXT ,
83+ } ) ;
9384 }
9485
9586 // The cookie `app-locale-id` must be provided (using the `withCredentials` option)
9687 // so that the server can determine the language to be used in the emails.
9788 giveRequested ( dto : GiveRequestedFeedbackDto ) {
9889 return this . httpClient
99- . post < void > ( `${ this . apiBaseUrl } /feedback/give-requested` , dto , { withCredentials : true } )
90+ . post < void > ( `${ this . apiBaseUrl } /feedback/give-requested` , dto , {
91+ context : BYPASS_AUTHORIZATION_CONTEXT ,
92+ withCredentials : true ,
93+ } )
10094 . pipe (
10195 map ( ( ) => true ) ,
10296 catchError ( ( ) => of ( false ) ) ,
@@ -107,30 +101,24 @@ export class FeedbackService {
107101
108102 // Note: use the `FeedbackDraftService` wrapper to access this method
109103 getDraftList ( ) {
110- return this . authService . withBearerIdToken ( ( headers ) =>
111- this . httpClient . get < FeedbackDraft [ ] > ( `${ this . apiBaseUrl } /feedback/give/draft` , { headers } ) ,
112- ) ;
104+ return this . httpClient . get < FeedbackDraft [ ] > ( `${ this . apiBaseUrl } /feedback/give/draft` ) ;
113105 }
114106
115107 // Note: use the `FeedbackDraftService` wrapper to access this method
116108 giveDraft ( dto : GiveFeedbackDto ) {
117- return this . authService . withBearerIdToken ( ( headers ) =>
118- this . httpClient . post < void > ( `${ this . apiBaseUrl } /feedback/give/draft` , dto , { headers } ) ,
119- ) ;
109+ return this . httpClient . post < void > ( `${ this . apiBaseUrl } /feedback/give/draft` , dto ) ;
120110 }
121111
122112 // The cookie `app-locale-id` must be provided (using the `withCredentials` option)
123113 // so that the server can determine the language to be used in the emails.
124114 give ( dto : GiveFeedbackDto ) : Observable < IdObject | { id : undefined ; error : true ; message ?: 'invalid_email' } > {
125- return this . authService . withBearerIdToken ( ( headers ) =>
126- this . httpClient . post < IdObject > ( `${ this . apiBaseUrl } /feedback/give` , dto , { headers, withCredentials : true } ) . pipe (
127- catchError ( ( { error } : HttpErrorResponse ) =>
128- of ( {
129- id : undefined ,
130- error : true as const ,
131- message : error . message ,
132- } ) ,
133- ) ,
115+ return this . httpClient . post < IdObject > ( `${ this . apiBaseUrl } /feedback/give` , dto , { withCredentials : true } ) . pipe (
116+ catchError ( ( { error } : HttpErrorResponse ) =>
117+ of ( {
118+ id : undefined ,
119+ error : true as const ,
120+ message : error . message ,
121+ } ) ,
134122 ) ,
135123 ) ;
136124 }
@@ -139,50 +127,34 @@ export class FeedbackService {
139127
140128 // Note: use the `FeedbackDraftService` wrapper to access this method
141129 deleteDraft ( type : FeedbackDraftType | FeedbackRequestDraftType , receiverEmailOrToken : string ) {
142- return this . authService . withBearerIdToken ( ( headers ) =>
143- this . httpClient . delete < void > ( `${ this . apiBaseUrl } /feedback/draft/${ type } /${ receiverEmailOrToken } ` , { headers } ) ,
144- ) ;
130+ return this . httpClient . delete < void > ( `${ this . apiBaseUrl } /feedback/draft/${ type } /${ receiverEmailOrToken } ` ) ;
145131 }
146132
147133 // ----- Archive feedback (with status "done") -----
148134
149135 archive ( feedbackId : string ) {
150- return this . authService . withBearerIdToken ( ( headers ) =>
151- this . httpClient . post < void > ( `${ this . apiBaseUrl } /feedback/archive/${ feedbackId } ` , { } , { headers } ) ,
152- ) ;
136+ return this . httpClient . post < void > ( `${ this . apiBaseUrl } /feedback/archive/${ feedbackId } ` , { } ) ;
153137 }
154138
155139 // ----- View feedbacks (requested and given) -----
156140
157141 getListMap ( types : FeedbackListType [ ] ) {
158- return this . authService . withBearerIdToken ( ( headers ) =>
159- this . httpClient . get < FeedbackListMap > ( `${ this . apiBaseUrl } /feedback/list-map` , {
160- headers,
161- params : { types : types . join ( ) } ,
162- } ) ,
163- ) ;
142+ return this . httpClient . get < FeedbackListMap > ( `${ this . apiBaseUrl } /feedback/list-map` , {
143+ params : { types : types . join ( ) } ,
144+ } ) ;
164145 }
165146
166147 getDocument ( id : string ) {
167- return this . authService . withBearerIdToken ( ( headers ) =>
168- this . httpClient . get < Feedback | FeedbackRequest | null > ( `${ this . apiBaseUrl } /feedback/document/${ id } ` , { headers } ) ,
169- ) ;
148+ return this . httpClient . get < Feedback | FeedbackRequest | null > ( `${ this . apiBaseUrl } /feedback/document/${ id } ` ) ;
170149 }
171150
172151 getSharedFeedbackList ( managedEmail : string ) {
173- return this . authService . withBearerIdToken ( ( headers ) =>
174- this . httpClient . get < ( FeedbackItem | FeedbackRequestItem ) [ ] > (
175- `${ this . apiBaseUrl } /feedback/shared/list/${ managedEmail } ` ,
176- { headers } ,
177- ) ,
152+ return this . httpClient . get < ( FeedbackItem | FeedbackRequestItem ) [ ] > (
153+ `${ this . apiBaseUrl } /feedback/shared/list/${ managedEmail } ` ,
178154 ) ;
179155 }
180156
181157 getSharedFeedbackDocument ( id : string ) {
182- return this . authService . withBearerIdToken ( ( headers ) =>
183- this . httpClient . get < Feedback | FeedbackRequest > ( `${ this . apiBaseUrl } /feedback/shared/document/${ id } ` , {
184- headers,
185- } ) ,
186- ) ;
158+ return this . httpClient . get < Feedback | FeedbackRequest > ( `${ this . apiBaseUrl } /feedback/shared/document/${ id } ` ) ;
187159 }
188160}
0 commit comments