Chore: Updated resolvers from Class to ResolveFn
This commit is contained in:
1 parent
6f433ef203
commit
6e3c429db3
255 files changed
+1737
-2155
No files matched your search
@@ -1,18 +0,0 @@
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
import { CostCentreListResolver } from './cost-centre-list-resolver.service';
|
||||
|
||||
describe('CostCentreListResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientModule, RouterTestingModule],
|
||||
providers: [CostCentreListResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([CostCentreListResolver], (service: CostCentreListResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { CostCentre } from '../core/cost-centre';
|
||||
|
||||
import { CostCentreService } from './cost-centre.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CostCentreListResolver {
|
||||
constructor(private ser: CostCentreService) {}
|
||||
|
||||
resolve(): Observable<CostCentre[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
|
||||
import { CostCentre } from '../core/cost-centre';
|
||||
|
||||
import { costCentreListResolver } from './cost-centre-list.resolver';
|
||||
|
||||
describe('costCentreListResolver', () => {
|
||||
const executeResolver: ResolveFn<CostCentre[]> = (...resolverParameters) =>
|
||||
TestBed.runInInjectionContext(() => costCentreListResolver(...resolverParameters));
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(executeResolver).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
|
||||
import { CostCentre } from '../core/cost-centre';
|
||||
|
||||
import { CostCentreService } from './cost-centre.service';
|
||||
|
||||
export const costCentreListResolver: ResolveFn<CostCentre[]> = () => {
|
||||
return inject(CostCentreService).list();
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
import { CostCentreResolver } from './cost-centre-resolver.service';
|
||||
|
||||
describe('CostCentreResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientModule, RouterTestingModule],
|
||||
providers: [CostCentreResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([CostCentreResolver], (service: CostCentreResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@@ -1,19 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { CostCentre } from '../core/cost-centre';
|
||||
|
||||
import { CostCentreService } from './cost-centre.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CostCentreResolver {
|
||||
constructor(private ser: CostCentreService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<CostCentre> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import { AuthGuard } from '../auth/auth-guard.service';
|
||||
|
||||
import { CostCentreDetailComponent } from './cost-centre-detail/cost-centre-detail.component';
|
||||
import { CostCentreListComponent } from './cost-centre-list/cost-centre-list.component';
|
||||
import { CostCentreListResolver } from './cost-centre-list-resolver.service';
|
||||
import { CostCentreResolver } from './cost-centre-resolver.service';
|
||||
import { costCentreListResolver } from './cost-centre-list.resolver';
|
||||
import { costCentreResolver } from './cost-centre.resolver';
|
||||
|
||||
const costCentreRoutes: Routes = [
|
||||
{
|
||||
@@ -20,7 +20,7 @@ const costCentreRoutes: Routes = [
|
||||
permission: 'Cost Centres',
|
||||
},
|
||||
resolve: {
|
||||
list: () => inject(CostCentreListResolver).resolve(),
|
||||
list: costCentreListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -33,7 +33,7 @@ const costCentreRoutes: Routes = [
|
||||
permission: 'Cost Centres',
|
||||
},
|
||||
resolve: {
|
||||
item: (route: ActivatedRouteSnapshot) => inject(CostCentreResolver).resolve(route),
|
||||
item: costCentreResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -46,7 +46,7 @@ const costCentreRoutes: Routes = [
|
||||
permission: 'Cost Centres',
|
||||
},
|
||||
resolve: {
|
||||
item: (route: ActivatedRouteSnapshot) => inject(CostCentreResolver).resolve(route),
|
||||
item: costCentreResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -54,6 +54,5 @@ const costCentreRoutes: Routes = [
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule.forChild(costCentreRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [CostCentreListResolver, CostCentreResolver],
|
||||
})
|
||||
export class CostCentreRoutingModule {}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
|
||||
import { CostCentre } from '../core/cost-centre';
|
||||
|
||||
import { costCentreResolver } from './cost-centre.resolver';
|
||||
|
||||
describe('costCentreResolver', () => {
|
||||
const executeResolver: ResolveFn<CostCentre> = (...resolverParameters) =>
|
||||
TestBed.runInInjectionContext(() => costCentreResolver(...resolverParameters));
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(executeResolver).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
|
||||
import { CostCentre } from '../core/cost-centre';
|
||||
|
||||
import { CostCentreService } from './cost-centre.service';
|
||||
|
||||
export const costCentreResolver: ResolveFn<CostCentre> = (route) => {
|
||||
const id = route.paramMap.get('id');
|
||||
return inject(CostCentreService).get(id);
|
||||
};
|
||||
Reference in new issue
Block a user