From 955893e022457d267273071d16d08ac40f134ff1 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Tue, 6 Jan 2026 09:54:29 +0330 Subject: [PATCH] sms count --- .../controllers/notifications.controller.ts | 13 +++++++++++-- .../repositories/sms-log.repository.ts | 13 +++++++++++++ .../notifications/services/notification.service.ts | 4 ++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/modules/notifications/controllers/notifications.controller.ts b/src/modules/notifications/controllers/notifications.controller.ts index 934512e..71e5335 100644 --- a/src/modules/notifications/controllers/notifications.controller.ts +++ b/src/modules/notifications/controllers/notifications.controller.ts @@ -168,9 +168,18 @@ export class NotificationsController { return this.preferenceService.create(restaurantId, dto); } - //here + @UseGuards(AdminAuthGuard) + @ApiBearerAuth() + @Get('admin/notifications/sms-usage') + @ApiOperation({ summary: 'Get SMS usage for my restaurant' }) + async getRestaurantSmsUsage(@RestId() restaurantId: string) { + const smsCount = await this.notificationService.getSmsCountByRestaurantId(restaurantId); + return { smsCount }; + } - // @UseGuards(SuperAdminAuthGuard) + // super admin endpoints + + @UseGuards(SuperAdminAuthGuard) @ApiBearerAuth() @Get('super-admin/notifications/sms-count') @ApiOperation({ summary: 'Get SMS count for each restaurant with pagination' }) diff --git a/src/modules/notifications/repositories/sms-log.repository.ts b/src/modules/notifications/repositories/sms-log.repository.ts index 0b4f9cf..6076a29 100644 --- a/src/modules/notifications/repositories/sms-log.repository.ts +++ b/src/modules/notifications/repositories/sms-log.repository.ts @@ -59,5 +59,18 @@ export class SmsLogRepository extends EntityRepository { }, }; } + + async getSmsCountByRestaurantId(restaurantId: string): Promise { + const result = await this.em.execute( + ` + SELECT COUNT(sl.id)::int as "smsCount" + FROM sms_logs sl + WHERE sl.restaurant_id = ? + `, + [restaurantId], + ); + + return parseInt(result[0]?.smsCount || '0', 10); + } } diff --git a/src/modules/notifications/services/notification.service.ts b/src/modules/notifications/services/notification.service.ts index f7e9af1..6c7e243 100644 --- a/src/modules/notifications/services/notification.service.ts +++ b/src/modules/notifications/services/notification.service.ts @@ -275,4 +275,8 @@ export class NotificationService { ): Promise> { return this.smsLogRepository.getSmsCountByRestaurant(page, limit); } + + async getSmsCountByRestaurantId(restaurantId: string): Promise { + return this.smsLogRepository.getSmsCountByRestaurantId(restaurantId); + } }