Skip to content

Commit

Permalink
Add PromiseVoidFunction import to multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Feb 27, 2024
1 parent eaf93f4 commit af44b4d
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Accounts/Serve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import App from 'CommonServer/Utils/StartServer';

import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';
import Express, { ExpressApplication } from 'CommonServer/Utils/Express';
import logger from 'CommonServer/Utils/Logger';

Expand Down
1 change: 1 addition & 0 deletions Accounts/src/Pages/VerifyEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Navigation from 'CommonUI/src/Utils/Navigation';
import ObjectID from 'Common/Types/ObjectID';
import URL from 'Common/Types/API/URL';
import API from 'CommonUI/src/Utils/API/API';
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';

const VerifyEmail: () => JSX.Element = () => {
const apiUrl: URL = VERIFY_EMAIL_API_URL;
Expand Down
1 change: 1 addition & 0 deletions AdminDashboard/Serve.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import App from 'CommonServer/Utils/StartServer';
import Express, { ExpressApplication } from 'CommonServer/Utils/Express';
import logger from 'CommonServer/Utils/Logger';
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';

export const APP_NAME: string = 'admin';

Expand Down
1 change: 1 addition & 0 deletions AdminDashboard/src/Components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BadDataException from 'Common/Types/Exception/BadDataException';
import ConfirmModal from 'CommonUI/src/Components/Modal/ConfirmModal';
import Dictionary from 'Common/Types/Dictionary';
import HTTPResponse from 'Common/Types/API/HTTPResponse';
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';

const DashboardFooter: () => JSX.Element = () => {
const [showAboutModal, setShowAboutModal] = React.useState<boolean>(false);
Expand Down
1 change: 1 addition & 0 deletions AdminDashboard/src/Pages/Settings/SMTP/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { JSONObject } from 'Common/Types/JSON';
import DropdownUtil from 'CommonUI/src/Utils/Dropdown';
import Pill from 'CommonUI/src/Components/Pill/Pill';
import { Green, Red } from 'Common/Types/BrandColors';
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';

const Settings: FunctionComponent = (): ReactElement => {
const [emailServerType, setemailServerType] =
Expand Down
4 changes: 3 additions & 1 deletion App/FeatureSet/Notification/API/Mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ router.post(
}
);

const hasMailServerSettingsInBody: Function = (body: JSONObject): boolean => {
type HasMailServerSettingsInBody = (body: JSONObject) => boolean;

const hasMailServerSettingsInBody: HasMailServerSettingsInBody = (body: JSONObject): boolean => {
return (
body &&
Object.keys(body).filter((key: string) => {
Expand Down
16 changes: 12 additions & 4 deletions App/FeatureSet/Notification/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const InternalSmtpEmail: Email = new Email(
export const InternalSmtpFromName: string =
process.env['INTERNAL_SMTP_FROM_NAME'] || 'OneUptime';

export const getGlobalSMTPConfig: Function =
type GetGlobalSMTPConfig = () => Promise<EmailServer | null>;

export const getGlobalSMTPConfig: GetGlobalSMTPConfig =
async (): Promise<EmailServer | null> => {
const globalConfig: GlobalConfig | null =
await GlobalConfigService.findOneBy({
Expand Down Expand Up @@ -71,7 +73,9 @@ export const getGlobalSMTPConfig: Function =
};
};

export const getEmailServerType: Function =
type GetEmailServerTypeFunction = () => Promise<EmailServerType>;

export const getEmailServerType: GetEmailServerTypeFunction =
async (): Promise<EmailServerType> => {
const globalConfig: GlobalConfig | null =
await GlobalConfigService.findOneBy({
Expand Down Expand Up @@ -99,7 +103,9 @@ export interface SendGridConfig {
fromEmail: Email;
}

export const getSendgridConfig: Function =
type GetSendgridConfigFunction = () => Promise<SendGridConfig | null>;

export const getSendgridConfig: GetSendgridConfigFunction =
async (): Promise<SendGridConfig | null> => {
const globalConfig: GlobalConfig | null =
await GlobalConfigService.findOneBy({
Expand Down Expand Up @@ -135,7 +141,9 @@ export const getSendgridConfig: Function =
return null;
};

export const getTwilioConfig: Function =
type GetTwilioConfigFunction = () => Promise<TwilioConfig | null>;

export const getTwilioConfig: GetTwilioConfigFunction =
async (): Promise<TwilioConfig | null> => {
const globalConfig: GlobalConfig | null =
await GlobalConfigService.findOneBy({
Expand Down
3 changes: 2 additions & 1 deletion App/FeatureSet/Workers/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import AnalyticsTableManagement from './Utils/AnalyticsDatabase/TableManegement'

import './Jobs/Workflow/TimeoutJobs';
import './Jobs/MeteredPlan/ReportTelemetryMeteredPlan';
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';

const APP_NAME: string = 'api/workers';

Expand Down Expand Up @@ -101,7 +102,7 @@ const WorkersFeatureSet: FeatureSet = {

logger.info('Running Job: ' + name);

const funcToRun: Function =
const funcToRun: PromiseVoidFunction =
JobDictionary.getJobFunction(name);

if (funcToRun) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ RunCron(
}
);

const shouldProcessRequest: Function = (monitor: Monitor): boolean => {
type ShouldProcessRequestFunction = (monitor: Monitor) => boolean;

const shouldProcessRequest: ShouldProcessRequestFunction = (monitor: Monitor): boolean => {
// check if any criteria has request time step. If yes, then process the request. If no then skip the request.
// We dont want Incoming Request Monitor to process the request if there is no criteria that checks for incoming request.
// Those monitors criteria should be checked if the request is receievd from the API and not through the worker.
Expand Down
9 changes: 5 additions & 4 deletions App/FeatureSet/Workers/Utils/JobDictionary.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import Dictionary from 'Common/Types/Dictionary';
import BadDataException from 'Common/Types/Exception/BadDataException';
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';

export default class JobDictionary {
private static dictionary: Dictionary<Function> = {};
private static dictionary: Dictionary<PromiseVoidFunction> = {};

public static getJobFunction(name: string): Function {
public static getJobFunction(name: string): PromiseVoidFunction {
if (this.dictionary[name]) {
return this.dictionary[name] as Function;
return this.dictionary[name] as PromiseVoidFunction;
}

throw new BadDataException('No job found with name: ' + name);
}

public static setJobFunction(name: string, job: Function): void {
public static setJobFunction(name: string, job: PromiseVoidFunction): void {
this.dictionary[name] = job;
}
}

0 comments on commit af44b4d

Please sign in to comment.