Skip to content

Commit

Permalink
format: clean the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Dec 31, 2024
1 parent bd071db commit 7068612
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions bot/src/migrations/db/deleteSpecificUserData.ts
Original file line number Diff line number Diff line change
@@ -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' })

Expand All @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit 7068612

Please sign in to comment.