diff --git a/env/.env.sample b/env/.env.sample index 63782906..458bfac2 100644 --- a/env/.env.sample +++ b/env/.env.sample @@ -1,5 +1,8 @@ # This is a sample file generated by sample-env -# app +### Environment File ################################################################## +# This file is a "template" of which env vars need to be defined for your application +######################################################################################## + APP_PORT= APP_PREFIX= APP_NAME= @@ -7,26 +10,29 @@ NODE_ENV= API_URL= CLIENT_URL= SWAGGER_USER= -ALLOWED_ORIGINS= +ALLOWED_HOSTS= SWAGGER_PASSWORD= -# database + # database DB_HOST= DB_PORT= DB_USERNAME= DB_PASSWORD= DB_DATABASE= -# encryption + + # encryption ENC_IV= ENC_KEY= -# jwt + + # jwt JWT_ACCESS_EXPIRY= JWT_REFRESH_EXPIRY= JWT_SECRET= -# mail + + # mail MAIL_HOST= MAIL_PASSWORD= MAIL_USERNAME= @@ -36,12 +42,13 @@ MAIL_PREVIEW_EMAIL= MAIL_SENDER_EMAIL= MAIL_TEMPLATE_DIR= -# cloudinary + + # cloudinary CLOUDINARY_CLOUD_NAME= CLOUDINARY_API_KEY= CLOUDINARY_API_SECRET= -# redis + # redis REDIS_TTL= REDIS_USERNAME= REDIS_PASSWORD= @@ -49,29 +56,33 @@ REDIS_HOST= REDIS_PORT= REDIS_URI= -# rabbitmq +#REDIS_URI= + + + # rabbitmq RABBITMQ_DEFAULT_USER= RABBITMQ_DEFAULT_PASS= -RABBITMQ_URI= RABBITMQ_EXCHANGE= -RABBITMQ_QUEUE= RABBITMQ_DEFAULT_PREFETCH= +RABBITMQ_URI= -#sentry + + #sentry SENTRY_DSN= -SENTRY_ENVIRONMENT= -#google ouath + #google ouath GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= GOOGLE_CALLBACK_URL= -#facebook ouath + + + #facebook ouath FACEBOOK_CLIENT_ID= FACEBOOK_CLIENT_SECRET= FACEBOOK_CALLBACK_URL= -#throttle + + #throttle THROTTLE_LIMIT= THROTTLE_TTL= - diff --git a/package.json b/package.json index 9947abe4..ef39e37a 100644 --- a/package.json +++ b/package.json @@ -147,7 +147,7 @@ "@nestjs/cli": "10.1.18", "@nestjs/schematics": "10.0.2", "@nestjs/testing": "10.2.7", - "@rubiin/eslint-config": "^1.8.8", + "@rubiin/eslint-config": "^1.8.10", "@rubiin/tsconfig": "^1.1.0", "@sentry/types": "^7.73.0", "@side/jest-runtime": "^1.1.0", diff --git a/src/common/@types/enums/misc.enum.ts b/src/common/@types/enums/misc.enum.ts index 927f2126..dc43cd50 100644 --- a/src/common/@types/enums/misc.enum.ts +++ b/src/common/@types/enums/misc.enum.ts @@ -70,6 +70,11 @@ export enum RoutingKey { SEND_NEWSLETTER = "send-newsletter", } +export enum Queues { + MAIL = "mail", + HTTP = "http", +} + export enum PaginationType { OFFSET = "OFFSET", CURSOR = "CURSOR", diff --git a/src/common/@types/global.d.ts b/src/common/@types/global.d.ts index c8580475..a1820e37 100644 --- a/src/common/@types/global.d.ts +++ b/src/common/@types/global.d.ts @@ -70,8 +70,6 @@ declare global { REDIS_PORT: number RABBITMQ_URI: string - RABBITMQ_EXCHANGE: string - RABBITMQ_QUEUE: string RABBITMQ_DEFAULT_PREFETCH: number SENTRY_DSN: string diff --git a/src/lib/config/configs/rabbitmq.config.ts b/src/lib/config/configs/rabbitmq.config.ts index 521239ef..65af1d2b 100644 --- a/src/lib/config/configs/rabbitmq.config.ts +++ b/src/lib/config/configs/rabbitmq.config.ts @@ -5,13 +5,11 @@ import { RABBIT_MQ_URI_REGEX } from "@common/constant"; export const rabbitmqConfigValidationSchema = { RABBITMQ_URI: Joi.string().pattern(RABBIT_MQ_URI_REGEX).required(), RABBITMQ_EXCHANGE: Joi.string().required(), - RABBITMQ_QUEUE: Joi.string().required(), RABBITMQ_DEFAULT_PREFETCH: Joi.number().required(), }; export const rabbitmq = registerAs("rabbitmq", () => ({ url: process.env.RABBITMQ_URI, exchange: process.env.RABBITMQ_EXCHANGE, - queue: process.env.RABBITMQ_QUEUE, prefetchCount: process.env.RABBITMQ_DEFAULT_PREFETCH, })); diff --git a/src/lib/mailer/mail.processor.ts b/src/lib/mailer/mail.processor.ts index c1195809..20373f35 100644 --- a/src/lib/mailer/mail.processor.ts +++ b/src/lib/mailer/mail.processor.ts @@ -14,7 +14,6 @@ export class MailProcessor { routingKey: [RoutingKey.SEND_MAIL, RoutingKey.SEND_NEWSLETTER], exchange: process.env.RABBITMQ_EXCHANGE, queue: process.env.RABBITMQ_QUEUE, - createQueueIfNotExists: true, }) sendMail(payload: MailPayload) { return from( diff --git a/src/lib/rabbit/rabbit.module.ts b/src/lib/rabbit/rabbit.module.ts index 9363e7ed..730d8725 100644 --- a/src/lib/rabbit/rabbit.module.ts +++ b/src/lib/rabbit/rabbit.module.ts @@ -2,6 +2,7 @@ import { RabbitMQModule } from "@golevelup/nestjs-rabbitmq"; import { Global, Logger, Module } from "@nestjs/common"; import { ConfigModule, ConfigService } from "@nestjs/config"; import { RabbitService } from "./rabbit.service"; +import { RabbitMQHealthCheckService } from "./healthcheck"; const logger = new Logger("RabbitMQ"); diff --git a/src/lib/rabbit/rabbit.service.ts b/src/lib/rabbit/rabbit.service.ts index 7296071e..fb64ce8e 100644 --- a/src/lib/rabbit/rabbit.service.ts +++ b/src/lib/rabbit/rabbit.service.ts @@ -2,7 +2,7 @@ import { RabbitSubscribe } from "@golevelup/nestjs-rabbitmq"; import { Injectable, Logger } from "@nestjs/common"; import { from, map, tap } from "rxjs"; import { MailerService } from "@lib/mailer/mailer.service"; -import { MailPayload, RoutingKey } from "@common/@types"; +import { MailPayload, Queues, RoutingKey } from "@common/@types"; @Injectable() export class RabbitService { @@ -12,9 +12,9 @@ export class RabbitService { constructor(private readonly mailService: MailerService) {} @RabbitSubscribe({ - routingKey: [RoutingKey.SEND_MAIL, RoutingKey.SEND_NEWSLETTER], + routingKey: RoutingKey.SEND_MAIL, exchange: process.env.RABBITMQ_EXCHANGE, - queue: process.env.RABBITMQ_QUEUE, + queue: Queues.MAIL, }) sendMail(payload: MailPayload) { return from( diff --git a/src/modules/user/user.service.ts b/src/modules/user/user.service.ts index 7443c349..53233b2f 100644 --- a/src/modules/user/user.service.ts +++ b/src/modules/user/user.service.ts @@ -11,8 +11,8 @@ import type { Observable } from "rxjs"; import { from, map, mergeMap, of, switchMap, throwError } from "rxjs"; import type { - RecordWithFile, PaginationResponse, + RecordWithFile, } from "@common/@types"; import { CursorType,