Skip to content

Commit

Permalink
DON-998: add resolver for an single mandate
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorota Hawro committed Dec 13, 2024
1 parent a1b1d3f commit 3244891
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/app/app-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {RegularGivingComponent} from "./regular-giving/regular-giving.component"
import {Person} from "./person.model";
import {firstValueFrom} from "rxjs";
import {MandateComponent} from "./mandate/mandate.component";
import {Mandate} from "./mandate.model";

export const registerPath = 'register';
export const myAccountPath = 'my-account';
Expand Down Expand Up @@ -73,6 +74,16 @@ const LoggedInPersonResolver: ResolveFn<Person | null> = async () => {
return await firstValueFrom(person$);
}

const mandateResolver: ResolveFn<Mandate> = async (route: ActivatedRouteSnapshot) => {
const mandateService = inject(MandateService);
const mandateId = route.paramMap.get('mandateId');
if (!mandateId) {
throw new Error('mandateId param missing in route');
}
const mandate$ = mandateService.getActiveMandate(mandateId);
return await firstValueFrom(mandate$);
}

const routes: Routes = [
{
path: '',
Expand Down Expand Up @@ -283,13 +294,7 @@ if (flags.regularGivingEnabled) {
requireLogin,
],
resolve: {
/**
* need similar method but for one mandate
*/
// mandates: () => {
// inject(MandateService).getActiveMandate(mandateId),
// }

mandate: mandateResolver,
},
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/mandate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class MandateService {
}));
}

getActiveMandate(regularGivingCampaignId: Campaign) {
getActiveMandate(mandateId: string) {
const jwt = this.identityService.getJWT();
const person$ = this.identityService.getLoggedInPerson();

Expand All @@ -42,7 +42,7 @@ export class MandateService {
}

return this.http.get<{ mandate: Mandate }>(
`${environment.donationsApiPrefix}/regular-giving/my-donation-mandate/${regularGivingCampaignId}`,
`${environment.donationsApiPrefix}/regular-giving/my-donation-mandates/${mandateId}`,
getPersonAuthHttpOptions(jwt),
).pipe(map((response) => response.mandate));
}));
Expand Down

0 comments on commit 3244891

Please sign in to comment.