From 9df52d660feb722404be00a50f3c8a612bec1c15 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 17 Aug 2021 14:42:53 +0200 Subject: Migrate client to eslint --- client/src/app/core/rest/rest-extractor.service.ts | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'client/src/app/core/rest/rest-extractor.service.ts') diff --git a/client/src/app/core/rest/rest-extractor.service.ts b/client/src/app/core/rest/rest-extractor.service.ts index 29a56ba39..dd4a78de5 100644 --- a/client/src/app/core/rest/rest-extractor.service.ts +++ b/client/src/app/core/rest/rest-extractor.service.ts @@ -13,15 +13,16 @@ export class RestExtractor { return true } - applyToResultListData (result: ResultList, fun: Function, additionalArgs?: any[]): ResultList { + applyToResultListData ( + result: ResultList, + fun: (data: T, ...args: A[]) => U, + additionalArgs: A[] = [] + ): ResultList { const data: T[] = result.data - const newData: T[] = [] - - data.forEach(d => newData.push(fun.apply(this, [ d ].concat(additionalArgs)))) return { total: result.total, - data: newData + data: data.map(d => fun.apply(this, [ d, ...additionalArgs ])) } } @@ -29,8 +30,10 @@ export class RestExtractor { return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert ]) } - convertDateToHuman (target: { [ id: string ]: string }, fieldsToConvert: string[]) { - fieldsToConvert.forEach(field => target[field] = dateToHuman(target[field])) + convertDateToHuman (target: any, fieldsToConvert: string[]) { + fieldsToConvert.forEach(field => { + target[field] = dateToHuman(target[field]) + }) return target } @@ -46,7 +49,7 @@ export class RestExtractor { errorMessage = err.error } else if (err.status !== undefined) { // A server-side error occurred. - if (err.error && err.error.errors) { + if (err.error?.errors) { const errors = err.error.errors const errorsArray: string[] = [] @@ -55,9 +58,10 @@ export class RestExtractor { }) errorMessage = errorsArray.join('. ') - } else if (err.error && err.error.error) { + } else if (err.error?.error) { errorMessage = err.error.error } else if (err.status === HttpStatusCode.PAYLOAD_TOO_LARGE_413) { + // eslint-disable-next-line max-len errorMessage = $localize`Media is too large for the server. Please contact you administrator if you want to increase the limit size.` } else if (err.status === HttpStatusCode.TOO_MANY_REQUESTS_429) { const secondsLeft = err.headers.get('retry-after') @@ -71,7 +75,7 @@ export class RestExtractor { errorMessage = $localize`Server error. Please retry later.` } - errorMessage = errorMessage ? errorMessage : 'Unknown error.' + errorMessage = errorMessage || 'Unknown error.' console.error(`Backend returned code ${err.status}, errorMessage is: ${errorMessage}`) } else { console.error(err) @@ -93,7 +97,7 @@ export class RestExtractor { } redirectTo404IfNotFound (obj: { status: number }, type: 'video' | 'other', status = [ HttpStatusCode.NOT_FOUND_404 ]) { - if (obj && obj.status && status.indexOf(obj.status) !== -1) { + if (obj?.status && status.includes(obj.status)) { // Do not use redirectService to avoid circular dependencies this.router.navigate([ '/404' ], { state: { type, obj }, skipLocationChange: true }) } -- cgit v1.2.3