mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
Refactor code formatting and remove unnecessary whitespace
This commit is contained in:
@@ -1,31 +1,34 @@
|
||||
import BadDataException from "./Exception/BadDataException";
|
||||
import BadDataException from './Exception/BadDataException';
|
||||
|
||||
export default class Currency {
|
||||
public static convertToDecimalPlaces(value: number, decimalPlaces: number = 2): number {
|
||||
|
||||
if(decimalPlaces < 0) {
|
||||
throw new BadDataException("decimalPlaces must be greater than or equal to 0.");
|
||||
public static convertToDecimalPlaces(
|
||||
value: number,
|
||||
decimalPlaces: number = 2
|
||||
): number {
|
||||
if (decimalPlaces < 0) {
|
||||
throw new BadDataException(
|
||||
'decimalPlaces must be greater than or equal to 0.'
|
||||
);
|
||||
}
|
||||
|
||||
if(typeof value === "string"){
|
||||
if (typeof value === 'string') {
|
||||
value = parseFloat(value);
|
||||
}
|
||||
|
||||
if(decimalPlaces === 0){
|
||||
if (decimalPlaces === 0) {
|
||||
return Math.ceil(value);
|
||||
}
|
||||
|
||||
value = value * Math.pow(10, decimalPlaces);
|
||||
|
||||
// convert to int.
|
||||
// convert to int.
|
||||
|
||||
value = Math.round(value);
|
||||
|
||||
|
||||
// convert back to float.
|
||||
|
||||
value = value / Math.pow(10, decimalPlaces);
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,35 @@
|
||||
import BadDataException from "./Exception/BadDataException";
|
||||
import BadDataException from './Exception/BadDataException';
|
||||
|
||||
export default class DiskSize {
|
||||
|
||||
public static convertToDecimalPlaces(value: number, decimalPlaces: number = 2): number {
|
||||
|
||||
if(decimalPlaces < 0) {
|
||||
throw new BadDataException("decimalPlaces must be greater than or equal to 0.");
|
||||
public static convertToDecimalPlaces(
|
||||
value: number,
|
||||
decimalPlaces: number = 2
|
||||
): number {
|
||||
if (decimalPlaces < 0) {
|
||||
throw new BadDataException(
|
||||
'decimalPlaces must be greater than or equal to 0.'
|
||||
);
|
||||
}
|
||||
|
||||
if(typeof value === "string"){
|
||||
if (typeof value === 'string') {
|
||||
value = parseFloat(value);
|
||||
}
|
||||
|
||||
|
||||
if(decimalPlaces === 0){
|
||||
if (decimalPlaces === 0) {
|
||||
return Math.ceil(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
value = value * Math.pow(10, decimalPlaces);
|
||||
|
||||
// convert to int.
|
||||
// convert to int.
|
||||
|
||||
value = Math.round(value);
|
||||
|
||||
|
||||
// convert back to float.
|
||||
|
||||
value = value / Math.pow(10, decimalPlaces);
|
||||
|
||||
return value;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static byteSizeToGB(byteSize: number): number {
|
||||
@@ -46,4 +43,4 @@ export default class DiskSize {
|
||||
public static byteSizeToKB(byteSize: number): number {
|
||||
return byteSize / 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ export default class ObjectID extends DatabaseProperty {
|
||||
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public get value() : string {
|
||||
|
||||
public get value(): string {
|
||||
return this._id.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
|
||||
const IsBillingEnabled: boolean =
|
||||
process.env['BILLING_ENABLED'] === 'true';
|
||||
const IsBillingEnabled: boolean = process.env['BILLING_ENABLED'] === 'true';
|
||||
const BillingPublicKey: string = process.env['BILLING_PUBLIC_KEY'] || '';
|
||||
const BillingPrivateKey: string =
|
||||
process.env['BILLING_PRIVATE_KEY'] || '';
|
||||
|
||||
const BillingPrivateKey: string = process.env['BILLING_PRIVATE_KEY'] || '';
|
||||
|
||||
export default {
|
||||
IsBillingEnabled,
|
||||
BillingPublicKey,
|
||||
BillingPrivateKey,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,9 +10,8 @@ export const getAllEnvVars: () => JSONObject = (): JSONObject => {
|
||||
};
|
||||
|
||||
export const IsBillingEnabled: boolean = BillingConfig.IsBillingEnabled;
|
||||
export const BillingPublicKey: string = BillingConfig.BillingPublicKey;;
|
||||
export const BillingPrivateKey: string =
|
||||
BillingConfig.BillingPrivateKey;
|
||||
export const BillingPublicKey: string = BillingConfig.BillingPublicKey;
|
||||
export const BillingPrivateKey: string = BillingConfig.BillingPrivateKey;
|
||||
|
||||
export const DatabaseHost: Hostname = Hostname.fromString(
|
||||
process.env['DATABASE_HOST'] || 'postgres'
|
||||
@@ -62,42 +61,50 @@ export const ClusterKey: ObjectID = new ObjectID(
|
||||
export const HasClusterKey: boolean = Boolean(process.env['ONEUPTIME_SECRET']);
|
||||
|
||||
export const RealtimeHostname: Hostname = Hostname.fromString(
|
||||
`${process.env['SERVER_REALTIME_HOSTNAME'] || 'localhost'}:${process.env['REALTIME_PORT'] || 80
|
||||
`${process.env['SERVER_REALTIME_HOSTNAME'] || 'localhost'}:${
|
||||
process.env['REALTIME_PORT'] || 80
|
||||
}`
|
||||
);
|
||||
|
||||
export const WorkerHostname: Hostname = Hostname.fromString(
|
||||
`${process.env['SERVER_WORKERS_HOSTNAME'] || 'localhost'}:${process.env['WORKERS_PORT'] || 80
|
||||
`${process.env['SERVER_WORKERS_HOSTNAME'] || 'localhost'}:${
|
||||
process.env['WORKERS_PORT'] || 80
|
||||
}`
|
||||
);
|
||||
|
||||
export const WorkflowHostname: Hostname = Hostname.fromString(
|
||||
`${process.env['SERVER_WORKFLOW_HOSTNAME'] || 'localhost'}:${process.env['WORKFLOW_PORT'] || 80
|
||||
`${process.env['SERVER_WORKFLOW_HOSTNAME'] || 'localhost'}:${
|
||||
process.env['WORKFLOW_PORT'] || 80
|
||||
}`
|
||||
);
|
||||
|
||||
export const DashboardApiHostname: Hostname = Hostname.fromString(
|
||||
`${process.env['SERVER_DASHBOARD_API_HOSTNAME'] || 'localhost'}:${process.env['DASHBOARD_API_PORT'] || 80
|
||||
`${process.env['SERVER_DASHBOARD_API_HOSTNAME'] || 'localhost'}:${
|
||||
process.env['DASHBOARD_API_PORT'] || 80
|
||||
}`
|
||||
);
|
||||
|
||||
export const IngestorHostname: Hostname = Hostname.fromString(
|
||||
`${process.env['SERVER_INGESTOR_HOSTNAME'] || 'localhost'}:${process.env['INGESTOR_PORT'] || 80
|
||||
`${process.env['SERVER_INGESTOR_HOSTNAME'] || 'localhost'}:${
|
||||
process.env['INGESTOR_PORT'] || 80
|
||||
}`
|
||||
);
|
||||
|
||||
export const AccountsHostname: Hostname = Hostname.fromString(
|
||||
`${process.env['SERVER_ACCOUNTS_HOSTNAME'] || 'localhost'}:${process.env['ACCOUNTS_PORT'] || 80
|
||||
`${process.env['SERVER_ACCOUNTS_HOSTNAME'] || 'localhost'}:${
|
||||
process.env['ACCOUNTS_PORT'] || 80
|
||||
}`
|
||||
);
|
||||
|
||||
export const HomeHostname: Hostname = Hostname.fromString(
|
||||
`${process.env['SERVER_HOME_HOSTNAME'] || 'localhost'}:${process.env['HOME_PORT'] || 80
|
||||
`${process.env['SERVER_HOME_HOSTNAME'] || 'localhost'}:${
|
||||
process.env['HOME_PORT'] || 80
|
||||
}`
|
||||
);
|
||||
|
||||
export const DashboardHostname: Hostname = Hostname.fromString(
|
||||
`${process.env['SERVER_DASHBOARD_HOSTNAME'] || 'localhost'}:${process.env['DASHBOARD_PORT'] || 80
|
||||
`${process.env['SERVER_DASHBOARD_HOSTNAME'] || 'localhost'}:${
|
||||
process.env['DASHBOARD_PORT'] || 80
|
||||
}`
|
||||
);
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ export class Service extends DatabaseService<Model> {
|
||||
productType: ProductType;
|
||||
usageCount: number;
|
||||
}): Promise<void> {
|
||||
|
||||
const serverMeteredPlan: ServerMeteredPlan =
|
||||
MeteredPlanUtil.getServerMeteredPlanByProductType(data.productType);
|
||||
|
||||
|
||||
@@ -45,21 +45,24 @@ export default class TelemetryMeteredPlan extends ServerMeteredPlan {
|
||||
|
||||
// calculate all the total usage count and report it to billing provider.
|
||||
|
||||
let totalCostInUSD: number = 0;
|
||||
let totalCostInUSD: number = 0;
|
||||
|
||||
for (const usageBilling of usageBillings) {
|
||||
if (usageBilling?.totalCostInUSD && usageBilling?.totalCostInUSD > 0) {
|
||||
if (
|
||||
usageBilling?.totalCostInUSD &&
|
||||
usageBilling?.totalCostInUSD > 0
|
||||
) {
|
||||
totalCostInUSD += usageBilling.totalCostInUSD;
|
||||
}
|
||||
}
|
||||
|
||||
if(totalCostInUSD < 1){
|
||||
return; // too low to report.
|
||||
if (totalCostInUSD < 1) {
|
||||
return; // too low to report.
|
||||
}
|
||||
|
||||
// convert USD to cents.
|
||||
// convert USD to cents.
|
||||
|
||||
let totalCostInCents = totalCostInUSD * 100;
|
||||
let totalCostInCents: number = totalCostInUSD * 100;
|
||||
|
||||
// convert this to integer.
|
||||
|
||||
@@ -83,7 +86,6 @@ export default class TelemetryMeteredPlan extends ServerMeteredPlan {
|
||||
project.paymentProviderMeteredSubscriptionId) &&
|
||||
project.paymentProviderPlanId
|
||||
) {
|
||||
|
||||
await BillingService.addOrUpdateMeteredPricingOnSubscription(
|
||||
(options?.meteredPlanSubscriptionId as string) ||
|
||||
(project.paymentProviderMeteredSubscriptionId as string),
|
||||
@@ -91,12 +93,8 @@ export default class TelemetryMeteredPlan extends ServerMeteredPlan {
|
||||
totalCostInCents
|
||||
);
|
||||
|
||||
|
||||
for (const usageBilling of usageBillings) {
|
||||
if (
|
||||
usageBilling.id
|
||||
) {
|
||||
|
||||
if (usageBilling.id) {
|
||||
// now mark it as reported.
|
||||
|
||||
await UsageBillingService.updateOneById({
|
||||
|
||||
@@ -18,7 +18,7 @@ export class Statement implements BaseQueryParams {
|
||||
public constructor(
|
||||
private strings: string[] = [''],
|
||||
private values: Array<StatementParameter | string> = []
|
||||
) { }
|
||||
) {}
|
||||
|
||||
public get query(): string {
|
||||
let query: string = this.strings.reduce(
|
||||
@@ -47,7 +47,6 @@ export class Statement implements BaseQueryParams {
|
||||
}
|
||||
|
||||
public get query_params(): Record<string, unknown> {
|
||||
|
||||
return Object.fromEntries(
|
||||
this.values.map((v: StatementParameter | string, i: integer) => {
|
||||
let finalValue: any = v;
|
||||
|
||||
@@ -53,7 +53,8 @@ const Settings: FunctionComponent<ComponentProps> = (
|
||||
isViewable={false}
|
||||
cardProps={{
|
||||
title: 'Usage History',
|
||||
description: 'Here is the usage history for this project. Please refer to the pricing page for more details.',
|
||||
description:
|
||||
'Here is the usage history for this project. Please refer to the pricing page for more details.',
|
||||
}}
|
||||
noItemsMessage={
|
||||
'No usage history found. Maybe you have not used Telemetry features yet?'
|
||||
@@ -91,9 +92,9 @@ const Settings: FunctionComponent<ComponentProps> = (
|
||||
type: FieldType.Text,
|
||||
getElement: (item: JSONObject) => {
|
||||
return (
|
||||
<div>{`${DiskSize.convertToDecimalPlaces(item['usageCount'] as number)} ${
|
||||
item['usageUnitName'] as string
|
||||
}`}</div>
|
||||
<div>{`${DiskSize.convertToDecimalPlaces(
|
||||
item['usageCount'] as number
|
||||
)} ${item['usageUnitName'] as string}`}</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -105,9 +106,9 @@ const Settings: FunctionComponent<ComponentProps> = (
|
||||
type: FieldType.Text,
|
||||
getElement: (item: JSONObject) => {
|
||||
return (
|
||||
<div>{`${
|
||||
Currency.convertToDecimalPlaces(item['totalCostInUSD'] as number)
|
||||
} USD`}</div>
|
||||
<div>{`${Currency.convertToDecimalPlaces(
|
||||
item['totalCostInUSD'] as number
|
||||
)} USD`}</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
@@ -63,8 +63,6 @@ router.use(
|
||||
'/otel/*',
|
||||
async (req: ExpressRequest, _res: ExpressResponse, next: NextFunction) => {
|
||||
try {
|
||||
|
||||
|
||||
// size of req.body in bytes.
|
||||
const sizeInBytes: number = Buffer.byteLength(
|
||||
JSON.stringify(req.body)
|
||||
@@ -158,7 +156,7 @@ router.use(
|
||||
productType: productType,
|
||||
usageCount: sizeToGb,
|
||||
}).catch((err: Error) => {
|
||||
logger.error("Failed to update usage billing for OTel");
|
||||
logger.error('Failed to update usage billing for OTel');
|
||||
logger.error(err);
|
||||
});
|
||||
|
||||
|
||||
@@ -17,9 +17,11 @@ import Sleep from 'Common/Types/Sleep';
|
||||
|
||||
RunCron(
|
||||
'MeteredPlan:ReportTelemetryMeteredPlan',
|
||||
{ schedule: IsDevelopment ? EVERY_FIVE_MINUTE : EVERY_DAY, runOnStartup: true },
|
||||
{
|
||||
schedule: IsDevelopment ? EVERY_FIVE_MINUTE : EVERY_DAY,
|
||||
runOnStartup: true,
|
||||
},
|
||||
async () => {
|
||||
|
||||
if (!IsBillingEnabled) {
|
||||
logger.info(
|
||||
'MeteredPlan:ReportTelemetryMeteredPlan Billing is not enabled. Skipping job.'
|
||||
|
||||
Reference in New Issue
Block a user