/** @file * @author Edouard DUPIN * @copyright 2018, Edouard DUPIN, all right reserved * @license PROPRIETARY (see license file) */ import { Injectable } from '@angular/core'; import { SessionService, HTTPMimeType, HTTPRequestModel, HttpWrapperService, ModelResponseHttp, } from 'common/service'; export interface ApplicationTokenModel { id: number; name: string; endValidityTime: string; token?: string; } @Injectable() export class ApplicationTokenService { constructor(private http: HttpWrapperService) { console.log('Start ApplicationTokenService'); } gets(applicationId: number): Promise { let self = this; return new Promise((resolve, reject) => { this.http .requestJson({ server: 'karso', endPoint: `application_token/${applicationId}`, requestType: HTTPRequestModel.GET, accept: HTTPMimeType.JSON, contentType: HTTPMimeType.JSON, }) .then((response: ModelResponseHttp) => { // TODO: check type ... console.log( `retreive Token for application : get some data to check: ${JSON.stringify(response.data)}` ); // tODO: check the format... resolve(response.data); }) .catch((error: any) => { reject(`return ERROR ${JSON.stringify(error, null, 2)}`); }); }); } create(applicationId: number, name: string, validity: number): Promise { let body = { name, validity, }; return new Promise((resolve, reject) => { this.http .requestJson({ server: 'karso', endPoint: `application_token/${applicationId}/create`, requestType: HTTPRequestModel.POST, accept: HTTPMimeType.JSON, contentType: HTTPMimeType.JSON, body, }) .then((response: ModelResponseHttp) => { resolve(response.data); }) .catch((error: any) => { reject(`return ERROR ${JSON.stringify(error, null, 2)}`); }); }); } remove(applicationId: number, tokenId: number): Promise { return new Promise((resolve, reject) => { this.http .request({ server: 'karso', endPoint: `application_token/${applicationId}/${tokenId}`, requestType: HTTPRequestModel.DELETE, accept: HTTPMimeType.ALL, contentType: HTTPMimeType.JSON, }) .then(() => { resolve(); }) .catch((error: any) => { reject(`return ERROR ${JSON.stringify(error, null, 2)}`); }); }); } }