diff --git a/helpers/ArchiveHelper.ts b/helpers/ArchiveHelper.ts index 61042990da04b1b7c88dd3144f3b6cf7843af48f..f4449d6e8f4953227e0b422bb0a647a85432351c 100644 --- a/helpers/ArchiveHelper.ts +++ b/helpers/ArchiveHelper.ts @@ -41,7 +41,7 @@ class ArchiveHelper { } public async getBase64(folderPath: string): Promise<string> { - let data: any; + let data: string; const tarDataStream = new stream.Writable({ write(this: Writable, chunk: Buffer, _encoding: BufferEncoding, next: (error?: Error | null) => void) { if ( data ) { @@ -55,9 +55,9 @@ class ArchiveHelper { await this.compress(folderPath, tarDataStream); - await (new Promise((resolve, reject) => { + data = await (new Promise((resolve) => { tarDataStream.on('close', () => { - resolve(0); + resolve(data); }); })); diff --git a/helpers/Dojo/SharedAssignmentHelper.ts b/helpers/Dojo/SharedAssignmentHelper.ts index f17bef93eb6575bc92308099636fb757c66a75b3..94e50051bbb79fcc7ddb20619f8ac34b183cf4ae 100644 --- a/helpers/Dojo/SharedAssignmentHelper.ts +++ b/helpers/Dojo/SharedAssignmentHelper.ts @@ -48,7 +48,7 @@ class SharedAssignmentHelper { const isValid = validator(results); return { - results: isValid ? results : results as any, + results: isValid ? results : results as AssignmentFile, isValid: isValid, errors : validator.errors }; diff --git a/helpers/Dojo/SharedExerciseHelper.ts b/helpers/Dojo/SharedExerciseHelper.ts index 6f81054e28fe1008bdb47f40b2b767434df2504e..e99fe0a302e41a28df5cafab292974b2fdb96b43 100644 --- a/helpers/Dojo/SharedExerciseHelper.ts +++ b/helpers/Dojo/SharedExerciseHelper.ts @@ -5,7 +5,7 @@ import JSON5 from 'json5'; class SharedExerciseHelper { - validateResultFile(resultsFilePathOrStr: string, isFile: boolean = true): { results: ExerciseResultsFile | undefined, isValid: boolean, errors: Array<ErrorObject<string, Record<string, any>, unknown> | string> | null | undefined } { + validateResultFile(resultsFilePathOrStr: string, isFile: boolean = true): { results: ExerciseResultsFile | undefined, isValid: boolean, errors: Array<ErrorObject | string> | null | undefined } { const ajv = new Ajv(); const schema: JTDSchemaType<ExerciseResultsFile> = { @@ -49,7 +49,7 @@ class SharedExerciseHelper { } return { - results: isValid ? results : results as any, + results: isValid ? results : results as ExerciseResultsFile, isValid: isValid, errors : validator.errors }; diff --git a/helpers/LazyVal.ts b/helpers/LazyVal.ts index ee0d8d464b0e99ea790ac9326868c3275745c226..4613c4b535706f5853b060279ce46a957e3c3030 100644 --- a/helpers/LazyVal.ts +++ b/helpers/LazyVal.ts @@ -4,12 +4,15 @@ class LazyVal<T> { constructor(private valLoader: () => Promise<T> | T) {} get value(): Promise<T> { - return new Promise<T>(async (resolve) => { + return new Promise<T>((resolve) => { if ( this.val === undefined ) { - this.val = await this.valLoader(); + Promise.resolve(this.valLoader()).then((value: T) => { + this.val = value; + resolve(value); + }); + } else { + resolve(this.val); } - - resolve(this.val); }); } diff --git a/helpers/Toolbox.ts b/helpers/Toolbox.ts index f1b3974e247fe33d1a3f76ab46cfa81f2ec50227..8a76bebb202e6bcbe46944e562924effdeb26afe 100644 --- a/helpers/Toolbox.ts +++ b/helpers/Toolbox.ts @@ -11,7 +11,7 @@ class Toolbox { Source of getAllFiles and getTotalSize (modified for this project): https://coderrocketfuel.com/article/get-the-total-size-of-all-files-in-a-directory-using-node-js */ private async getAllFiles(dirPath: string, arrayOfFiles: Array<string> = []): Promise<Array<string>> { - let files = await fs.readdir(dirPath); + const files = await fs.readdir(dirPath); await Promise.all(files.map(async file => { if ( (await fs.stat(dirPath + '/' + file)).isDirectory() ) { @@ -22,7 +22,7 @@ class Toolbox { })); return arrayOfFiles; - }; + } private async getTotalSize(directoryPath: string): Promise<number> { const arrayOfFiles = await this.getAllFiles(directoryPath); @@ -34,7 +34,7 @@ class Toolbox { } return totalSize; - }; + } get fs() { return { diff --git a/helpers/TypeScriptExtensions.ts b/helpers/TypeScriptExtensions.ts index c5093d859f552e7f28068f8883d2ffba82fb6e71..fd730ad37daa50a1b6e855efaf3c48ce739faa05 100644 --- a/helpers/TypeScriptExtensions.ts +++ b/helpers/TypeScriptExtensions.ts @@ -1,6 +1,11 @@ declare global { + interface BigInt { + toJSON: () => string; + } + + interface Array<T> { - removeObjectDuplicates: (getProperty: (item: T) => any) => Array<T>; + removeObjectDuplicates: (getProperty: (item: T) => unknown) => Array<T>; } @@ -22,15 +27,15 @@ function registerAll() { } function registerBigIntJson() { - (BigInt.prototype as any).toJSON = function () { + BigInt.prototype.toJSON = function () { return this.toString(); }; } function registerArrayRemoveObjectDuplicates() { - Array.prototype.removeObjectDuplicates = function <T>(this: Array<T>, getProperty: (item: T) => any): Array<T> { + Array.prototype.removeObjectDuplicates = function <T>(this: Array<T>, getProperty: (item: T) => unknown): Array<T> { return this.reduce((accumulator: Array<T>, current: T) => { - if ( !accumulator.find((item: any) => getProperty(item) === getProperty(current)) ) { + if ( !accumulator.find((item: T) => getProperty(item) === getProperty(current)) ) { accumulator.push(current); } return accumulator; diff --git a/helpers/recursiveFilesStats/RecursiveFilesStats.ts b/helpers/recursiveFilesStats/RecursiveFilesStats.ts index 5a97fda8bd22ad08ff0e5f252c895a2b07aec22a..a571aaac797de782ee6bc95d33ad9e75ee03b647 100644 --- a/helpers/recursiveFilesStats/RecursiveFilesStats.ts +++ b/helpers/recursiveFilesStats/RecursiveFilesStats.ts @@ -131,7 +131,7 @@ class RecursiveFilesStats { } return stat; - }; + } /** * Get ext diff --git a/managers/SharedGitlabManager.ts b/managers/SharedGitlabManager.ts index aca93d0f667d9635b3ac1e4e0e4f66fb1fdc6ffc..68ff699a036044872cb7f33ead08782afbbdb830 100644 --- a/managers/SharedGitlabManager.ts +++ b/managers/SharedGitlabManager.ts @@ -11,20 +11,16 @@ class GitlabManager { } async getTokens(codeOrRefresh: string, isRefresh: boolean = false, clientSecret: string = ''): Promise<GitlabToken> { - try { - const response = await axios.post<GitlabToken>(SharedConfig.login.gitlab.url.token, { - client_id : SharedConfig.login.gitlab.client.id, - client_secret: clientSecret, - grant_type : isRefresh ? 'refresh_token' : 'authorization_code', - refresh_token: codeOrRefresh, - code : codeOrRefresh, - redirect_uri : SharedConfig.login.gitlab.url.redirect - }); - - return response.data; - } catch ( error ) { - throw error; - } + const response = await axios.post<GitlabToken>(SharedConfig.login.gitlab.url.token, { + client_id : SharedConfig.login.gitlab.client.id, + client_secret: clientSecret, + grant_type : isRefresh ? 'refresh_token' : 'authorization_code', + refresh_token: codeOrRefresh, + code : codeOrRefresh, + redirect_uri : SharedConfig.login.gitlab.url.redirect + }); + + return response.data; } async getRepositoryPipelines(repoId: number, branch: string = 'main'): Promise<Array<GitlabPipeline>> { diff --git a/types/Gitlab/GitlabRoute.ts b/types/Gitlab/GitlabRoute.ts index ec5f0d89fa542c4d3c0d9c08806455fd5ad55d44..76c3a80b04c0d72abcaa7821037ca146f993faff 100644 --- a/types/Gitlab/GitlabRoute.ts +++ b/types/Gitlab/GitlabRoute.ts @@ -3,8 +3,8 @@ enum GitlabRoute { PROFILE_GET = '/user', USERS_GET = '/users', REPOSITORY_GET = '/projects/{{id}}', - REPOSITORY_CREATE = '/projects', - REPOSITORY_DELETE = '/projects/{{id}}', + REPOSITORY_CREATE = '/projects', // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values + REPOSITORY_DELETE = '/projects/{{id}}', // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values REPOSITORY_EDIT = '/projects/{{id}}', REPOSITORY_FORK = '/projects/{{id}}/fork', REPOSITORY_MEMBER_ADD = '/projects/{{id}}/members',