Resolve "Transition to ESLint"

This commit is contained in:
Thea Schöbl
2022-06-27 14:40:09 +00:00
committed by Rainer Killinger
parent ca1d2444e0
commit 418ba67d15
47 changed files with 1854 additions and 1634 deletions

View File

@@ -29,7 +29,6 @@ export type BulkOperation = 'create' | 'expired' | 'update';
* Describes an indexing process
*/
export class Bulk implements SCBulkRequest {
/**
* Expiration of the bulk
*
@@ -70,19 +69,15 @@ export class Bulk implements SCBulkRequest {
/**
* Creates a new bulk process
*
* @param request Data needed for requesting a bulk
*/
constructor(request: SCBulkRequest) {
this.uid = v4();
this.state = 'in progress';
if (typeof request.expiration === 'string') {
this.expiration = request.expiration;
} else {
this.expiration = moment()
.add(1, 'hour')
.toISOString();
}
this.expiration =
typeof request.expiration === 'string' ? request.expiration : moment().add(1, 'hour').toISOString();
// when should this process be finished
// where does the process come from
this.source = request.source;
@@ -102,10 +97,10 @@ export class BulkStorage {
/**
* Creates a new BulkStorage
*
* @param database the database that is controlled by this bulk storage
*/
constructor(public database: Database) {
// a bulk lives 60 minutes if no expiration is given
// the cache is checked every 60 seconds
this.cache = new NodeCache({stdTTL: 3600, checkperiod: 60});
@@ -121,13 +116,12 @@ export class BulkStorage {
/**
* Saves a bulk process and assigns to it a user-defined ttl (time-to-live)
*
* @param bulk the bulk process to save
* @returns the bulk process that was saved
*/
private save(bulk: Bulk): Bulk {
const expirationInSeconds = moment(bulk.expiration)
// tslint:disable-next-line: no-magic-numbers
.diff(moment.now()) / 1000;
const expirationInSeconds = moment(bulk.expiration).diff(moment.now()) / 1000;
Logger.info('Bulk expires in ', expirationInSeconds, 'seconds');
// save the item in the cache with it's expected expiration
@@ -138,6 +132,7 @@ export class BulkStorage {
/**
* Create and save a new bulk process
*
* @param bulkRequest a request for a new bulk process
* @returns a promise that contains the new bulk process
*/
@@ -156,6 +151,7 @@ export class BulkStorage {
/**
* Delete a bulk process
*
* @param uid uid of the bulk process
* @returns a promise that contains the deleted bulk process
*/
@@ -163,7 +159,7 @@ export class BulkStorage {
const bulk = this.read(uid);
if (typeof bulk === 'undefined') {
throw new Error(`Bulk that should be deleted was not found. UID was "${uid}"`);
throw new TypeError(`Bulk that should be deleted was not found. UID was "${uid}"`);
}
// delete the bulk process from the cache
@@ -177,6 +173,7 @@ export class BulkStorage {
/**
* Update an old bulk process (replace it with the new one)
*
* @param bulk new bulk process
* @returns an empty promise
*/
@@ -192,11 +189,11 @@ export class BulkStorage {
/**
* Read an existing bulk process
*
* @param uid uid of the bulk process
* @returns a promise that contains a bulk
*/
public read(uid: string): Bulk | undefined {
return this.cache.get(uid);
}
}