From 61d564ddd1a054a25f2ffad6b44ba3617b91331e Mon Sep 17 00:00:00 2001 From: Dmitrijs Pavlovs Date: Mon, 18 Dec 2023 18:36:55 +0200 Subject: [PATCH] Cleanup --- apps/backend/src/services/bot.service.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/backend/src/services/bot.service.ts b/apps/backend/src/services/bot.service.ts index e2cc144..29b9443 100644 --- a/apps/backend/src/services/bot.service.ts +++ b/apps/backend/src/services/bot.service.ts @@ -12,7 +12,7 @@ export class BotService { constructor( @InjectRepository(TelegramUser) private readonly userRepository: Repository, - private readonly configService: ConfigService, // Inject the ConfigService + private readonly configService: ConfigService, ) { this.webUrl = this.configService.get('WEB_URL'); } @@ -49,10 +49,8 @@ export class BotService { const telegramId = parseInt(args[0], 10); const text = args.slice(1).join(' '); - // Retrieve the user from the database using the context's user ID const user = await this.userRepository.findOne({ where: { id: ctx.from.id.toString() } }); - // Check if the user is an admin if (user && user.is_admin) { try { await ctx.telegram.sendMessage(telegramId, text); @@ -114,7 +112,6 @@ export class BotService { @Command('makeadmin') async makeUserAdmin(@Ctx() ctx: Context) { const adminUser = await this.userRepository.findOne({ where: { id: ctx.from.id.toString() } }); - // Check if the user invoking the command is an admin if (!adminUser || !adminUser.is_admin) { await ctx.reply('You are not authorized to use this command.'); return; @@ -131,7 +128,6 @@ export class BotService { let userToMakeAdmin = await this.userRepository.findOne({ where: { id: adminId } }); - // If user not found, create a new user if (!userToMakeAdmin) { try { userToMakeAdmin = this.userRepository.create({ @@ -143,7 +139,7 @@ export class BotService { language_code: '', is_premium: false, added_to_attachment_menu: false, - is_admin: true, // Set as admin + is_admin: true, }); await this.userRepository.save(userToMakeAdmin); await ctx.reply(`New user created and set as admin with ID: ${adminId}`); @@ -151,7 +147,6 @@ export class BotService { await ctx.reply(`Error adding new user: ` + e.message); } } else { - // Update the user's is_admin status userToMakeAdmin.is_admin = true; await this.userRepository.save(userToMakeAdmin); await ctx.reply(`User with ID: ${adminId} is now an admin.`);