Posted by bolatah on 7/12/2024, 8:55:20 AM
import { HttpRequest, HttpHandlerFn, HttpEvent, HttpInterceptorFn } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
export const dateToUnixTimestamp : HttpInterceptorFn = (req: HttpRequest<any>, next: HttpHandlerFn) : Observable<HttpEvent<any>> => {
if(req.body && req.body.faellig){
const faelligDate = new Date (req.body.faellig);
const unixTimestamp= faelligDate.getTime();
const unixTimeStampValue = Math.floor(unixTimestamp/1000);
const modifiedReq = req.clone({
body: {...req.body, faellig: unixTimeStampValue}
})
return next(modifiedReq)
}
return next(req)
}
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptors } from '@angular/common/http';
import { provideStore } from '@ngrx/store';
import { todosReducer } from './store/reducers/todos.reducer';
import { authReducer } from './store/reducers/auth.reducer';
import { AuthGuard } from './guards/auth.guard';
import { authInterceptor } from './store/interceptors/auth.interceptor';
import { dateToUnixTimestamp } from './store/interceptors/date-to-unix-timestamp.interceptor';
export const appConfig: ApplicationConfig = {
providers: [
AuthGuard,
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes),
provideAnimationsAsync(),
provideHttpClient(withInterceptors([authInterceptor, dateToUnixTimestamp])),
provideStore({
todos: todosReducer,
auth: authReducer,
}),
],
};