Skip to content

Commit 30061b6

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent 68b1fa5 commit 30061b6

3 files changed

Lines changed: 684 additions & 663 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
"test:cov": "jest --config test/jest.json --runInBand --forceExit --coverage"
1313
},
1414
"dependencies": {
15-
"@backendworks/post-db": "^1.0.0",
15+
"@backendworks/post-db": "^1.0.1",
16+
"@keyv/redis": "^4.4.0",
1617
"@nestjs/cache-manager": "^3.0.1",
1718
"@nestjs/common": "^11.0.0",
1819
"@nestjs/config": "^4.0.2",
1920
"@nestjs/core": "^11.0.0",
2021
"@nestjs/microservices": "^11.1.2",
21-
"@keyv/redis": "^4.4.0",
2222
"amqplib": "^0.10.7",
2323
"cacheable": "^1.9.0",
2424
"joi": "^17.13.3",

src/common/common.module.ts

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
import { Module } from "@nestjs/common";
2-
import { ConfigModule, ConfigService } from "@nestjs/config";
3-
import { CacheModule } from "@nestjs/cache-manager";
4-
import { createKeyv, Keyv } from "@keyv/redis";
5-
import { CacheableMemory } from "cacheable";
6-
import Joi from "joi";
1+
import { Module } from '@nestjs/common';
2+
import { ConfigModule, ConfigService } from '@nestjs/config';
3+
import { CacheModule } from '@nestjs/cache-manager';
4+
import { createKeyv, Keyv } from '@keyv/redis';
5+
import { CacheableMemory } from 'cacheable';
6+
import Joi from 'joi';
77

8-
import configs from "./config";
8+
import configs from './config';
99

1010
@Module({
11-
imports: [
12-
ConfigModule.forRoot({
13-
load: configs,
14-
isGlobal: true,
15-
cache: true,
16-
envFilePath: [".env.docker", ".env"],
17-
expandVariables: true,
18-
validationSchema: Joi.object({
19-
// App
20-
NODE_ENV: Joi.string()
21-
.valid("development", "staging", "production", "local")
22-
.default("development"),
23-
APP_NAME: Joi.string().default("post-worker"),
24-
APP_DEBUG: Joi.boolean().truthy("true").falsy("false").default(false),
11+
imports: [
12+
ConfigModule.forRoot({
13+
load: configs,
14+
isGlobal: true,
15+
cache: true,
16+
envFilePath: ['.env'],
17+
expandVariables: true,
18+
validationSchema: Joi.object({
19+
// App
20+
NODE_ENV: Joi.string()
21+
.valid('development', 'staging', 'production', 'local')
22+
.default('development'),
23+
APP_NAME: Joi.string().default('post-worker'),
24+
APP_DEBUG: Joi.boolean().truthy('true').falsy('false').default(false),
2525

26-
// Database
27-
DATABASE_URL: Joi.string().uri().required(),
26+
// Database
27+
DATABASE_URL: Joi.string().uri().required(),
2828

29-
// Redis
30-
REDIS_URL: Joi.string().uri().default("redis://localhost:6379"),
31-
REDIS_KEY_PREFIX: Joi.string().default("post-worker:"),
32-
REDIS_TTL: Joi.number().default(3600),
29+
// Redis
30+
REDIS_URL: Joi.string().uri().default('redis://localhost:6379'),
31+
REDIS_KEY_PREFIX: Joi.string().default('post-worker:'),
32+
REDIS_TTL: Joi.number().default(3600),
3333

34-
// RabbitMQ
35-
RABBITMQ_URL: Joi.string().required(),
36-
RABBITMQ_QUEUE: Joi.string().default("post_worker_queue"),
37-
}),
38-
}),
39-
40-
CacheModule.registerAsync({
41-
inject: [ConfigService],
42-
useFactory: async (configService: ConfigService) => {
43-
const ttl = configService.get<number>("redis.ttl") * 1000;
44-
const redisUrl = configService.get<string>("redis.url");
45-
return {
46-
stores: [
47-
new Keyv({
48-
store: new CacheableMemory({ ttl, lruSize: 1000 }),
34+
// RabbitMQ
35+
RABBITMQ_URL: Joi.string().required(),
36+
RABBITMQ_QUEUE: Joi.string().default('post_worker_queue'),
4937
}),
50-
createKeyv(redisUrl),
51-
],
52-
};
53-
},
54-
isGlobal: true,
55-
}),
56-
],
57-
exports: [],
38+
}),
39+
40+
CacheModule.registerAsync({
41+
inject: [ConfigService],
42+
useFactory: async (configService: ConfigService) => {
43+
const ttl = configService.get<number>('redis.ttl') * 1000;
44+
const redisUrl = configService.get<string>('redis.url');
45+
return {
46+
stores: [
47+
new Keyv({
48+
store: new CacheableMemory({ ttl, lruSize: 1000 }),
49+
}),
50+
createKeyv(redisUrl),
51+
],
52+
};
53+
},
54+
isGlobal: true,
55+
}),
56+
],
57+
exports: [],
5858
})
5959
export class CommonModule {}

0 commit comments

Comments
 (0)