Skip to content

Commit

Permalink
Merge pull request #60 from s1seven/chore-resolve-sonar-major-issues
Browse files Browse the repository at this point in the history
chore: resolve SonarCloud major issues
  • Loading branch information
getlarge authored Aug 28, 2023
2 parents 03e1b8b + 4ddfa34 commit 8acaf74
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@s1seven/nestjs-tools",
"version": "0.0.8",
"version": "0.1.0",
"description": "Common resources shared by microservices",
"main": "dist/index.js",
"bin": "dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/amqp-transport/src/amqp-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export class AmqpClient extends ClientProxy {
}

close(): void {
this.channel && this.channel.close();
this.client && this.client.close();
this.channel?.close();
this.client?.close();
this.channel = null;
this.client = null;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/amqp-transport/src/amqp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export class AmqpServer extends Server implements CustomTransportStrategy {
}

close(): void {
this.channel && this.channel.close();
this.server && this.server.close();
this.channel?.close();
this.server?.close();
this.channel = null;
this.server = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@ import { AsyncLocalStorageService } from './async-local-storage.service';
*/
@Injectable()
export class AsyncLocalStorageInterceptor implements NestInterceptor {
readonly mode: AsyncLocalStorageMode;

constructor(
@Inject(AsyncLocalStorageService)
private readonly asyncLocalStorage: AsyncLocalStorageService,
@Inject(ASYNC_LOCAL_STORAGE_MODULE_OPTIONS)
private readonly options: AsyncLocalStorageModuleOptions,
) {
) {}

get mode(): AsyncLocalStorageMode {
const { useGuard, useInterceptor } = this.options;
this.mode = useGuard ? AsyncLocalStorageMode.Guard : useInterceptor ? AsyncLocalStorageMode.Interceptor : null;
if (useGuard) {
return AsyncLocalStorageMode.Guard;
}
if (useInterceptor) {
return AsyncLocalStorageMode.Interceptor;
}
return null;
}

async intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<unknown>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class AsyncLocalStorageService extends Map<K, T[K]> {
}

// AsyncLocalStorage methods and properties
run<R, TArgs extends any[]>(store: StoreMap = new Map(), callback: (...args: TArgs) => R, ...args: TArgs): R {
run<R, TArgs extends any[]>(store: StoreMap, callback: (...args: TArgs) => R, ...args: TArgs): R {
return this.instance.run(store, callback, ...args);
}

Expand Down
8 changes: 3 additions & 5 deletions packages/boot/src/api-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,16 @@ export async function setupOpenApi<Conf extends BaseConfig>(
setCommonOptions(openApiOptions, openApi);
const openApiDocument = SwaggerModule.createDocument(app, openApiOptions.build(), { extraModels });
const mainServerUrl = getMainServerUrl(config);
const customfavIcon =
typeof customFavIcon === 'function'
? customFavIcon(app)
: `${mainServerUrl}/${customFavIcon}` || `${mainServerUrl}/favicon.ico`;
const customFavIconPath =
typeof customFavIcon === 'function' ? customFavIcon(app) : `${mainServerUrl}/${customFavIcon || 'favicon.ico'}`;

const customOptions: SwaggerCustomOptions = {
swaggerOptions: {
persistAuthorization: true,
},
customSiteTitle:
typeof customSiteTitle === 'function' ? customSiteTitle(app) : customSiteTitle || `${serviceName} API`,
customfavIcon,
customfavIcon: customFavIconPath,
explorer: typeof enableExplorer === 'function' ? enableExplorer(app) : enableExplorer,
};

Expand Down
1 change: 0 additions & 1 deletion packages/cluster-service/src/cluster.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export type WorkerFn = (
send?: (message: any, workerId?: number) => void,
) => void | Promise<void>;

// export type PrimaryFn = (this: ClusterService) => void | Promise<void>;
export type PrimaryFn = () => void | Promise<void>;

// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
2 changes: 1 addition & 1 deletion packages/lock/src/lock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class LockService implements OnModuleInit, OnModuleDestroy {
createConnection(): void {
this.redis = new IORedis(this.options.redis);
this.redlock = new Redlock([this.redis], { ...this.defaultLockOptions, ...(this.options.lock || {}) });
// this.redlock.on('error', this.errorHandler);
// TODO: this.redlock.on('error', this.errorHandler);
}

isInitialized(): void {
Expand Down

0 comments on commit 8acaf74

Please sign in to comment.