rez_core 7.0.2 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/bull.config.js +3 -3
- package/dist/config/bull.config.js.map +1 -1
- package/dist/config/redis.config.d.ts +10 -0
- package/dist/config/redis.config.js +52 -0
- package/dist/config/redis.config.js.map +1 -0
- package/dist/module/auth/auth.module.js +5 -14
- package/dist/module/auth/auth.module.js.map +1 -1
- package/dist/module/auth/strategies/jwt.strategy.js +1 -1
- package/dist/module/auth/strategies/jwt.strategy.js.map +1 -1
- package/dist/module/listmaster/controller/list-master.controller.d.ts +1 -1
- package/dist/module/listmaster/controller/list-master.controller.js +5 -4
- package/dist/module/listmaster/controller/list-master.controller.js.map +1 -1
- package/dist/module/listmaster/entity/list-master.entity.d.ts +1 -0
- package/dist/module/listmaster/entity/list-master.entity.js +4 -0
- package/dist/module/listmaster/entity/list-master.entity.js.map +1 -1
- package/dist/module/listmaster/repository/list-master.repository.d.ts +1 -1
- package/dist/module/listmaster/repository/list-master.repository.js +4 -1
- package/dist/module/listmaster/repository/list-master.repository.js.map +1 -1
- package/dist/module/listmaster/service/list-master.service.d.ts +1 -1
- package/dist/module/listmaster/service/list-master.service.js +2 -2
- package/dist/module/listmaster/service/list-master.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/config/bull.config.ts +8 -5
- package/src/config/redis.config.ts +56 -0
- package/src/module/auth/auth.module.ts +7 -14
- package/src/module/auth/strategies/jwt.strategy.ts +3 -2
- package/src/module/listmaster/controller/list-master.controller.ts +2 -0
- package/src/module/listmaster/entity/list-master.entity.ts +9 -7
- package/src/module/listmaster/repository/list-master.repository.ts +5 -1
- package/src/module/listmaster/service/list-master.service.ts +2 -1
package/package.json
CHANGED
|
@@ -5,18 +5,21 @@ import { ConfigService } from '@nestjs/config';
|
|
|
5
5
|
/**
|
|
6
6
|
* Bull Queue Configuration
|
|
7
7
|
* Configures Redis connection and queue settings for Bull
|
|
8
|
+
*
|
|
9
|
+
* Uses Redis DB 0 for queue management
|
|
10
|
+
* Cache/sessions use DB 1 (configured in redis.config.ts)
|
|
8
11
|
*/
|
|
9
12
|
@Injectable()
|
|
10
13
|
export class BullConfigService implements SharedBullConfigurationFactory {
|
|
11
|
-
constructor(private configService: ConfigService) {}
|
|
14
|
+
constructor(private configService: ConfigService) { }
|
|
12
15
|
|
|
13
16
|
createSharedConfiguration(): BullModuleOptions {
|
|
14
17
|
return {
|
|
15
18
|
redis: {
|
|
16
|
-
host:
|
|
17
|
-
port: 6379,
|
|
18
|
-
password: 'Rezolut123',
|
|
19
|
-
db: 0,
|
|
19
|
+
host: this.configService.get('REDIS_HOST') || 'localhost',
|
|
20
|
+
port: Number(this.configService.get('REDIS_PORT')) || 6379,
|
|
21
|
+
password: this.configService.get('REDIS_PASSWORD') || 'Rezolut123',
|
|
22
|
+
db: 0, // Bull uses DB 0
|
|
20
23
|
// Enable offline queue to handle Redis disconnections
|
|
21
24
|
enableOfflineQueue: true,
|
|
22
25
|
// Retry strategy for Redis connection
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import {
|
|
4
|
+
RedisModuleOptions,
|
|
5
|
+
RedisOptionsFactory,
|
|
6
|
+
} from '@liaoliaots/nestjs-redis';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Centralized Redis Configuration
|
|
10
|
+
*
|
|
11
|
+
* Provides named Redis connections for different purposes:
|
|
12
|
+
* - 'cache': For session storage, JWT validation, and general caching (DB 1)
|
|
13
|
+
* - Bull uses DB 0 separately via bull.config.ts
|
|
14
|
+
*
|
|
15
|
+
* This separation ensures Bull queues don't interfere with cache data
|
|
16
|
+
*/
|
|
17
|
+
@Injectable()
|
|
18
|
+
export class RedisConfigService implements RedisOptionsFactory {
|
|
19
|
+
constructor(private configService: ConfigService) {}
|
|
20
|
+
|
|
21
|
+
createRedisOptions(): RedisModuleOptions {
|
|
22
|
+
const host = this.configService.get('REDIS_HOST') || 'localhost';
|
|
23
|
+
const port = Number(this.configService.get('REDIS_PORT')) || 6379;
|
|
24
|
+
const password = this.configService.get('REDIS_PASSWORD') || 'Rezolut123';
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
config: [
|
|
28
|
+
{
|
|
29
|
+
// Cache connection - for sessions, JWT validation, and general caching
|
|
30
|
+
namespace: 'cache',
|
|
31
|
+
host,
|
|
32
|
+
port,
|
|
33
|
+
password,
|
|
34
|
+
db: 1, // Use DB 1 for cache
|
|
35
|
+
enableOfflineQueue: true,
|
|
36
|
+
retryStrategy: (times: number) => {
|
|
37
|
+
const delay = Math.min(times * 50, 2000);
|
|
38
|
+
return delay;
|
|
39
|
+
},
|
|
40
|
+
connectTimeout: 10000,
|
|
41
|
+
keepAlive: 30000,
|
|
42
|
+
keyPrefix: 'cache:', // Optional: prefix all cache keys
|
|
43
|
+
},
|
|
44
|
+
// Bull uses its own connection to DB 0 (configured in bull.config.ts)
|
|
45
|
+
// This keeps queue data separate from application cache
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Factory function for RedisModule.forRootAsync()
|
|
53
|
+
*/
|
|
54
|
+
export const redisConfigFactory = {
|
|
55
|
+
useClass: RedisConfigService,
|
|
56
|
+
};
|
|
@@ -10,6 +10,7 @@ import { AuthService } from './services/auth.service';
|
|
|
10
10
|
import { AuthController } from './controller/auth.controller';
|
|
11
11
|
import { RedisModule, RedisService } from '@liaoliaots/nestjs-redis';
|
|
12
12
|
import { Redis } from 'ioredis';
|
|
13
|
+
import { redisConfigFactory } from '../../config/redis.config';
|
|
13
14
|
|
|
14
15
|
@Module({
|
|
15
16
|
imports: [
|
|
@@ -30,17 +31,8 @@ import { Redis } from 'ioredis';
|
|
|
30
31
|
};
|
|
31
32
|
},
|
|
32
33
|
}),
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
inject: [ConfigService],
|
|
36
|
-
useFactory: async (configService: ConfigService) => ({
|
|
37
|
-
config: {
|
|
38
|
-
host: configService.get('REDIS_HOST') || 'localhost',
|
|
39
|
-
port: Number(configService.get('REDIS_PORT')) || 6379,
|
|
40
|
-
password: configService.get('REDIS_PASSWORD') || 'Rezolut123',
|
|
41
|
-
},
|
|
42
|
-
}),
|
|
43
|
-
}),
|
|
34
|
+
// Use centralized Redis configuration with named 'cache' connection
|
|
35
|
+
RedisModule.forRootAsync(redisConfigFactory),
|
|
44
36
|
],
|
|
45
37
|
controllers: [AuthController],
|
|
46
38
|
providers: [
|
|
@@ -56,17 +48,18 @@ export class AuthModule implements OnModuleInit {
|
|
|
56
48
|
constructor(private readonly redisService: RedisService) {}
|
|
57
49
|
|
|
58
50
|
async onModuleInit() {
|
|
59
|
-
|
|
51
|
+
// Get the named 'cache' connection (DB 1)
|
|
52
|
+
const redis: Redis = this.redisService.getOrThrow('cache');
|
|
60
53
|
|
|
61
54
|
// TEST WRITE
|
|
62
55
|
await redis.set('PING_TEST', 'PONG', 'EX', 10000);
|
|
63
56
|
|
|
64
57
|
// TEST READ
|
|
65
58
|
const value = await redis.get('PING_TEST');
|
|
66
|
-
console.log(`Redis Read: ${value}`);
|
|
59
|
+
console.log(`[Cache Redis DB 1] Read: ${value}`);
|
|
67
60
|
|
|
68
61
|
// TEST PING
|
|
69
62
|
const ping = await redis.ping();
|
|
70
|
-
console.log(`Redis PING reply: ${ping}`);
|
|
63
|
+
console.log(`[Cache Redis DB 1] PING reply: ${ping}`);
|
|
71
64
|
}
|
|
72
65
|
}
|
|
@@ -10,13 +10,14 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
|
10
10
|
private redis: Redis;
|
|
11
11
|
|
|
12
12
|
constructor(private readonly configService: ConfigService,
|
|
13
|
-
|
|
13
|
+
private readonly redisService: RedisService) {
|
|
14
14
|
super({
|
|
15
15
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
16
16
|
ignoreExpiration: false,
|
|
17
17
|
secretOrKey: configService.get('SECRET_KEY'),
|
|
18
18
|
});
|
|
19
|
-
|
|
19
|
+
// Use the named 'cache' connection for session validation
|
|
20
|
+
this.redis = this.redisService.getOrThrow('cache');
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
async validate(payload) {
|
|
@@ -126,11 +126,13 @@ export class ListMasterController {
|
|
|
126
126
|
@HttpCode(HttpStatus.OK)
|
|
127
127
|
async getAllListMasters(
|
|
128
128
|
@Req() req: Request & { user: any },
|
|
129
|
+
@Query('app_code') app_code: string,
|
|
129
130
|
@Query('search') search?: string,
|
|
130
131
|
) {
|
|
131
132
|
const loggedInUser = req.user.userData;
|
|
132
133
|
return await this.service.getAllListMasterByOrganization(
|
|
133
134
|
loggedInUser.enterprise_id,
|
|
135
|
+
app_code,
|
|
134
136
|
search,
|
|
135
137
|
);
|
|
136
138
|
}
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { Column, Entity, Index
|
|
1
|
+
import { Column, Entity, Index } from 'typeorm';
|
|
2
2
|
import { BaseEntity } from '../../meta/entity/base-entity.entity';
|
|
3
|
-
import { ENTITYTYPE_LISTMASTER } from '../../../constant/global.constant';
|
|
4
3
|
|
|
5
4
|
@Entity({ name: 'frm_list_master' })
|
|
6
5
|
@Index('idx_list_master_type_org', ['type', 'enterprise_id'])
|
|
7
6
|
export class ListMasterData extends BaseEntity {
|
|
8
7
|
|
|
9
|
-
@Column({nullable: true})
|
|
8
|
+
@Column({ nullable: true })
|
|
10
9
|
type: string;
|
|
11
10
|
|
|
12
|
-
@Column({nullable: true})
|
|
11
|
+
@Column({ nullable: true })
|
|
13
12
|
storage_type: string;
|
|
14
13
|
|
|
15
|
-
@Column({nullable: true})
|
|
14
|
+
@Column({ nullable: true })
|
|
16
15
|
sort_by: string;
|
|
17
16
|
|
|
18
|
-
@Column({nullable: true})
|
|
17
|
+
@Column({ nullable: true })
|
|
19
18
|
is_factory: number;
|
|
20
19
|
|
|
21
|
-
@Column({nullable: true})
|
|
20
|
+
@Column({ nullable: true })
|
|
22
21
|
source: string;
|
|
22
|
+
|
|
23
|
+
@Column({ type: 'varchar', length: 25, nullable: true })
|
|
24
|
+
app_code: string;
|
|
23
25
|
}
|
|
@@ -24,13 +24,17 @@ export class ListMasterRepository {
|
|
|
24
24
|
return await this.repo.findOne({ where: condition });
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
async findAllItems(enterprise_id: number, search?: string) {
|
|
27
|
+
async findAllItems(enterprise_id: number, app_code?: string, search?: string) {
|
|
28
28
|
const qb = this.repo
|
|
29
29
|
.createQueryBuilder('item')
|
|
30
30
|
.where('item.source = :source', { source: 'master' })
|
|
31
31
|
.andWhere('item.enterprise_id = :enterprise_id', { enterprise_id });
|
|
32
32
|
// .andWhere('item.is_factory = :isFactory', { isFactory: false });
|
|
33
33
|
|
|
34
|
+
if (app_code) {
|
|
35
|
+
qb.andWhere('item.app_code = :appcode', { app_code: app_code });
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
if (search?.trim()) {
|
|
35
39
|
qb.andWhere(
|
|
36
40
|
'(LOWER(item.name) LIKE :search OR LOWER(item.code) LIKE :search)',
|
|
@@ -288,9 +288,10 @@ export class ListMasterService extends EntityServiceImpl {
|
|
|
288
288
|
|
|
289
289
|
async getAllListMasterByOrganization(
|
|
290
290
|
enterprise_id: number,
|
|
291
|
+
app_code: string,
|
|
291
292
|
search?: string,
|
|
292
293
|
): Promise<any[]> {
|
|
293
|
-
return await this.listMasterRepo.findAllItems(enterprise_id, search);
|
|
294
|
+
return await this.listMasterRepo.findAllItems(enterprise_id, app_code, search);
|
|
294
295
|
}
|
|
295
296
|
|
|
296
297
|
async getDropDownData(
|