import { Injectable } from '@angular/core' ; import { HttpClient , HttpHeaders } from '@angular/common/http' ; import { Router } from '@angular/router' ; import { AbstractService } from 'src/app/services/abstract' ; import { Token } from 'src/app/storage/Token' ; import { AuthenticationModelApplication , AuthenticationNormalizerApplication , AuthenticationSerializerApplication , } from 'src/app/model/Authentication' ; @ Injectable ( { providedIn : 'root' , } ) export class ConnectionService extends AbstractService { normalizer = new AuthenticationNormalizerApplication ( ) ; serializer = new AuthenticationSerializerApplication ( ) ; protected endpoint = 'authentication_token' ; constructor ( protected http , private router ) { super ( http ) ; } getOptions ( ) { return { headers : new HttpHeaders ( { 'Content-Type' : 'application/json; charset=utf-8' , } ) , } ; } getUrl ( ) { return `${ ConnectionService . getBaseAPI ( ) }/${ this . endpoint }` ; } insert ( data ) { return super . insert ( data ) ; } login ( data ) { return this . insert ( data ) . then ( ( { token } ) => ( { token } ) ) ; } logout ( ) { new Token ( ) . reset ( ) ; this . router . navigateByUrl ( '/login' ) ; } }