fix: update core and apply stricter tslint rules

This commit is contained in:
Michel Jonathan Schmitz
2019-07-10 12:38:29 +02:00
parent 03c317430a
commit 911492d064
67 changed files with 1291 additions and 507 deletions

View File

@@ -15,11 +15,12 @@
import {HTTP_INTERCEPTORS, HttpClient,
HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {SCIndexResponse, SCThingOriginType, SCThingType} from '@openstapps/core';
import {SCIndexResponse, SCSettingInputType, SCThingOriginType, SCThingType} from '@openstapps/core';
import {Observable, of} from 'rxjs';
import {map, delay} from 'rxjs/operators';
import {delay, map} from 'rxjs/operators';
import {SampleThings} from './data/sample-things';
// tslint:disable:no-magic-numbers
const sampleIndexResponse: SCIndexResponse = {
app: {
campusPolygon: {
@@ -58,12 +59,9 @@ const sampleIndexResponse: SCIndexResponse = {
settings: [
{
categories: ['profile'],
defaultValue: 'student',
description: '',
input: {
defaultValue: 'student',
inputType: 'singleChoice',
values: ['student', 'employee', 'guest'],
},
inputType: SCSettingInputType.SingleChoice,
name: 'group',
order: 1,
origin: {
@@ -87,15 +85,13 @@ const sampleIndexResponse: SCIndexResponse = {
},
type: SCThingType.Setting,
uid: '',
values: ['student', 'employee', 'guest'],
},
{
categories: ['profile'],
defaultValue: 'en',
description: '',
input: {
defaultValue: 'en',
inputType: 'singleChoice',
values: ['en', 'de'],
},
inputType: SCSettingInputType.SingleChoice,
name: 'language',
order: 0,
origin: {
@@ -117,15 +113,13 @@ const sampleIndexResponse: SCIndexResponse = {
},
type: SCThingType.Setting,
uid: '',
values: ['en', 'de'],
},
{
categories: ['privacy'],
defaultValue: false,
description: '',
input: {
defaultValue: false,
inputType: 'singleChoice',
values: [true, false],
},
inputType: SCSettingInputType.SingleChoice,
name: 'geoLocation',
order: 0,
origin: {
@@ -149,6 +143,7 @@ const sampleIndexResponse: SCIndexResponse = {
},
type: SCThingType.Setting,
uid: '',
values: [true, false],
},
],
},
@@ -226,20 +221,33 @@ const sampleIndexResponse: SCIndexResponse = {
},
};
// tslint:enable:no-magic-numbers
/**
* TODO
*/
@Injectable()
export class FakeBackendInterceptor implements HttpInterceptor {
/**
* TODO
*/
sampleFetcher: SampleThings;
constructor(http: HttpClient) {
this.sampleFetcher = new SampleThings(http);
}
/**
* TODO
*/
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (request.method === 'POST') {
if (request.url.endsWith('/') && request.method === 'POST') {
// respond with expected (faked) index response
return of(new HttpResponse({status: 200, body: sampleIndexResponse}));
// respond with a search response with sample data
} else if (request.url.endsWith('/search')) {
}
if (request.url.endsWith('/search')) {
if (typeof request.body.filter !== 'undefined' && typeof request.body.filter.arguments !== 'undefined') {
if (request.body.filter.arguments.field === 'uid') {
return this.sampleFetcher.getSampleThing(request.body.filter.arguments.value)
@@ -248,11 +256,14 @@ export class FakeBackendInterceptor implements HttpInterceptor {
}), delay(1000)); // add delay for skeleton screens to be seen (see !16)
}
}
return this.sampleFetcher.getSampleThings().pipe(map((sampleData: any) => {
return new HttpResponse({status: 200, body: {data: sampleData}});
}), delay(1000)); // add delay for skeleton screens to be seen (see !16)
return this.sampleFetcher.getSampleThings()
.pipe(map((sampleData: any) => {
return new HttpResponse({status: 200, body: {data: sampleData}});
}), delay(1000)); // add delay for skeleton screens to be seen (see !16)
}
}
return next.handle(request);
}
}