Skip to content

Commit 5eaa4b4

Browse files
committed
minor renaming
1 parent d39d807 commit 5eaa4b4

File tree

7 files changed

+38
-29
lines changed

7 files changed

+38
-29
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export interface Handler {
1+
export interface IHandlers {
22
handleRoutes(): void
33
}

source/api/v1/api/handlers/auth/AuthHandlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { AuthUserSchema, ChangePasswordSchema } from "../../validation/schemas/A
55
import { extractJwtPayload } from "../../../shared/utils/jwt/PayloadExtractor";
66
import { extractToken } from "../../../shared/utils/common/TokenExtractor";
77
import { isException } from "../../../shared/utils/guards/ExceptionGuard";
8-
import { Handler } from "../Handler";
8+
import { IHandlers } from "../Handler";
99
import { AuthorizationPreHandler } from "../../prehandlers/AuthPreHandler";
1010

11-
export class AuthHandler implements Handler {
11+
export class AuthHandlers implements IHandlers {
1212
constructor(
1313
private server: FastifyInstance,
1414
private authorizationPreHandler: AuthorizationPreHandler,

source/api/v1/api/handlers/common/CommonHandler.ts renamed to source/api/v1/api/handlers/common/CommonHandlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { FastifyInstance } from "fastify";
22
import Healthcheck, { SystemReport } from "../../../shared/utils/common/Healthcheck";
3-
import { Handler } from "../Handler";
3+
import { IHandlers } from "../Handler";
44
import { isException } from "../../../shared/utils/guards/ExceptionGuard";
55

6-
export class CommonHandler implements Handler {
6+
export class CommonHandlers implements IHandlers {
77
constructor(
88
private server: FastifyInstance,
99
private healthcheck: Healthcheck

source/api/v1/api/handlers/notes/NotesHandlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { extractJwtPayload } from "../../../shared/utils/jwt/PayloadExtractor";
55
import { extractToken } from "../../../shared/utils/common/TokenExtractor";
66
import { AddCollaboratorSchema, CreateNoteSchema, DeleteNoteSchema, GetNoteCollaboratorsSchema, GetNoteSchema, GetNotesSchema, RemoveCollaboratorSchema, UpdateNoteSchema } from "../../validation/schemas/NoteSchemas";
77
import { isException } from "../../../shared/utils/guards/ExceptionGuard";
8-
import { Handler } from "../Handler";
8+
import { IHandlers } from "../Handler";
99
import { AuthorizationPreHandler } from "../../prehandlers/AuthPreHandler";
1010

11-
export class NotesHandler implements Handler {
11+
export class NotesHandlers implements IHandlers {
1212
constructor(
1313
private server: FastifyInstance,
1414
private authorizationPreHandler: AuthorizationPreHandler,

source/api/v1/api/handlers/users/UsersHandlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { CreateUserSchema, GetMyProfileSchema, GetUserSchema, UpdateUserSchema }
44
import { extractJwtPayload } from "../../../shared/utils/jwt/PayloadExtractor";
55
import { extractToken } from "../../../shared/utils/common/TokenExtractor";
66
import { isException } from "../../../shared/utils/guards/ExceptionGuard";
7-
import { Handler } from "../Handler";
7+
import { IHandlers } from "../Handler";
88
import { AuthorizationPreHandler } from "../../prehandlers/AuthPreHandler";
99
import { IUsersService } from "../../../services/users/UsersServiceInterface";
1010
import { UsersService } from "../../../services/users/UsersService";
1111

1212

13-
export class UsersHandler implements Handler {
13+
export class UsersHandlers implements IHandlers {
1414
constructor (
1515
private server: FastifyInstance,
1616
private authorizationPreHandler: AuthorizationPreHandler,
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { LOGGER } from "../utils/common/Logger"
22

3-
export const withRetry = (_target: any, _key: string, descriptor: PropertyDescriptor) => {
4-
const originalMethod = descriptor.value
3+
export const withRetry = (maxRetries: number = 5, delay: number = 1000) => {
4+
return function (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) {
5+
const originalMethod = descriptor.value;
56

6-
descriptor.value = async function (...args: any[]) {
7-
try {
8-
return await originalMethod.apply(this, args)
9-
} catch (error) {
10-
LOGGER.error(error)
11-
return await originalMethod.apply(this, args)
12-
}
13-
}
14-
15-
return descriptor
7+
descriptor.value = async function (...args: any[]) {
8+
let attempts = 0;
9+
let lastError: any;
10+
11+
while (attempts < maxRetries) {
12+
try {
13+
return await originalMethod.apply(this, args);
14+
} catch (error) {
15+
lastError = error;
16+
attempts++;
17+
LOGGER.error(error)
18+
await new Promise(resolve => setTimeout(resolve, delay));
19+
}
20+
}
21+
22+
throw lastError;
23+
};
24+
};
1625
}

source/main.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import { Note as NoteEntity } from './api/v1/database/entities/Note'
1313
import { initSwaggerViewer } from './api/v1/api/openapi/swagger/InitSwagger'
1414
import { connectAndGetRedisInstance } from './api/v1/cache/InitRedisInstance'
1515
import Healthcheck from './api/v1/shared/utils/common/Healthcheck'
16-
import { CommonHandler } from './api/v1/api/handlers/common/CommonHandler'
17-
import { AuthHandler } from './api/v1/api/handlers/auth/AuthHandlers'
18-
import { NotesHandler } from './api/v1/api/handlers/notes/NotesHandlers'
19-
import { UsersHandler } from './api/v1/api/handlers/users/UsersHandlers'
16+
import { CommonHandlers } from './api/v1/api/handlers/common/CommonHandlers'
17+
import { AuthHandlers } from './api/v1/api/handlers/auth/AuthHandlers'
18+
import { NotesHandlers } from './api/v1/api/handlers/notes/NotesHandlers'
19+
import { UsersHandlers } from './api/v1/api/handlers/users/UsersHandlers'
2020
import { LOGGER } from './api/v1/shared/utils/common/Logger'
2121

2222
const main = async () => {
@@ -58,10 +58,10 @@ const main = async () => {
5858

5959
// registering handlers with version prefix
6060
server.register((server, _, done) => {
61-
const usersHandler = new UsersHandler(server, authentication, usersService)
62-
const notesHandler = new NotesHandler(server, authentication, notesService)
63-
const authHandler = new AuthHandler(server, authentication, authService)
64-
const commonHandler = new CommonHandler(server, healthcheck)
61+
const usersHandler = new UsersHandlers(server, authentication, usersService)
62+
const notesHandler = new NotesHandlers(server, authentication, notesService)
63+
const authHandler = new AuthHandlers(server, authentication, authService)
64+
const commonHandler = new CommonHandlers(server, healthcheck)
6565

6666
usersHandler.handleRoutes()
6767
notesHandler.handleRoutes()

0 commit comments

Comments
 (0)