diff --git a/CommonServer/API/NotificationAPI.ts b/CommonServer/API/NotificationAPI.ts index 4f508a4601..c7455e540c 100644 --- a/CommonServer/API/NotificationAPI.ts +++ b/CommonServer/API/NotificationAPI.ts @@ -12,6 +12,7 @@ import ObjectID from 'Common/Types/ObjectID'; import JSONFunctions from 'Common/Types/JSONFunctions'; import Permission, { UserPermission } from 'Common/Types/Permission'; import Exception from 'Common/Types/Exception/Exception'; +import PositiveNumber from 'Common/Types/PositiveNumber'; const router: ExpressRouter = Express.getRouter(); @@ -20,7 +21,19 @@ router.post( UserMiddleware.getUserMiddleware, async (req: ExpressRequest, res: ExpressResponse) => { try { - const amount: number = req.body.amount; + let amount: number | PositiveNumber = + JSONFunctions.deserializeValue(req.body.amount) as + | number + | PositiveNumber; + + if (amount instanceof PositiveNumber) { + amount = amount.toNumber(); + } + + if (typeof amount === 'string') { + amount = parseInt(amount); + } + const projectId: ObjectID = JSONFunctions.deserializeValue( req.body.projectId ) as ObjectID; @@ -97,6 +110,8 @@ router.post( } catch (err: any) { return Response.sendErrorResponse(req, res, err as Exception); } + + return Response.sendEmptyResponse(req, res); } ); diff --git a/Dashboard/src/Pages/Settings/CallSms.tsx b/Dashboard/src/Pages/Settings/CallSms.tsx index 809d6c4b75..fcd599b7bc 100644 --- a/Dashboard/src/Pages/Settings/CallSms.tsx +++ b/Dashboard/src/Pages/Settings/CallSms.tsx @@ -17,6 +17,8 @@ import { JSONObject } from 'Common/Types/JSON'; import API from 'CommonUI/src/Utils/API/API'; import URL from 'Common/Types/API/URL'; import Navigation from 'CommonUI/src/Utils/Navigation'; +import HTTPResponse from 'Common/Types/API/HTTPResponse'; +import HTTPErrorResponse from 'Common/Types/API/HTTPErrorResponse'; const Settings: FunctionComponent = ( _props: PageComponentProps @@ -69,6 +71,8 @@ const Settings: FunctionComponent = ( icon: IconProp.Add, onClick: () => { setShowRechargeBalanceModal(true); + setRechargeBalanceError(null); + setIsRechargeBalanceLoading(false); }, }, ], @@ -336,7 +340,9 @@ const Settings: FunctionComponent = ( onSubmit={async (item: JSONObject) => { setIsRechargeBalanceLoading(true); try { - await API.post( + const response: + | HTTPResponse + | HTTPErrorResponse = await API.post( URL.fromString( DASHBOARD_API_URL.toString() ).addRoute('/notification/recharge'), @@ -346,9 +352,17 @@ const Settings: FunctionComponent = ( DashboardNavigation.getProjectId()?.toString(), } ); - setIsRechargeBalanceLoading(false); - setShowRechargeBalanceModal(false); - Navigation.reload(); + + if (response.isFailure()) { + setRechargeBalanceError( + API.getFriendlyMessage(response) + ); + setIsRechargeBalanceLoading(false); + } else { + setIsRechargeBalanceLoading(false); + setShowRechargeBalanceModal(false); + Navigation.reload(); + } } catch (e) { setRechargeBalanceError(API.getFriendlyMessage(e)); setIsRechargeBalanceLoading(false); @@ -369,7 +383,7 @@ const Settings: FunctionComponent = ( minValue: 20, maxValue: 1000, }, - fieldType: FormFieldSchemaType.PositveNumber, + fieldType: FormFieldSchemaType.Number, }, ], }}