From 3ce839bbd507a6c1731ac6b9ffb61075a850cde9 Mon Sep 17 00:00:00 2001 From: isra el Date: Tue, 14 May 2024 04:44:59 +0300 Subject: [PATCH] fix(api): throw exception if message is blank or invalid recipients provided --- api/src/gateway/gateway.service.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/api/src/gateway/gateway.service.ts b/api/src/gateway/gateway.service.ts index b2e1c7d..74bc90f 100644 --- a/api/src/gateway/gateway.service.ts +++ b/api/src/gateway/gateway.service.ts @@ -103,6 +103,26 @@ export class GatewayService { const message = smsData.message || smsData.smsBody const recipients = smsData.recipients || smsData.receivers + if (!message) { + throw new HttpException( + { + success: false, + error: 'Invalid message', + }, + HttpStatus.BAD_REQUEST, + ) + } + + if (!Array.isArray(recipients) || recipients.length === 0) { + throw new HttpException( + { + success: false, + error: 'Invalid recipients', + }, + HttpStatus.BAD_REQUEST, + ) + } + // TODO: Implement a queue to send the SMS if recipients are too many let smsBatch: SMSBatch