Chore: Updated resolvers from Class to ResolveFn
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { IncentiveResolver } from './incentive-resolver.service';
|
||||
|
||||
describe('IncentiveResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientModule],
|
||||
providers: [IncentiveResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([IncentiveResolver], (service: IncentiveResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { Voucher } from '../core/voucher';
|
||||
import { VoucherService } from '../core/voucher.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class IncentiveResolver {
|
||||
constructor(private ser: VoucherService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<Voucher> {
|
||||
const id = route.paramMap.get('id');
|
||||
if (id === null) {
|
||||
return this.ser.getOfType('Incentive');
|
||||
}
|
||||
return this.ser.get(id, 'Incentive');
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import { ActivatedRouteSnapshot, RouterModule, RouterStateSnapshot, Routes } fro
|
||||
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
|
||||
import { IncentiveResolver } from './incentive-resolver.service';
|
||||
import { IncentiveComponent } from './incentive.component';
|
||||
import { incentiveResolver } from './incentive.resolver';
|
||||
|
||||
const incentiveRoutes: Routes = [
|
||||
{
|
||||
@@ -18,7 +18,7 @@ const incentiveRoutes: Routes = [
|
||||
permission: 'incentive',
|
||||
},
|
||||
resolve: {
|
||||
voucher: (route: ActivatedRouteSnapshot) => inject(IncentiveResolver).resolve(route),
|
||||
voucher: incentiveResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
},
|
||||
@@ -32,7 +32,7 @@ const incentiveRoutes: Routes = [
|
||||
permission: 'incentive',
|
||||
},
|
||||
resolve: {
|
||||
voucher: (route: ActivatedRouteSnapshot) => inject(IncentiveResolver).resolve(route),
|
||||
voucher: incentiveResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
},
|
||||
@@ -41,6 +41,5 @@ const incentiveRoutes: Routes = [
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule.forChild(incentiveRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [IncentiveResolver],
|
||||
})
|
||||
export class IncentiveRoutingModule {}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
|
||||
import { Voucher } from '../core/voucher';
|
||||
|
||||
import { incentiveResolver } from './incentive.resolver';
|
||||
|
||||
describe('incentiveResolver', () => {
|
||||
const executeResolver: ResolveFn<Voucher> = (...resolverParameters) =>
|
||||
TestBed.runInInjectionContext(() => incentiveResolver(...resolverParameters));
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(executeResolver).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
|
||||
import { Voucher } from '../core/voucher';
|
||||
import { VoucherService } from '../core/voucher.service';
|
||||
|
||||
export const incentiveResolver: ResolveFn<Voucher> = (route) => {
|
||||
const id = route.paramMap.get('id');
|
||||
if (id === null) {
|
||||
return inject(VoucherService).getOfType('Incentive');
|
||||
}
|
||||
return inject(VoucherService).get(id, 'Incentive');
|
||||
};
|
||||
Reference in New Issue
Block a user