Chore: Updated resolvers from Class to ResolveFn

This commit is contained in:
2024-05-31 09:58:48 +05:30
parent 6f433ef203
commit 6e3c429db3
255 changed files with 1737 additions and 2155 deletions
@@ -1,17 +0,0 @@
import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { ProfitLossResolver } from './profit-loss-resolver.service';
describe('ProfitLossResolver', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientModule],
providers: [ProfitLossResolver],
});
});
it('should be created', inject([ProfitLossResolver], (service: ProfitLossResolver) => {
expect(service).toBeTruthy();
}));
});
@@ -1,19 +0,0 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot } from '@angular/router';
import { Observable } from 'rxjs/internal/Observable';
import { ProfitLoss } from './profit-loss';
import { ProfitLossService } from './profit-loss.service';
@Injectable({
providedIn: 'root',
})
export class ProfitLossResolver {
constructor(private ser: ProfitLossService) {}
resolve(route: ActivatedRouteSnapshot): Observable<ProfitLoss> {
const startDate = route.queryParamMap.get('startDate') || null;
const finishDate = route.queryParamMap.get('finishDate') || null;
return this.ser.list(startDate, finishDate);
}
}
@@ -4,8 +4,8 @@ import { ActivatedRouteSnapshot, RouterModule, RouterStateSnapshot, Routes } fro
import { AuthGuard } from '../auth/auth-guard.service';
import { ProfitLossResolver } from './profit-loss-resolver.service';
import { ProfitLossComponent } from './profit-loss.component';
import { profitLossResolver } from './profit-loss.resolver';
const profitLossRoutes: Routes = [
{
@@ -18,7 +18,7 @@ const profitLossRoutes: Routes = [
permission: 'Profit & Loss',
},
resolve: {
info: (route: ActivatedRouteSnapshot) => inject(ProfitLossResolver).resolve(route),
info: profitLossResolver,
},
runGuardsAndResolvers: 'always',
},
@@ -27,6 +27,5 @@ const profitLossRoutes: Routes = [
@NgModule({
imports: [CommonModule, RouterModule.forChild(profitLossRoutes)],
exports: [RouterModule],
providers: [ProfitLossResolver],
})
export class ProfitLossRoutingModule {}
@@ -0,0 +1,18 @@
import { TestBed } from '@angular/core/testing';
import { ResolveFn } from '@angular/router';
import { ProfitLoss } from './profit-loss';
import { profitLossResolver } from './profit-loss.resolver';
describe('profitLossResolver', () => {
const executeResolver: ResolveFn<ProfitLoss> = (...resolverParameters) =>
TestBed.runInInjectionContext(() => profitLossResolver(...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 { ProfitLoss } from './profit-loss';
import { ProfitLossService } from './profit-loss.service';
export const profitLossResolver: ResolveFn<ProfitLoss> = (route) => {
const startDate = route.queryParamMap.get('startDate') || null;
const finishDate = route.queryParamMap.get('finishDate') || null;
return inject(ProfitLossService).list(startDate, finishDate);
};