Skip to content

Commit d18bc39

Browse files
committed
removed core.module file
1 parent 738c07b commit d18bc39

25 files changed

+90
-153
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ Follow these steps to get the project up and running:
3737
$ cd logistics-app
3838
```
3939
40-
3. Install Angular app NPM packages:
40+
3. Install Angular app dependencies:
4141
```
4242
cd src\Client\Logistics.OfficeApp
43-
npm install
43+
bun install
4444
```
4545
4646
4. Update database connection strings:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { provideHttpClient, withInterceptors } from '@angular/common/http';
2+
import { ApplicationConfig, importProvidersFrom } from "@angular/core";
3+
import { BrowserModule } from '@angular/platform-browser';
4+
import { provideAnimations } from '@angular/platform-browser/animations';
5+
import { provideRouter } from '@angular/router';
6+
import { provideAuth } from 'angular-auth-oidc-client';
7+
import { ToastModule } from 'primeng/toast';
8+
import { APP_ROUTES } from './app.routes';
9+
import { AUTH_CONFIG } from './configs';
10+
import { tenantInterceptor, tokenInterceptor } from './core/interceptors';
11+
12+
export const appConfig: ApplicationConfig = {
13+
providers: [
14+
provideAuth({config: AUTH_CONFIG}),
15+
provideRouter(APP_ROUTES),
16+
importProvidersFrom(BrowserModule, ToastModule),
17+
provideAnimations(),
18+
provideHttpClient(withInterceptors([tenantInterceptor, tokenInterceptor])),
19+
],
20+
};

src/Client/Logistics.OfficeApp/src/app/components/layout/sidebar/sidebar.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {SplitButtonModule} from "primeng/splitbutton";
66
import {PanelMenuModule} from "primeng/panelmenu";
77
import {OverlayPanelModule} from "primeng/overlaypanel";
88
import {MenuItem} from "primeng/api";
9-
import {AppConfig} from "@/configs";
9+
import {GLOBAL_CONFIG} from "@/configs";
1010
import {AuthService} from "@/core/auth";
1111
import {ApiService, TenantService} from "@/core/services";
1212

@@ -107,6 +107,6 @@ export class SidebarComponent implements OnInit {
107107
}
108108

109109
openAccountUrl() {
110-
window.open(`${AppConfig.idHost}/account/manage/profile`, "_blank");
110+
window.open(`${GLOBAL_CONFIG.idHost}/account/manage/profile`, "_blank");
111111
}
112112
}

src/Client/Logistics.OfficeApp/src/app/configs/app.config.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Client/Logistics.OfficeApp/src/app/configs/auth.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {OpenIdConfiguration} from "angular-auth-oidc-client";
2-
import {AppConfig} from "./app.config";
2+
import {GLOBAL_CONFIG} from "./global.config";
33

4-
export const AuthConfig: OpenIdConfiguration = {
5-
authority: AppConfig.idHost,
4+
export const AUTH_CONFIG: OpenIdConfiguration = {
5+
authority: GLOBAL_CONFIG.idHost,
66
postLoginRoute: "/",
77
// forbiddenRoute: '/forbidden',
88
unauthorizedRoute: "/unauthorized",

src/Client/Logistics.OfficeApp/src/app/configs/global.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {environment} from "src/environments/environment";
22

3-
export const APP_CONFIG = {
3+
export const GLOBAL_CONFIG = {
44
apiHost: environment.apiHost,
55
idHost: environment.idHost,
66
mapboxToken: environment.mapboxToken,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export {AuthConfig} from "./auth.config";
2-
export {AppConfig} from "./app.config";
1+
export * from "./auth.config";
2+
export * from "./global.config";

src/Client/Logistics.OfficeApp/src/app/core/core.module.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/Client/Logistics.OfficeApp/src/app/core/guards/auth.guard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {ActivatedRouteSnapshot, Router, UrlTree} from "@angular/router";
33
import {map, Observable} from "rxjs";
44
import {AuthService, UserData} from "@/core/auth";
55

6-
@Injectable()
6+
@Injectable({providedIn: "root"})
77
export class AuthGuard {
88
constructor(
99
private authService: AuthService,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {AuthGuard} from "./auth.guard";
1+
export * from "./auth.guard";
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export {TenantInterceptor} from "./tenant.interceptor";
2-
export {TokenInterceptor} from "./token.interceptor";
1+
export * from "./tenant.interceptor";
2+
export * from "./token.interceptor";
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
import {Injectable} from "@angular/core";
2-
import {HttpRequest, HttpHandler, HttpEvent, HttpInterceptor} from "@angular/common/http";
1+
import {inject} from "@angular/core";
2+
import {HttpRequest, HttpEvent, HttpHandlerFn} from "@angular/common/http";
33
import {Observable} from "rxjs";
44
import {TenantService} from "../services/tenant.service";
55

6-
@Injectable()
7-
export class TenantInterceptor implements HttpInterceptor {
8-
constructor(private tenantService: TenantService) {}
6+
export function tenantInterceptor(request: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>> {
7+
const tenantService = inject(TenantService);
8+
const tenantId = tenantService.getTenantName();
9+
const headers = tenantService.createTenantHeaders(request.headers, tenantId);
10+
tenantService.setTenantCookie(tenantId);
911

10-
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
11-
const tenantId = this.tenantService.getTenantName();
12-
const headers = this.tenantService.createTenantHeaders(request.headers, tenantId);
13-
this.tenantService.setTenantCookie(tenantId);
14-
15-
request = request.clone({
16-
headers: headers,
17-
});
18-
return next.handle(request);
19-
}
12+
request = request.clone({
13+
headers: headers,
14+
});
15+
return next(request);
2016
}
Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
import {Injectable} from "@angular/core";
2-
import {HttpRequest, HttpHandler, HttpEvent, HttpInterceptor} from "@angular/common/http";
1+
import {inject} from "@angular/core";
2+
import {HttpRequest, HttpEvent, HttpHandlerFn} from "@angular/common/http";
33
import {Observable} from "rxjs";
44
import {AuthService} from "@/core/auth";
55

6-
@Injectable()
7-
export class TokenInterceptor implements HttpInterceptor {
8-
constructor(private authService: AuthService) {}
6+
export function tokenInterceptor(request: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>> {
7+
const authService = inject(AuthService);
8+
let token = "";
9+
authService.getAccessToken().subscribe((i) => (token = i));
10+
const headers = {Authorization: ""};
911

10-
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
11-
let token = "";
12-
this.authService.getAccessToken().subscribe((i) => (token = i));
13-
const headers = {Authorization: ""};
14-
15-
if (!request.headers.get("bypassAuthorization")) {
16-
headers["Authorization"] = `Bearer ${token}`;
17-
}
18-
19-
const newRequest = request.clone({
20-
setHeaders: headers,
21-
});
22-
23-
return next.handle(newRequest);
12+
if (!request.headers.get("bypassAuthorization")) {
13+
headers["Authorization"] = `Bearer ${token}`;
2414
}
15+
16+
const newRequest = request.clone({
17+
setHeaders: headers,
18+
});
19+
return next(newRequest);
2520
}

src/Client/Logistics.OfficeApp/src/app/core/services/api.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Injectable} from "@angular/core";
33
import {MessageService} from "primeng/api";
44
import {catchError, Observable, of} from "rxjs";
55
import {TenantService} from "@/core/services";
6-
import {AppConfig} from "@/configs";
6+
import {GLOBAL_CONFIG} from "@/configs";
77
import {
88
Result,
99
EmployeeDto,
@@ -45,7 +45,7 @@ import {
4545
GetPayrollsQuery,
4646
} from "../models";
4747

48-
@Injectable()
48+
@Injectable({providedIn: "root"})
4949
export class ApiService {
5050
private host: string;
5151
private headers: Record<string, string>;
@@ -55,7 +55,7 @@ export class ApiService {
5555
private readonly tenantService: TenantService,
5656
private readonly messageService: MessageService
5757
) {
58-
this.host = AppConfig.apiHost;
58+
this.host = GLOBAL_CONFIG.apiHost;
5959
this.headers = {"content-type": "application/json"};
6060
}
6161

src/Client/Logistics.OfficeApp/src/app/core/services/base-hub-connection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {AppConfig} from "@/configs";
1+
import {GLOBAL_CONFIG} from "@/configs";
22
import {HubConnection, HubConnectionBuilder, HttpTransportType} from "@microsoft/signalr";
33
import {TenantService} from "./tenant.service";
44

@@ -12,7 +12,7 @@ export abstract class BaseHubConnection {
1212
) {
1313
this.isConnected = false;
1414
this.hubConnection = new HubConnectionBuilder()
15-
.withUrl(`${AppConfig.apiHost}/hubs/${hubName}`, {
15+
.withUrl(`${GLOBAL_CONFIG.apiHost}/hubs/${hubName}`, {
1616
skipNegotiation: true,
1717
transport: HttpTransportType.WebSockets,
1818
})

src/Client/Logistics.OfficeApp/src/app/core/services/cookie.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Injectable} from "@angular/core";
22

3-
@Injectable()
3+
@Injectable({providedIn: "root"})
44
export class CookieService {
55
getCookie(name: string): string {
66
const cookies = document.cookie.split(";");

src/Client/Logistics.OfficeApp/src/app/core/services/notification.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {TenantService} from "./tenant.service";
66
import {BaseHubConnection} from "./base-hub-connection";
77
import {ApiService} from "./api.service";
88

9-
@Injectable()
9+
@Injectable({providedIn: "root"})
1010
export class NotificationService extends BaseHubConnection {
1111
constructor(
1212
private apiService: ApiService,
@@ -15,7 +15,7 @@ export class NotificationService extends BaseHubConnection {
1515
super("notification", tenantService);
1616
}
1717

18-
set onReceiveNotification(callback: OnReceiveNotifictionCallback) {
18+
set onReceiveNotification(callback: OnReceiveNotifictionFn) {
1919
this.hubConnection.on("ReceiveNotification", callback);
2020
}
2121

@@ -32,4 +32,4 @@ export class NotificationService extends BaseHubConnection {
3232
}
3333
}
3434

35-
type OnReceiveNotifictionCallback = (notification: NotificationDto) => void;
35+
type OnReceiveNotifictionFn = (notification: NotificationDto) => void;

src/Client/Logistics.OfficeApp/src/app/core/services/storage.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Injectable} from "@angular/core";
22

3-
@Injectable()
3+
@Injectable({providedIn: "root"})
44
export class StorageService {
55
get<T = unknown>(name: string): T | null {
66
try {

src/Client/Logistics.OfficeApp/src/app/core/services/toast.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Injectable} from "@angular/core";
22
import {MessageService} from "primeng/api";
33

4-
@Injectable()
4+
@Injectable({providedIn: "root"})
55
export class ToastService {
66
constructor(private messageService: MessageService) {}
77

src/Client/Logistics.OfficeApp/src/app/pages/dashboard/dashboard.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component} from "@angular/core";
22
import {CommonModule} from "@angular/common";
3-
import {AppConfig} from "@/configs";
3+
import {GLOBAL_CONFIG} from "@/configs";
44
import {GrossesBarchartComponent, TrucksMapComponent} from "@/components";
55
import {CompanyStatsComponent, TruckStatsTableComponent} from "./components";
66

@@ -21,6 +21,6 @@ export class DashboardComponent {
2121
public readonly accessToken: string;
2222

2323
constructor() {
24-
this.accessToken = AppConfig.mapboxToken;
24+
this.accessToken = GLOBAL_CONFIG.mapboxToken;
2525
}
2626
}

src/Client/Logistics.OfficeApp/src/app/pages/home/home.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {TooltipModule} from "primeng/tooltip";
88
import {TableModule} from "primeng/table";
99
import {SharedModule} from "primeng/api";
1010
import {CardModule} from "primeng/card";
11-
import {AppConfig} from "@/configs";
11+
import {GLOBAL_CONFIG} from "@/configs";
1212
import {DailyGrossesDto, LoadDto} from "@/core/models";
1313
import {ApiService} from "@/core/services";
1414
import {TrucksMapComponent} from "@/components";
@@ -39,7 +39,7 @@ import {NotificationsPanelComponent} from "./components";
3939
],
4040
})
4141
export class HomeComponent implements OnInit {
42-
public readonly accessToken = AppConfig.mapboxToken;
42+
public readonly accessToken = GLOBAL_CONFIG.mapboxToken;
4343
public todayGross = 0;
4444
public weeklyGross = 0;
4545
public weeklyDistance = 0;

src/Client/Logistics.OfficeApp/src/app/pages/load/add-load/add-load.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {ButtonModule} from "primeng/button";
88
import {DropdownModule} from "primeng/dropdown";
99
import {AutoCompleteModule} from "primeng/autocomplete";
1010
import {ProgressSpinnerModule} from "primeng/progressspinner";
11-
import {AppConfig} from "@/configs";
11+
import {GLOBAL_CONFIG} from "@/configs";
1212
import {AuthService} from "@/core/auth";
1313
import {AddressDto, CreateLoadCommand, CustomerDto} from "@/core/models";
1414
import {ApiService, ToastService} from "@/core/services";
@@ -47,7 +47,7 @@ import {TruckData} from "../shared";
4747
],
4848
})
4949
export class AddLoadComponent implements OnInit {
50-
public readonly accessToken = AppConfig.mapboxToken;
50+
public readonly accessToken = GLOBAL_CONFIG.mapboxToken;
5151
private distanceMeters = 0;
5252
public isLoading = false;
5353
public form: FormGroup<AddLoadForm>;

src/Client/Logistics.OfficeApp/src/app/pages/load/edit-load/edit-load.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {ButtonModule} from "primeng/button";
1010
import {DropdownModule} from "primeng/dropdown";
1111
import {AutoCompleteModule} from "primeng/autocomplete";
1212
import {ProgressSpinnerModule} from "primeng/progressspinner";
13-
import {AppConfig} from "@/configs";
13+
import {GLOBAL_CONFIG} from "@/configs";
1414
import {EnumType, LoadStatus, LoadStatusEnum} from "@/core/enums";
1515
import {AddressDto, CustomerDto, UpdateLoadCommand} from "@/core/models";
1616
import {ApiService, ToastService} from "@/core/services";
@@ -51,7 +51,7 @@ import {SearchCustomerComponent, SearchTruckComponent} from "../components";
5151
providers: [ConfirmationService],
5252
})
5353
export class EditLoadComponent implements OnInit {
54-
public readonly accessToken = AppConfig.mapboxToken;
54+
public readonly accessToken = GLOBAL_CONFIG.mapboxToken;
5555
private distanceMeters = 0;
5656
public id!: string;
5757
public loadRefId!: number;

0 commit comments

Comments
 (0)