From 706861216e6ceb7fb0f6f5984001a8ade66e1777 Mon Sep 17 00:00:00 2001 From: Behzad-rabiei Date: Tue, 31 Dec 2024 11:01:40 +0100 Subject: [PATCH] format: clean the code --- .../migrations/db/deleteSpecificUserData.ts | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/bot/src/migrations/db/deleteSpecificUserData.ts b/bot/src/migrations/db/deleteSpecificUserData.ts index a14609ec..59e271b8 100644 --- a/bot/src/migrations/db/deleteSpecificUserData.ts +++ b/bot/src/migrations/db/deleteSpecificUserData.ts @@ -1,11 +1,11 @@ -import 'dotenv/config' +import 'dotenv/config'; -import mongoose from 'mongoose' +import mongoose from 'mongoose'; -import { DatabaseManager, Platform, PlatformNames } from '@togethercrew.dev/db' +import { DatabaseManager, Platform, PlatformNames } from '@togethercrew.dev/db'; -import config from '../../config' -import parentLogger from '../../config/logger' +import config from '../../config'; +import parentLogger from '../../config/logger'; const logger = parentLogger.child({ event: 'deleteSpecificUserData' }) @@ -21,10 +21,10 @@ const connectToMongoDB = async () => { export const up = async () => { try { // const GUILD_ID = '675aea1f2b104f11ad1f5417' - // const SPECIFIC_DISCORD_ID = '641449673818898472' + // const USER_ID = '641449673818898472' const GUILD_ID = '980858613587382322' - const SPECIFIC_DISCORD_ID = '681946187490000900' + const USER_ID = '681946187490000900' await connectToMongoDB() const platform = await Platform.findOne({ name: PlatformNames.Discord, @@ -33,33 +33,21 @@ export const up = async () => { logger.info(`platform info:${platform}`) const guildConnection = await DatabaseManager.getInstance().getGuildDb(GUILD_ID) + const deleteGuildMemberResult = await guildConnection.models.GuildMember.deleteOne({ - discordId: SPECIFIC_DISCORD_ID, + discordId: USER_ID, }) - logger.info( - `Platform ${platform?.id}: Deleted GuildMember with discordId = SPECIFIC_DISCORD_ID. Result: ${JSON.stringify(deleteGuildMemberResult)}` - ) - const deleteRawInfoResult = await guildConnection.models.RawInfo.deleteMany({ author: SPECIFIC_DISCORD_ID }) - logger.info( - `Platform ${platform?.id}: Deleted RawInfo docs with author = SPECIFIC_VALUE. Result: ${JSON.stringify(deleteRawInfoResult)}` - ) + const deleteRawInfoResult = await guildConnection.models.RawInfo.deleteMany({ author: USER_ID }) const pullUserMentionsResult = await guildConnection.models.RawInfo.updateMany( - { user_mentions: SPECIFIC_DISCORD_ID }, - { $pull: { user_mentions: SPECIFIC_DISCORD_ID } } + { user_mentions: USER_ID }, + { $pull: { user_mentions: USER_ID } } ) - logger.info( - `Platform ${platform?.id}: Pulled 'SPECIFIC_VALUE' from user_mentions. Result: ${JSON.stringify(pullUserMentionsResult)}` - ) - const updateRepliedUserResult = await guildConnection.models.RawInfo.updateMany( - { replied_user: SPECIFIC_DISCORD_ID }, + { replied_user: USER_ID }, { $set: { replied_user: null } } ) - logger.info( - `Platform ${platform?.id}: Set replied_user to null where it was 'SPECIFIC_VALUE'. Result: ${JSON.stringify(updateRepliedUserResult)}` - ) await mongoose.connection.close() logger.info('Migration completed and core MongoDB connection closed.') } catch (err) {