Skip to content

Commit

Permalink
refactor: remove explicit return types for TypeScript inference
Browse files Browse the repository at this point in the history
  • Loading branch information
Gi-jutsu committed Dec 13, 2024
1 parent 3f29c50 commit d769540
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/core/primitives/entity.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export abstract class Entity<
static hydrate<Constructor extends new (...args: any) => any>(
this: Constructor,
...args: ConstructorParameters<Constructor>
): InstanceType<Constructor> {
) {
return new this(...args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class DrizzleAccountRepository implements AccountRepository {
});
}

async isEmailTaken(email: string): Promise<boolean> {
async isEmailTaken(email: string) {
const [record] = await this.database
.select({
count: count(),
Expand All @@ -42,7 +42,7 @@ export class DrizzleAccountRepository implements AccountRepository {
return record.count > 0;
}

async save(account: Account): Promise<void> {
async save(account: Account) {
await this.database
.insert(accountSchema)
.values(account.properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class DrizzleForgotPasswordRequestRepository
private readonly database: IdentityAndAccessDatabase
) {}

async hasPendingRequest(accountId: string): Promise<boolean> {
async hasPendingRequest(accountId: string) {
const results = await this.database
.select({ count: count() })
.from(ForgotPasswordRequestSchema)
Expand All @@ -27,7 +27,7 @@ export class DrizzleForgotPasswordRequestRepository
return results[0].count > 0;
}

async save(request: ForgotPasswordRequest): Promise<void> {
async save(request: ForgotPasswordRequest) {
const values = {
...request.properties,
expiresAt: request.properties.expiresAt.toJSDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { AccountRepository } from "@identity-and-access/domain/account/repo
export class InMemoryAccountRepository implements AccountRepository {
snapshots = new Map();

async findByEmail(email: string): Promise<Account | null> {
async findByEmail(email: string) {
for (const [id, properties] of this.snapshots.entries()) {
if (properties.email !== email) continue;

Expand All @@ -17,13 +17,13 @@ export class InMemoryAccountRepository implements AccountRepository {
return null;
}

async isEmailTaken(email: string): Promise<boolean> {
async isEmailTaken(email: string) {
return Array.from(this.snapshots.values()).some(
(properties) => properties.email === email
);
}

async save(account: Account): Promise<void> {
async save(account: Account) {
this.snapshots.set(account.id, account.properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export class InMemoryForgotPasswordRequestRepository
{
snapshots = new Map();

async hasPendingRequest(accountId: string): Promise<boolean> {
async hasPendingRequest(accountId: string) {
return [...this.snapshots.values()].some(
(request) => request.accountId === accountId
);
}

async save(request: ForgotPasswordRequest): Promise<void> {
async save(request: ForgotPasswordRequest) {
this.snapshots.set(request.id, request.properties);
}
}
2 changes: 1 addition & 1 deletion src/shared-kernel/infrastructure/console-mailer.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class ConsoleMailer implements Mailer {
to: string,
templateId: string,
variables: Record<string, unknown>
): Promise<void> {
) {
this.logger.log(
`Sending email to ${to} using template ${templateId} with variables: ${JSON.stringify(
variables
Expand Down
3 changes: 1 addition & 2 deletions src/shared-kernel/infrastructure/http-logger.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import {
Logger,
NestInterceptor,
} from "@nestjs/common";
import { Observable } from "rxjs";
import { tap } from "rxjs/operators";

@Injectable()
export class HttpLoggerInterceptor implements NestInterceptor {
private readonly logger = new Logger(HttpLoggerInterceptor.name);

intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
intercept(context: ExecutionContext, next: CallHandler) {
const request = context.switchToHttp().getRequest();
const response = context.switchToHttp().getResponse();
const start = Date.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import {
NotFoundException,
} from "@nestjs/common";
import { DateTime } from "luxon";
import { Observable, throwError } from "rxjs";
import { throwError } from "rxjs";
import { catchError } from "rxjs/operators";

@Injectable()
export class MapErrorToRfc9457HttpException implements NestInterceptor {
private readonly logger = new Logger(MapErrorToRfc9457HttpException.name);

intercept(_context: ExecutionContext, next: CallHandler): Observable<any> {
intercept(_context: ExecutionContext, next: CallHandler) {
return next
.handle()
.pipe(catchError((error) => this.throwAsHttpException(error)));
}

private throwAsHttpException(error: unknown): Observable<never> {
private throwAsHttpException(error: unknown) {
this.logger.error(error);

// @TODO: Map ValidationErrors to RFC9457
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class DrizzleOutboxMessageRepository implements OutboxMessageRepository {
private readonly database: SharedKernelDatabase
) {}

async findUnprocessedMessages(): Promise<OutboxMessage[]> {
async findUnprocessedMessages() {
const snapshots = await this.database
.select()
.from(outboxMessageSchema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MockEventEmitter implements EventEmitter {
shouldThrowError = false;
errorMessage: string = "An error occurred";

async emitAsync(event: string, ...values: any[]): Promise<void> {
async emitAsync(event: string, ...values: any[]) {
if (this.shouldThrowError) {
throw new Error(this.errorMessage);
}
Expand Down

0 comments on commit d769540

Please sign in to comment.