Skip to content

Commit

Permalink
fix: lots of missing where condition for tenantId
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-rocket committed Apr 30, 2024
1 parent a79682a commit 05d666c
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 524 deletions.
172 changes: 86 additions & 86 deletions packages/core/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MulterModule } from '@nestjs/platform-express';
import { ThrottlerModule } from '@nestjs/throttler';
import { ThrottlerBehindProxyGuard } from 'throttler/throttler-behind-proxy.guard';
import { ServeStaticModule, ServeStaticModuleOptions } from '@nestjs/serve-static';
import { ClsModule, ClsService } from 'nestjs-cls';
import { HeaderResolver, I18nModule } from 'nestjs-i18n';
import { initialize as initializeUnleash, InMemStorageProvider, UnleashConfig } from 'unleash-client';
import * as path from 'path';
Expand All @@ -15,6 +16,7 @@ import { ConfigService, environment } from '@gauzy/config';
import { ProbotModule } from '@gauzy/integration-github';
import { JiraModule } from '@gauzy/integration-jira';
import { CoreModule } from './core/core.module';
import { RequestContext } from './core/context/request-context';
import { SharedModule } from './shared/shared.module';
import { HealthModule } from './health/health.module';
import { CandidateInterviewersModule } from './candidate-interviewers/candidate-interviewers.module';
Expand Down Expand Up @@ -140,8 +142,6 @@ import { EmailResetModule } from './email-reset/email-reset.module';
import { TaskLinkedIssueModule } from './tasks/linked-issue/task-linked-issue.module';
import { OrganizationTaskSettingModule } from './organization-task-setting/organization-task-setting.module';
import { TaskEstimationModule } from './tasks/estimation/task-estimation.module';
import { ClsModule, ClsService } from 'nestjs-cls';
import { RequestContext } from 'core/context/request-context';
import { DailyPlanModule } from './tasks/daily-plan/daily-plan.module';

const { unleashConfig, github, jira } = environment;
Expand Down Expand Up @@ -200,84 +200,84 @@ if (environment.THROTTLE_ENABLED) {
}),
...(process.env.REDIS_ENABLED === 'true'
? [
CacheModule.registerAsync({
isGlobal: true,
useFactory: async () => {
const url =
process.env.REDIS_URL ||
(process.env.REDIS_TLS === 'true'
? `rediss://${process.env.REDIS_USER}:${process.env.REDIS_PASSWORD}@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`
: `redis://${process.env.REDIS_USER}:${process.env.REDIS_PASSWORD}@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`);
CacheModule.registerAsync({
isGlobal: true,
useFactory: async () => {
const url =
process.env.REDIS_URL ||
(process.env.REDIS_TLS === 'true'
? `rediss://${process.env.REDIS_USER}:${process.env.REDIS_PASSWORD}@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`
: `redis://${process.env.REDIS_USER}:${process.env.REDIS_PASSWORD}@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`);

console.log('REDIS_URL: ', url);
console.log('REDIS_URL: ', url);

let host, port, username, password;
let host, port, username, password;

const isTls = url.startsWith('rediss://');
const isTls = url.startsWith('rediss://');

// Removing the protocol part
let authPart = url.split('://')[1];
// Removing the protocol part
let authPart = url.split('://')[1];

// Check if the URL contains '@' (indicating the presence of username/password)
if (authPart.includes('@')) {
// Splitting user:password and host:port
let [userPass, hostPort] = authPart.split('@');
[username, password] = userPass.split(':');
[host, port] = hostPort.split(':');
} else {
// If there is no '@', it means there is no username/password
[host, port] = authPart.split(':');
}
// Check if the URL contains '@' (indicating the presence of username/password)
if (authPart.includes('@')) {
// Splitting user:password and host:port
let [userPass, hostPort] = authPart.split('@');
[username, password] = userPass.split(':');
[host, port] = hostPort.split(':');
} else {
// If there is no '@', it means there is no username/password
[host, port] = authPart.split(':');
}

port = parseInt(port);
port = parseInt(port);

const storeOptions = {
url: url,
username: username,
password: password,
isolationPoolOptions: {
min: 1,
max: 100
},
socket: {
tls: isTls,
host: host,
port: port,
passphrase: password,
rejectUnauthorized: process.env.NODE_ENV === 'production'
},
ttl: 60 * 60 * 24 * 7 // 1 week,
};
const storeOptions = {
url: url,
username: username,
password: password,
isolationPoolOptions: {
min: 1,
max: 100
},
socket: {
tls: isTls,
host: host,
port: port,
passphrase: password,
rejectUnauthorized: process.env.NODE_ENV === 'production'
},
ttl: 60 * 60 * 24 * 7 // 1 week,
};

const store = await redisStore(storeOptions);
const store = await redisStore(storeOptions);

store.client
.on('error', (err) => {
console.log('Redis Cache Client Error: ', err);
})
.on('connect', () => {
console.log('Redis Cache Client Connected');
})
.on('ready', () => {
console.log('Redis Cache Client Ready');
})
.on('reconnecting', () => {
console.log('Redis Cache Client Reconnecting');
})
.on('end', () => {
console.log('Redis Cache Client End');
});
store.client
.on('error', (err) => {
console.log('Redis Cache Client Error: ', err);
})
.on('connect', () => {
console.log('Redis Cache Client Connected');
})
.on('ready', () => {
console.log('Redis Cache Client Ready');
})
.on('reconnecting', () => {
console.log('Redis Cache Client Reconnecting');
})
.on('end', () => {
console.log('Redis Cache Client End');
});

// ping Redis
const res = await store.client.ping();
console.log('Redis Cache Client Cache Ping: ', res);
// ping Redis
const res = await store.client.ping();
console.log('Redis Cache Client Cache Ping: ', res);

return {
store: () => store
};
}
})
]
return {
store: () => store
};
}
})
]
: [CacheModule.register({ isGlobal: true })]),
ServeStaticModule.forRootAsync({
useFactory: async (configService: ConfigService): Promise<ServeStaticModuleOptions[]> => {
Expand Down Expand Up @@ -323,18 +323,18 @@ if (environment.THROTTLE_ENABLED) {
}),
...(environment.THROTTLE_ENABLED
? [
ThrottlerModule.forRootAsync({
inject: [ConfigService],
useFactory: () => {
return [
{
ttl: environment.THROTTLE_TTL,
limit: environment.THROTTLE_LIMIT
}
];
}
})
]
ThrottlerModule.forRootAsync({
inject: [ConfigService],
useFactory: () => {
return [
{
ttl: environment.THROTTLE_TTL,
limit: environment.THROTTLE_LIMIT
}
];
}
})
]
: []),
HealthModule,
CoreModule,
Expand Down Expand Up @@ -465,11 +465,11 @@ if (environment.THROTTLE_ENABLED) {
AppService,
...(environment.THROTTLE_ENABLED
? [
{
provide: APP_GUARD,
useClass: ThrottlerBehindProxyGuard
}
]
{
provide: APP_GUARD,
useClass: ThrottlerBehindProxyGuard
}
]
: []),
{
provide: APP_INTERCEPTOR,
Expand Down

0 comments on commit 05d666c

Please sign in to comment.