From c9aba1184bea6d32f8166fe6c6001a2f482e9758 Mon Sep 17 00:00:00 2001 From: Behzad Rabiei <53224485+Behzad-rabiei@users.noreply.github.com> Date: Sun, 28 Jan 2024 23:48:08 +0330 Subject: [PATCH] [CI]: working on the CI --- .eslintrc.json | 4 +++- docker-compose.test.yml | 2 ++ mongo-init.js | 12 ++++++++++++ package.json | 2 +- src/rabbitmq/events/sendMessageEvent.ts | 26 +++++++++++++------------ types/types.d.ts | 10 +++++----- 6 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 mongo-init.js diff --git a/.eslintrc.json b/.eslintrc.json index cbb1327d..a1436192 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -20,6 +20,8 @@ "dist", "__tests__/", "jest.config.js", - "*.yml" + "*.yml", + "mongo-init.js", + "bable.config.js", ] } \ No newline at end of file diff --git a/docker-compose.test.yml b/docker-compose.test.yml index c5cd491e..71b489fd 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -40,6 +40,8 @@ services: environment: - MONGO_INITDB_ROOT_USERNAME=root - MONGO_INITDB_ROOT_PASSWORD=pass + volumes: + - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js healthcheck: test: echo 'db.stats().ok' | mongosh localhost:27017/test --quiet interval: 60s diff --git a/mongo-init.js b/mongo-init.js new file mode 100644 index 00000000..9b1a7efa --- /dev/null +++ b/mongo-init.js @@ -0,0 +1,12 @@ +db.createUser({ + user: 'root', + pwd: 'pass', + roles: [ + { + role: 'readWrite', + db: 'RnDAO', + }, + ], +}); + +db.createCollection("myCollection"); // This will create the RnDAO database \ No newline at end of file diff --git a/package.json b/package.json index beb7021e..74beec15 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "test:ci": "jest --ci --detectOpenHandles", "lint": "eslint **/*.ts", "lint-fix": "eslint --fix **/*.ts", - "format": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"", + "format": "prettier --write \"src/**/*.ts\" \"types/*.ts\" \"__tests__/**/*.ts\"", "migrate:create": "migrate create --template-file ./src/migrations/utils/template.ts --migrations-dir=\"./src/migrations/db\"", "migrate:up": "migrate --migrations-dir=\"./lib/migrations/db\" up", "migrate:down": "migrate --migrations-dir=\"./lib/migrations/db\" down" diff --git a/src/rabbitmq/events/sendMessageEvent.ts b/src/rabbitmq/events/sendMessageEvent.ts index 7577abcc..85fb8187 100644 --- a/src/rabbitmq/events/sendMessageEvent.ts +++ b/src/rabbitmq/events/sendMessageEvent.ts @@ -1,4 +1,5 @@ -import { Channel, ChannelType, Snowflake, TextChannel } from 'discord.js'; +/* eslint-disable @typescript-eslint/consistent-type-assertions */ +import { type Channel, ChannelType, type Snowflake, type TextChannel } from 'discord.js'; import { Event, MBConnection } from '@togethercrew.dev/tc-messagebroker'; import { coreService } from '../../services'; import { createPrivateThreadAndSendMessage } from '../../functions/thread'; @@ -11,7 +12,7 @@ const logger = parentLogger.child({ module: `${Event.DISCORD_BOT.SEND_MESSAGE}` const notifyUserAboutAnalysisFinish = async ( discordId: string, info: { guildId: Snowflake; message: string; useFallback: boolean }, -) => { +): Promise => { const client = await coreService.DiscordBotManager.getClient(); // related issue https://github.com/RnDAO/tc-discordBot/issues/68 @@ -21,7 +22,7 @@ const notifyUserAboutAnalysisFinish = async ( const channels = await guild.channels.fetch(); const arrayChannels = Array.from(channels, ([name, value]) => ({ ...value } as Channel)); - const textChannels = arrayChannels.filter((channel) => channel.type == ChannelType.GuildText) as TextChannel[]; + const textChannels = arrayChannels.filter((channel) => channel.type === ChannelType.GuildText) as TextChannel[]; const rawPositionBasedSortedTextChannels = textChannels.sort((textChannelA, textChannelB) => textChannelA.rawPosition > textChannelB.rawPosition ? 1 : -1, ); @@ -33,27 +34,28 @@ const notifyUserAboutAnalysisFinish = async ( // can not send DM to the user // Will create a private thread and notify him/her about the status if useFallback is true if (useFallback) - createPrivateThreadAndSendMessage(upperTextChannel, { + await createPrivateThreadAndSendMessage(upperTextChannel, { threadName: 'TogetherCrew Status', message: `<@${discordId}> ${message}`, }); } }; -export async function handleSendMessageEvent(msg: any) { +export async function handleSendMessageEvent(msg: any): Promise { try { logger.info({ msg, event: Event.DISCORD_BOT.SEND_MESSAGE, sagaId: msg.content.uuid }, 'is running'); - if (!msg) return; + if (msg === undefined || msg === null) return; const { content } = msg; const saga = await MBConnection.models.Saga.findOne({ sagaId: content.uuid }); - const platformId = saga.data['platformId']; + const platformId = saga.data.platformId; const platform = await platformService.getPlatform({ _id: platformId }); - const discordId = saga.data['discordId']; - const message = saga.data['message']; - const useFallback = saga.data['useFallback']; - if (platform) { - await saga.next(() => + const discordId = saga.data.discordId; + const message = saga.data.message; + const useFallback = saga.data.useFallback; + if (platform !== null) { + await saga.next(async () => + // eslint-disable-next-line @typescript-eslint/return-await notifyUserAboutAnalysisFinish(discordId, { guildId: platform.metadata?.id, message, useFallback }), ); } diff --git a/types/types.d.ts b/types/types.d.ts index 7e64cf61..b548d2b5 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -2,8 +2,8 @@ import { type Collection } from 'discord.js'; declare module 'discord.js' { - interface Client { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - commands: Collection; - } -} \ No newline at end of file + interface Client { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + commands: Collection; + } +}