From eaf93f43b00e52cd3393411e9210f49e062bf2a9 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Tue, 27 Feb 2024 16:36:27 +0000 Subject: [PATCH] Refactor code and fix formatting issues --- Common/Types/Database/UniqueColumnBy.ts | 8 ++++++-- CommonServer/Utils/BasicCron.ts | 15 +++++---------- CommonServer/Utils/Express.ts | 2 +- CommonServer/Utils/LocalFile.ts | 6 +++--- .../Components/HeaderAlert/HeaderModelAlert.tsx | 1 - .../Components/ModelProgress/ModelProgress.tsx | 2 -- CommonUI/src/Tests/Components/Card.test.tsx | 4 +++- 7 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Common/Types/Database/UniqueColumnBy.ts b/Common/Types/Database/UniqueColumnBy.ts index 62476058518..06f2ce30633 100644 --- a/Common/Types/Database/UniqueColumnBy.ts +++ b/Common/Types/Database/UniqueColumnBy.ts @@ -14,7 +14,9 @@ type GetUniqueColumnByFunction = ( propertyKey: string ) => string; -export const getUniqueColumnBy: GetUniqueColumnByFunction = ( +export const getUniqueColumnBy: GetUniqueColumnByFunction = < + T extends BaseModel +>( target: T, propertyKey: string ): string => { @@ -25,7 +27,9 @@ type GetUniqueColumnsByFunction = ( target: T ) => Dictionary; -export const getUniqueColumnsBy: GetUniqueColumnsByFunction = ( +export const getUniqueColumnsBy: GetUniqueColumnsByFunction = < + T extends BaseModel +>( target: T ): Dictionary => { const dictonary: Dictionary = {}; diff --git a/CommonServer/Utils/BasicCron.ts b/CommonServer/Utils/BasicCron.ts index b3d8caa36f5..ffc01800f86 100644 --- a/CommonServer/Utils/BasicCron.ts +++ b/CommonServer/Utils/BasicCron.ts @@ -7,18 +7,13 @@ type BasicCronProps = { options: { schedule: string; runOnStartup: boolean; - }, - runFunction: PromiseVoidFunction -} - -type BasicCronFunction = ( - props: BasicCronProps -) => void; + }; + runFunction: PromiseVoidFunction; +}; -const BasicCron: BasicCronFunction = ( - props: BasicCronProps -): void => { +type BasicCronFunction = (props: BasicCronProps) => void; +const BasicCron: BasicCronFunction = (props: BasicCronProps): void => { const { jobName, options, runFunction } = props; cron.schedule(options.schedule, async () => { diff --git a/CommonServer/Utils/Express.ts b/CommonServer/Utils/Express.ts index 6c1a6b9f802..7a5aef101df 100644 --- a/CommonServer/Utils/Express.ts +++ b/CommonServer/Utils/Express.ts @@ -81,7 +81,7 @@ class Express { type ResolveFunction = (app: express.Application) => void; - return new Promise((resolve:ResolveFunction) => { + return new Promise((resolve: ResolveFunction) => { this.httpServer.listen( port?.toNumber() || this.app.get('port'), () => { diff --git a/CommonServer/Utils/LocalFile.ts b/CommonServer/Utils/LocalFile.ts index 6af46f52ee8..0669c53a08d 100644 --- a/CommonServer/Utils/LocalFile.ts +++ b/CommonServer/Utils/LocalFile.ts @@ -1,11 +1,11 @@ import fs from 'fs'; -import {PromiseRejectErrorFunction} from 'Common/Types/FunctionTypes'; +import { PromiseRejectErrorFunction } from 'Common/Types/FunctionTypes'; export default class LocalFile { public static async makeDirectory(path: string): Promise { return new Promise( (resolve: Function, reject: PromiseRejectErrorFunction) => { - fs.mkdir(path, { recursive: true }, (err: Error | null) => { + fs.mkdir(path, { recursive: true }, (err: Error | null) => { if (err) { return reject(err); } @@ -18,7 +18,7 @@ export default class LocalFile { public static async write(path: string, data: string): Promise { return new Promise( (resolve: Function, reject: PromiseRejectErrorFunction) => { - fs.writeFile(path, data, (err: Error | null) => { + fs.writeFile(path, data, (err: Error | null) => { if (err) { return reject(err); } diff --git a/CommonUI/src/Components/HeaderAlert/HeaderModelAlert.tsx b/CommonUI/src/Components/HeaderAlert/HeaderModelAlert.tsx index c8c2797adc3..bfceed48bac 100644 --- a/CommonUI/src/Components/HeaderAlert/HeaderModelAlert.tsx +++ b/CommonUI/src/Components/HeaderAlert/HeaderModelAlert.tsx @@ -36,7 +36,6 @@ const HeaderModelAlert: ( }, [props.refreshToggle]); const fetchCount: PromiseVoidFunction = async (): Promise => { - setError(''); setIsLoading(true); diff --git a/CommonUI/src/Components/ModelProgress/ModelProgress.tsx b/CommonUI/src/Components/ModelProgress/ModelProgress.tsx index f50d9fe50d2..61295760637 100644 --- a/CommonUI/src/Components/ModelProgress/ModelProgress.tsx +++ b/CommonUI/src/Components/ModelProgress/ModelProgress.tsx @@ -45,11 +45,9 @@ const ModelProgress: ( }; useEffect(() => { - fetchCount().catch((err: Error) => { setError(API.getFriendlyMessage(err)); }); - }, []); return ( diff --git a/CommonUI/src/Tests/Components/Card.test.tsx b/CommonUI/src/Tests/Components/Card.test.tsx index 6a5f2d04d8b..052cbd8d81a 100644 --- a/CommonUI/src/Tests/Components/Card.test.tsx +++ b/CommonUI/src/Tests/Components/Card.test.tsx @@ -16,7 +16,9 @@ describe('Card', () => { type RenderComponentFunction = (props: ComponentProps) => void; - const renderComponent: RenderComponentFunction = (props: ComponentProps): void => { + const renderComponent: RenderComponentFunction = ( + props: ComponentProps + ): void => { render(); };