Skip to content

Commit

Permalink
feat: 🎸 add elasticsearch module
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatpotato13 committed Jan 12, 2025
1 parent ececa55 commit 43ac515
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/shared/modules/elasticsearch/elasticsearch.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { ElasticsearchConfig } from "@src/config";

import { ElasticsearchService } from "./elasticsearch.service";

@Module({
imports: [ConfigModule.forFeature(ElasticsearchConfig)],
providers: [
{
provide: "ElasticsearchService",
useClass: ElasticsearchService
}
],
exports: ["ElasticsearchService"]
})
export class ElasticsearchModule {}
18 changes: 18 additions & 0 deletions src/shared/modules/elasticsearch/elasticsearch.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Client } from "@elastic/elasticsearch";
import { Inject, Injectable } from "@nestjs/common";
import { ConfigType } from "@nestjs/config";
import { ElasticsearchConfig } from "@src/config";

@Injectable()
export class ElasticsearchService {
private readonly client: Client;

constructor(
@Inject(ElasticsearchConfig.KEY)
private readonly config: ConfigType<typeof ElasticsearchConfig>
) {
this.client = new Client({
node: this.config.node
});
}
}
3 changes: 2 additions & 1 deletion src/shared/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ElasticsearchModule } from "./elasticsearch/elasticsearch.module";
import { JwtModule } from "./jwt/jwt.module";
import { KafkaModule } from "./kafka/kafka.module";
import { RedisModule } from "./redis/redis.module";

export { JwtModule, KafkaModule, RedisModule };
export { ElasticsearchModule, JwtModule, KafkaModule, RedisModule };

0 comments on commit 43ac515

Please sign in to comment.