refactor: move to eslint

This commit is contained in:
Rainer Killinger
2022-08-17 16:02:34 +02:00
parent c1dc7b4e8f
commit f864c64efa
92 changed files with 2287 additions and 1871 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -50,7 +50,8 @@ export abstract class SCError implements SCErrorResponse {
constructor(public name: string, public message: string, public statusCode: number, stack = false) {
// generate stacktrace if needed
if (stack) {
this.stack = (new Error()).stack;
// eslint-disable-next-line unicorn/error-message
this.stack = new Error().stack;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -29,15 +29,15 @@ export class SCInternalServerErrorResponse extends SCError {
/**
* Create a SCInternalServerErrorResponse
*
* @param err Internal server error
* @param error Internal server error
* @param stack Set to true if a stack trace should be created
* and the internal server error should be displayed to the client
*/
constructor(err?: Error, stack = false) {
constructor(error?: Error, stack = false) {
super('InternalServerError', 'Internal server error', StatusCodes.BAD_GATEWAY, stack);
if (stack) {
this.additionalData = err;
this.additionalData = error;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -27,6 +27,11 @@ export class SCMethodNotAllowedErrorResponse extends SCError {
* @param stack Set to true if a stack trace should be created
*/
constructor(stack?: boolean) {
super('MethodNotAllowedError', 'HTTP method is not allowed on this route', StatusCodes.METHOD_NOT_ALLOWED, stack);
super(
'MethodNotAllowedError',
'HTTP method is not allowed on this route',
StatusCodes.METHOD_NOT_ALLOWED,
stack,
);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -40,8 +40,8 @@ export enum SCRouteHttpVerbs {
/**
* The constructor of an error response
*/
// tslint:disable-next-line:no-any
export type SCErrorResponseConstructor = new (...args: any[]) => SCErrorResponse;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type SCErrorResponseConstructor = new (...arguments_: any[]) => SCErrorResponse;
/**
* A description of a route
@@ -91,26 +91,32 @@ export abstract class SCAbstractRoute implements SCRoute {
* @see SCRoute.errorNames
*/
errorNames: SCErrorResponseConstructor[] = [];
/**
* @see SCRoute.method
*/
method: SCRouteHttpVerbs = SCRouteHttpVerbs.GET;
/**
* @see SCRoute.obligatoryParameters
*/
obligatoryParameters?: SCMap<string>;
/**
* @see SCRoute.requestBodyName
*/
requestBodyName = 'any';
/**
* @see SCRoute.responseBodyName
*/
responseBodyName = 'any';
/**
* @see SCRoute.statusCodeSuccess
*/
statusCodeSuccess = 200;
/**
* @see SCRoute.urlPath
*/
@@ -134,15 +140,15 @@ export abstract class SCAbstractRoute implements SCRoute {
return this.urlPath
.split('/')
.map((part) => {
.map(part => {
if (part.indexOf(':') !== 0) {
return part;
}
const parameter = part.substr(1);
const parameter = part.slice(1);
if (typeof parameters[parameter] === 'undefined') {
throw new Error(`Parameter '${parameter}' not provided.`);
throw new TypeError(`Parameter '${parameter}' not provided.`);
}
return parameters[parameter];
@@ -155,7 +161,7 @@ export abstract class SCAbstractRoute implements SCRoute {
* Possible requests
*/
export type SCRequests =
SCBookAvailabilityRequest
| SCBookAvailabilityRequest
| SCBulkRequest
| SCBulkAddRequest
| SCBulkDoneRequest
@@ -169,7 +175,7 @@ export type SCRequests =
* Possible responses
*/
export type SCResponses =
SCBookAvailabilityResponse
| SCBookAvailabilityResponse
| SCBulkResponse
| SCBulkAddResponse
| SCBulkDoneResponse
@@ -182,59 +188,91 @@ export type SCResponses =
/**
* Associated response for a request
*/
export type SCAssociatedResponse<REQUEST> =
REQUEST extends SCBookAvailabilityRequest ? SCBookAvailabilityResponse :
REQUEST extends SCBulkRequest ? SCBulkResponse :
REQUEST extends SCBulkAddRequest ? SCBulkAddResponse :
REQUEST extends SCBulkDoneRequest ? SCBulkDoneResponse :
REQUEST extends SCFeedbackRequest ? SCFeedbackResponse :
REQUEST extends SCIndexRequest ? SCIndexResponse :
REQUEST extends SCMultiSearchRequest ? SCMultiSearchResponse :
REQUEST extends SCSearchRequest ? SCSearchResponse :
REQUEST extends SCThingUpdateRequest ? SCThingUpdateResponse :
never;
export type SCAssociatedResponse<REQUEST> = REQUEST extends SCBookAvailabilityRequest
? SCBookAvailabilityResponse
: REQUEST extends SCBulkRequest
? SCBulkResponse
: REQUEST extends SCBulkAddRequest
? SCBulkAddResponse
: REQUEST extends SCBulkDoneRequest
? SCBulkDoneResponse
: REQUEST extends SCFeedbackRequest
? SCFeedbackResponse
: REQUEST extends SCIndexRequest
? SCIndexResponse
: REQUEST extends SCMultiSearchRequest
? SCMultiSearchResponse
: REQUEST extends SCSearchRequest
? SCSearchResponse
: REQUEST extends SCThingUpdateRequest
? SCThingUpdateResponse
: never;
/**
* Associated request for a response
*/
export type SCAssociatedRequest<RESPONSE> =
RESPONSE extends SCBookAvailabilityResponse ? SCBookAvailabilityRequest :
RESPONSE extends SCBulkResponse ? SCBulkRequest :
RESPONSE extends SCBulkAddResponse ? SCBulkAddRequest :
RESPONSE extends SCBulkDoneResponse ? SCBulkDoneRequest :
RESPONSE extends SCFeedbackResponse ? SCFeedbackRequest :
RESPONSE extends SCIndexResponse ? SCIndexRequest :
RESPONSE extends SCMultiSearchResponse ? SCMultiSearchRequest :
RESPONSE extends SCSearchResponse ? SCSearchRequest :
RESPONSE extends SCThingUpdateResponse ? SCThingUpdateRequest :
never;
export type SCAssociatedRequest<RESPONSE> = RESPONSE extends SCBookAvailabilityResponse
? SCBookAvailabilityRequest
: RESPONSE extends SCBulkResponse
? SCBulkRequest
: RESPONSE extends SCBulkAddResponse
? SCBulkAddRequest
: RESPONSE extends SCBulkDoneResponse
? SCBulkDoneRequest
: RESPONSE extends SCFeedbackResponse
? SCFeedbackRequest
: RESPONSE extends SCIndexResponse
? SCIndexRequest
: RESPONSE extends SCMultiSearchResponse
? SCMultiSearchRequest
: RESPONSE extends SCSearchResponse
? SCSearchRequest
: RESPONSE extends SCThingUpdateResponse
? SCThingUpdateRequest
: never;
/**
* Associated request for a route
*/
export type SCAssignedRequest<ROUTE extends SCAbstractRoute> =
ROUTE extends SCBookAvailabilityRoute ? SCBookAvailabilityRequest :
ROUTE extends SCBulkRoute ? SCBulkRequest :
ROUTE extends SCBulkAddRoute ? SCBulkAddRequest :
ROUTE extends SCBulkDoneRoute ? SCBulkDoneRequest :
ROUTE extends SCFeedbackRoute ? SCFeedbackRequest :
ROUTE extends SCIndexRoute ? SCIndexRequest :
ROUTE extends SCMultiSearchRoute ? SCMultiSearchRequest :
ROUTE extends SCSearchRoute ? SCSearchRequest :
ROUTE extends SCThingUpdateRoute ? SCThingUpdateRequest :
never;
export type SCAssignedRequest<ROUTE extends SCAbstractRoute> = ROUTE extends SCBookAvailabilityRoute
? SCBookAvailabilityRequest
: ROUTE extends SCBulkRoute
? SCBulkRequest
: ROUTE extends SCBulkAddRoute
? SCBulkAddRequest
: ROUTE extends SCBulkDoneRoute
? SCBulkDoneRequest
: ROUTE extends SCFeedbackRoute
? SCFeedbackRequest
: ROUTE extends SCIndexRoute
? SCIndexRequest
: ROUTE extends SCMultiSearchRoute
? SCMultiSearchRequest
: ROUTE extends SCSearchRoute
? SCSearchRequest
: ROUTE extends SCThingUpdateRoute
? SCThingUpdateRequest
: never;
/**
* Associated response for a route
*/
export type SCAssignedResponse<ROUTE extends SCAbstractRoute> =
ROUTE extends SCBookAvailabilityRoute ? SCBookAvailabilityResponse :
ROUTE extends SCBulkRoute ? SCBulkResponse :
ROUTE extends SCBulkAddRoute ? SCBulkAddResponse :
ROUTE extends SCBulkDoneRoute ? SCBulkDoneResponse :
ROUTE extends SCFeedbackRoute ? SCFeedbackResponse :
ROUTE extends SCIndexRoute ? SCIndexResponse :
ROUTE extends SCMultiSearchRoute ? SCMultiSearchResponse :
ROUTE extends SCSearchRoute ? SCSearchResponse :
ROUTE extends SCThingUpdateRoute ? SCThingUpdateResponse :
never;
export type SCAssignedResponse<ROUTE extends SCAbstractRoute> = ROUTE extends SCBookAvailabilityRoute
? SCBookAvailabilityResponse
: ROUTE extends SCBulkRoute
? SCBulkResponse
: ROUTE extends SCBulkAddRoute
? SCBulkAddResponse
: ROUTE extends SCBulkDoneRoute
? SCBulkDoneResponse
: ROUTE extends SCFeedbackRoute
? SCFeedbackResponse
: ROUTE extends SCIndexRoute
? SCIndexResponse
: ROUTE extends SCMultiSearchRoute
? SCMultiSearchResponse
: ROUTE extends SCSearchRoute
? SCSearchResponse
: ROUTE extends SCThingUpdateRoute
? SCThingUpdateResponse
: never;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -14,7 +14,10 @@
*/
import {StatusCodes} from 'http-status-codes';
import {SCUuid} from '../../general/uuid';
import {SCAcademicPriceGroup, SCThingThatCanBeOfferedOffer} from '../../things/abstract/thing-that-can-be-offered';
import {
SCAcademicPriceGroup,
SCThingThatCanBeOfferedOffer,
} from '../../things/abstract/thing-that-can-be-offered';
import {SCInternalServerErrorResponse} from '../errors/internal-server-error';
import {SCMethodNotAllowedErrorResponse} from '../errors/method-not-allowed';
import {SCNotFoundErrorResponse} from '../errors/not-found';

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -35,8 +35,7 @@ export type SCBulkAddRequest = SCThings;
*
* @validatable
*/
export interface SCBulkAddResponse {
}
export interface SCBulkAddResponse {}
/**
* Route for indexing SC things in a bulk

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -27,16 +27,14 @@ import {SCAbstractRoute, SCRouteHttpVerbs} from '../route';
*
* @validatable
*/
export interface SCBulkDoneRequest {
}
export interface SCBulkDoneRequest {}
/**
* Response to a request to change the state of a bulk to done
*
* @validatable
*/
export interface SCBulkDoneResponse {
}
export interface SCBulkDoneResponse {}
/**
* Route for closing bulks

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -31,8 +31,7 @@ import {SCAbstractRoute, SCRouteHttpVerbs} from '../route';
*
* @validatable
*/
export interface SCBulkRequest extends SCBulkParameters {
}
export type SCBulkRequest = SCBulkParameters;
/**
* Parameters for a bulk

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -39,8 +39,7 @@ export interface SCFeedbackRequest extends SCMessage {
*
* @validatable
*/
export interface SCFeedbackResponse {
}
export interface SCFeedbackResponse {}
/**
* Route for feedback submission

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -29,8 +29,7 @@ import {SCAbstractRoute, SCRouteHttpVerbs} from '../route';
*
* @validatable
*/
export interface SCIndexRequest {
}
export interface SCIndexRequest {}
/**
* A response to an index request
@@ -46,7 +45,7 @@ export interface SCIndexResponse {
/**
* @see SCAuthorizationProvider
*/
auth: { [key in SCAuthorizationProviderType]?: SCAuthorizationProvider; };
auth: {[key in SCAuthorizationProviderType]?: SCAuthorizationProvider};
/**
* @see SCBackendConfiguration

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -28,16 +28,14 @@ import {SCSearchResult} from '../search/result';
*
* @validatable
*/
export interface SCSearchRequest extends SCSearchQuery {
}
export type SCSearchRequest = SCSearchQuery;
/**
* A search response
*
* @validatable
*/
export interface SCSearchResponse extends SCSearchResult {
}
export type SCSearchResponse = SCSearchResult;
/**
* Route for searching things

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -35,8 +35,7 @@ export type SCThingUpdateRequest = SCThings;
*
* @validatable
*/
export interface SCThingUpdateResponse {
}
export interface SCThingUpdateResponse {}
/**
* Route for updating existing things

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -27,7 +27,7 @@ import {SCSearchValueFilter} from './filters/value';
* Filter instruction types
*/
export type SCSearchFilterType =
'availability'
| 'availability'
| 'boolean'
| 'distance'
| 'value'
@@ -59,7 +59,7 @@ export type SCSearchAbstractFilterArguments = SCMap<unknown>;
* Available filter instructions
*/
export type SCSearchFilter =
SCSearchAvailabilityFilter
| SCSearchAvailabilityFilter
| SCSearchBooleanFilter
| SCSearchDistanceFilter
| SCSearchValueFilter

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -12,7 +12,6 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
// tslint:disable-next-line:no-implicit-dependencies
import {Position} from 'geojson';
import {SCThingsField} from '../../../meta';
import {SCSearchAbstractFilter, SCSearchAbstractFilterArguments} from '../filter';

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 StApps
* Copyright (C) 2021-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -12,7 +12,6 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
// tslint:disable-next-line:no-implicit-dependencies
import {Polygon, Position} from 'geojson';
import {SCThingsField} from '../../../meta';
import {SCSearchAbstractFilter, SCSearchAbstractFilterArguments} from '../filter';

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 StApps
* Copyright (C) 2020-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -47,6 +47,7 @@ export interface SCSearchNumericRangeFilter extends SCSearchAbstractFilter<SCNum
* Additional arguments for date range filters
*
* Filter uses a plain string to allow for date math expressions
*
* @see https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/date-math-expressions.html
*/
export interface SCDateRangeFilterArguments extends SCRangeFilterArguments<string> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019, 2020 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 StApps
* Copyright (C) 2019-2022 Open StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -12,7 +12,6 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
// tslint:disable-next-line:no-implicit-dependencies
import {Position} from 'geojson';
import {SCSearchAbstractSort, SCSearchAbstractSortArguments} from '../sort';