sms count
This commit is contained in:
@@ -168,9 +168,18 @@ export class NotificationsController {
|
|||||||
return this.preferenceService.create(restaurantId, dto);
|
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()
|
@ApiBearerAuth()
|
||||||
@Get('super-admin/notifications/sms-count')
|
@Get('super-admin/notifications/sms-count')
|
||||||
@ApiOperation({ summary: 'Get SMS count for each restaurant with pagination' })
|
@ApiOperation({ summary: 'Get SMS count for each restaurant with pagination' })
|
||||||
|
|||||||
@@ -59,5 +59,18 @@ export class SmsLogRepository extends EntityRepository<SmsLog> {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSmsCountByRestaurantId(restaurantId: string): Promise<number> {
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -275,4 +275,8 @@ export class NotificationService {
|
|||||||
): Promise<PaginatedResult<{ restaurantId: string; restaurantName: string; smsCount: number }>> {
|
): Promise<PaginatedResult<{ restaurantId: string; restaurantName: string; smsCount: number }>> {
|
||||||
return this.smsLogRepository.getSmsCountByRestaurant(page, limit);
|
return this.smsLogRepository.getSmsCountByRestaurant(page, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSmsCountByRestaurantId(restaurantId: string): Promise<number> {
|
||||||
|
return this.smsLogRepository.getSmsCountByRestaurantId(restaurantId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user