Skip to content

Commit

Permalink
removed core.module file
Browse files Browse the repository at this point in the history
  • Loading branch information
suxrobGM committed Oct 6, 2024
1 parent 738c07b commit d18bc39
Show file tree
Hide file tree
Showing 25 changed files with 90 additions and 153 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ Follow these steps to get the project up and running:
$ cd logistics-app
```
3. Install Angular app NPM packages:
3. Install Angular app dependencies:
```
cd src\Client\Logistics.OfficeApp
npm install
bun install
```
4. Update database connection strings:
Expand Down
20 changes: 20 additions & 0 deletions src/Client/Logistics.OfficeApp/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { ApplicationConfig, importProvidersFrom } from "@angular/core";
import { BrowserModule } from '@angular/platform-browser';
import { provideAnimations } from '@angular/platform-browser/animations';
import { provideRouter } from '@angular/router';
import { provideAuth } from 'angular-auth-oidc-client';
import { ToastModule } from 'primeng/toast';
import { APP_ROUTES } from './app.routes';
import { AUTH_CONFIG } from './configs';
import { tenantInterceptor, tokenInterceptor } from './core/interceptors';

export const appConfig: ApplicationConfig = {
providers: [
provideAuth({config: AUTH_CONFIG}),
provideRouter(APP_ROUTES),
importProvidersFrom(BrowserModule, ToastModule),
provideAnimations(),
provideHttpClient(withInterceptors([tenantInterceptor, tokenInterceptor])),
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {SplitButtonModule} from "primeng/splitbutton";
import {PanelMenuModule} from "primeng/panelmenu";
import {OverlayPanelModule} from "primeng/overlaypanel";
import {MenuItem} from "primeng/api";
import {AppConfig} from "@/configs";
import {GLOBAL_CONFIG} from "@/configs";
import {AuthService} from "@/core/auth";
import {ApiService, TenantService} from "@/core/services";

Expand Down Expand Up @@ -107,6 +107,6 @@ export class SidebarComponent implements OnInit {
}

openAccountUrl() {
window.open(`${AppConfig.idHost}/account/manage/profile`, "_blank");
window.open(`${GLOBAL_CONFIG.idHost}/account/manage/profile`, "_blank");
}
}
12 changes: 0 additions & 12 deletions src/Client/Logistics.OfficeApp/src/app/configs/app.config.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/Client/Logistics.OfficeApp/src/app/configs/auth.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {OpenIdConfiguration} from "angular-auth-oidc-client";
import {AppConfig} from "./app.config";
import {GLOBAL_CONFIG} from "./global.config";

export const AuthConfig: OpenIdConfiguration = {
authority: AppConfig.idHost,
export const AUTH_CONFIG: OpenIdConfiguration = {
authority: GLOBAL_CONFIG.idHost,
postLoginRoute: "/",
// forbiddenRoute: '/forbidden',
unauthorizedRoute: "/unauthorized",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {environment} from "src/environments/environment";

export const APP_CONFIG = {
export const GLOBAL_CONFIG = {
apiHost: environment.apiHost,
idHost: environment.idHost,
mapboxToken: environment.mapboxToken,
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Logistics.OfficeApp/src/app/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {AuthConfig} from "./auth.config";
export {AppConfig} from "./app.config";
export * from "./auth.config";
export * from "./global.config";
40 changes: 0 additions & 40 deletions src/Client/Logistics.OfficeApp/src/app/core/core.module.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ActivatedRouteSnapshot, Router, UrlTree} from "@angular/router";
import {map, Observable} from "rxjs";
import {AuthService, UserData} from "@/core/auth";

@Injectable()
@Injectable({providedIn: "root"})
export class AuthGuard {
constructor(
private authService: AuthService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {AuthGuard} from "./auth.guard";
export * from "./auth.guard";
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {TenantInterceptor} from "./tenant.interceptor";
export {TokenInterceptor} from "./token.interceptor";
export * from "./tenant.interceptor";
export * from "./token.interceptor";
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import {Injectable} from "@angular/core";
import {HttpRequest, HttpHandler, HttpEvent, HttpInterceptor} from "@angular/common/http";
import {inject} from "@angular/core";
import {HttpRequest, HttpEvent, HttpHandlerFn} from "@angular/common/http";
import {Observable} from "rxjs";
import {TenantService} from "../services/tenant.service";

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

intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
const tenantId = this.tenantService.getTenantName();
const headers = this.tenantService.createTenantHeaders(request.headers, tenantId);
this.tenantService.setTenantCookie(tenantId);

request = request.clone({
headers: headers,
});
return next.handle(request);
}
request = request.clone({
headers: headers,
});
return next(request);
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import {Injectable} from "@angular/core";
import {HttpRequest, HttpHandler, HttpEvent, HttpInterceptor} from "@angular/common/http";
import {inject} from "@angular/core";
import {HttpRequest, HttpEvent, HttpHandlerFn} from "@angular/common/http";
import {Observable} from "rxjs";
import {AuthService} from "@/core/auth";

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

intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
let token = "";
this.authService.getAccessToken().subscribe((i) => (token = i));
const headers = {Authorization: ""};

if (!request.headers.get("bypassAuthorization")) {
headers["Authorization"] = `Bearer ${token}`;
}

const newRequest = request.clone({
setHeaders: headers,
});

return next.handle(newRequest);
if (!request.headers.get("bypassAuthorization")) {
headers["Authorization"] = `Bearer ${token}`;
}

const newRequest = request.clone({
setHeaders: headers,
});
return next(newRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Injectable} from "@angular/core";
import {MessageService} from "primeng/api";
import {catchError, Observable, of} from "rxjs";
import {TenantService} from "@/core/services";
import {AppConfig} from "@/configs";
import {GLOBAL_CONFIG} from "@/configs";
import {
Result,
EmployeeDto,
Expand Down Expand Up @@ -45,7 +45,7 @@ import {
GetPayrollsQuery,
} from "../models";

@Injectable()
@Injectable({providedIn: "root"})
export class ApiService {
private host: string;
private headers: Record<string, string>;
Expand All @@ -55,7 +55,7 @@ export class ApiService {
private readonly tenantService: TenantService,
private readonly messageService: MessageService
) {
this.host = AppConfig.apiHost;
this.host = GLOBAL_CONFIG.apiHost;
this.headers = {"content-type": "application/json"};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AppConfig} from "@/configs";
import {GLOBAL_CONFIG} from "@/configs";
import {HubConnection, HubConnectionBuilder, HttpTransportType} from "@microsoft/signalr";
import {TenantService} from "./tenant.service";

Expand All @@ -12,7 +12,7 @@ export abstract class BaseHubConnection {
) {
this.isConnected = false;
this.hubConnection = new HubConnectionBuilder()
.withUrl(`${AppConfig.apiHost}/hubs/${hubName}`, {
.withUrl(`${GLOBAL_CONFIG.apiHost}/hubs/${hubName}`, {
skipNegotiation: true,
transport: HttpTransportType.WebSockets,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Injectable} from "@angular/core";

@Injectable()
@Injectable({providedIn: "root"})
export class CookieService {
getCookie(name: string): string {
const cookies = document.cookie.split(";");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {TenantService} from "./tenant.service";
import {BaseHubConnection} from "./base-hub-connection";
import {ApiService} from "./api.service";

@Injectable()
@Injectable({providedIn: "root"})
export class NotificationService extends BaseHubConnection {
constructor(
private apiService: ApiService,
Expand All @@ -15,7 +15,7 @@ export class NotificationService extends BaseHubConnection {
super("notification", tenantService);
}

set onReceiveNotification(callback: OnReceiveNotifictionCallback) {
set onReceiveNotification(callback: OnReceiveNotifictionFn) {
this.hubConnection.on("ReceiveNotification", callback);
}

Expand All @@ -32,4 +32,4 @@ export class NotificationService extends BaseHubConnection {
}
}

type OnReceiveNotifictionCallback = (notification: NotificationDto) => void;
type OnReceiveNotifictionFn = (notification: NotificationDto) => void;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Injectable} from "@angular/core";

@Injectable()
@Injectable({providedIn: "root"})
export class StorageService {
get<T = unknown>(name: string): T | null {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Injectable} from "@angular/core";
import {MessageService} from "primeng/api";

@Injectable()
@Injectable({providedIn: "root"})
export class ToastService {
constructor(private messageService: MessageService) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component} from "@angular/core";
import {CommonModule} from "@angular/common";
import {AppConfig} from "@/configs";
import {GLOBAL_CONFIG} from "@/configs";
import {GrossesBarchartComponent, TrucksMapComponent} from "@/components";
import {CompanyStatsComponent, TruckStatsTableComponent} from "./components";

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

constructor() {
this.accessToken = AppConfig.mapboxToken;
this.accessToken = GLOBAL_CONFIG.mapboxToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {TooltipModule} from "primeng/tooltip";
import {TableModule} from "primeng/table";
import {SharedModule} from "primeng/api";
import {CardModule} from "primeng/card";
import {AppConfig} from "@/configs";
import {GLOBAL_CONFIG} from "@/configs";
import {DailyGrossesDto, LoadDto} from "@/core/models";
import {ApiService} from "@/core/services";
import {TrucksMapComponent} from "@/components";
Expand Down Expand Up @@ -39,7 +39,7 @@ import {NotificationsPanelComponent} from "./components";
],
})
export class HomeComponent implements OnInit {
public readonly accessToken = AppConfig.mapboxToken;
public readonly accessToken = GLOBAL_CONFIG.mapboxToken;
public todayGross = 0;
public weeklyGross = 0;
public weeklyDistance = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {ButtonModule} from "primeng/button";
import {DropdownModule} from "primeng/dropdown";
import {AutoCompleteModule} from "primeng/autocomplete";
import {ProgressSpinnerModule} from "primeng/progressspinner";
import {AppConfig} from "@/configs";
import {GLOBAL_CONFIG} from "@/configs";
import {AuthService} from "@/core/auth";
import {AddressDto, CreateLoadCommand, CustomerDto} from "@/core/models";
import {ApiService, ToastService} from "@/core/services";
Expand Down Expand Up @@ -47,7 +47,7 @@ import {TruckData} from "../shared";
],
})
export class AddLoadComponent implements OnInit {
public readonly accessToken = AppConfig.mapboxToken;
public readonly accessToken = GLOBAL_CONFIG.mapboxToken;
private distanceMeters = 0;
public isLoading = false;
public form: FormGroup<AddLoadForm>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {ButtonModule} from "primeng/button";
import {DropdownModule} from "primeng/dropdown";
import {AutoCompleteModule} from "primeng/autocomplete";
import {ProgressSpinnerModule} from "primeng/progressspinner";
import {AppConfig} from "@/configs";
import {GLOBAL_CONFIG} from "@/configs";
import {EnumType, LoadStatus, LoadStatusEnum} from "@/core/enums";
import {AddressDto, CustomerDto, UpdateLoadCommand} from "@/core/models";
import {ApiService, ToastService} from "@/core/services";
Expand Down Expand Up @@ -51,7 +51,7 @@ import {SearchCustomerComponent, SearchTruckComponent} from "../components";
providers: [ConfirmationService],
})
export class EditLoadComponent implements OnInit {
public readonly accessToken = AppConfig.mapboxToken;
public readonly accessToken = GLOBAL_CONFIG.mapboxToken;
private distanceMeters = 0;
public id!: string;
public loadRefId!: number;
Expand Down
Loading

0 comments on commit d18bc39

Please sign in to comment.