mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
feat: Add SMS balance check before sending notifications to prevent low balance issues
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { IsBillingEnabled } from "../EnvironmentConfig";
|
||||
import CreateBy from "../Types/Database/CreateBy";
|
||||
import { OnCreate } from "../Types/Database/Hooks";
|
||||
import logger from "../Utils/Logger";
|
||||
@@ -33,6 +34,7 @@ export class Service extends DatabaseService<Model> {
|
||||
},
|
||||
select: {
|
||||
enableSmsNotifications: true,
|
||||
smsOrCallCurrentBalanceInUSDCents: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -46,6 +48,15 @@ export class Service extends DatabaseService<Model> {
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
(project.smsOrCallCurrentBalanceInUSDCents as number) <= 100 &&
|
||||
IsBillingEnabled
|
||||
) {
|
||||
throw new BadDataException(
|
||||
"Your SMS balance is low. Please recharge your SMS balance in Project Settings > Notification Settings.",
|
||||
);
|
||||
}
|
||||
|
||||
// Check if user already has a verified phone number for this project
|
||||
const existingVerifiedNumber: Model | null = await this.findOneBy({
|
||||
query: {
|
||||
@@ -116,6 +127,7 @@ export class Service extends DatabaseService<Model> {
|
||||
},
|
||||
select: {
|
||||
enableSmsNotifications: true,
|
||||
smsOrCallCurrentBalanceInUSDCents: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -129,6 +141,15 @@ export class Service extends DatabaseService<Model> {
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
(project.smsOrCallCurrentBalanceInUSDCents as number) <= 100 &&
|
||||
IsBillingEnabled
|
||||
) {
|
||||
throw new BadDataException(
|
||||
"Your SMS balance is low. Please recharge your SMS balance in Project Settings > Notification Settings.",
|
||||
);
|
||||
}
|
||||
|
||||
// Generate new verification code
|
||||
item.verificationCode = Text.generateRandomNumber(6);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user