diff --git a/src/api/controllers/ProjectController.ts b/src/api/controllers/ProjectController.ts index 031cac84..7987d438 100644 --- a/src/api/controllers/ProjectController.ts +++ b/src/api/controllers/ProjectController.ts @@ -61,3 +61,4 @@ export default class ProjectController extends ApiController { this.httpCreated(res, await this.projectService.create(projectEntity)); } } + diff --git a/src/api/controllers/index.ts b/src/api/controllers/index.ts index 463ebb48..c0dc0129 100644 --- a/src/api/controllers/index.ts +++ b/src/api/controllers/index.ts @@ -2,7 +2,7 @@ import { Container } from "typedi"; import ProjectController from "./ProjectController"; export default { - start: () => { - Container.get(ProjectController); - }, -}; + start: () => { + Container.get(ProjectController); + } +} diff --git a/src/api/middlewares/ErrorHandler.ts b/src/api/middlewares/ErrorHandler.ts index 274f5923..ac0b0f4d 100644 --- a/src/api/middlewares/ErrorHandler.ts +++ b/src/api/middlewares/ErrorHandler.ts @@ -10,7 +10,7 @@ export default function errorHandler(error: any, req: Request, response: Respons if (error instanceof SyntaxError && errorStatus === 400 && "body" in error) { response.status(HttpCodes.BAD_REQUEST).send({ body: error["body"], - type: error as any["type"], + type: error as any ["type"], }); return; } @@ -22,3 +22,4 @@ export default function errorHandler(error: any, req: Request, response: Respons next(error); } + diff --git a/src/common/config/IDatabaseConfig.ts b/src/common/config/IDatabaseConfig.ts index 2b03000e..24796543 100644 --- a/src/common/config/IDatabaseConfig.ts +++ b/src/common/config/IDatabaseConfig.ts @@ -1,4 +1,4 @@ -export default interface IDatabaseConfig { - name: string; - url?: string; -} +export default interface IDatabaseConfig { + name: string; + url?: string; +} diff --git a/src/common/databases/TezosLink.ts b/src/common/databases/TezosLink.ts index 9455894d..3ad33c72 100644 --- a/src/common/databases/TezosLink.ts +++ b/src/common/databases/TezosLink.ts @@ -26,3 +26,4 @@ export default class TezosLink { return name; } } + diff --git a/src/common/helpers/ObjectHydrate.ts b/src/common/helpers/ObjectHydrate.ts index 7efbc7db..880d1cef 100644 --- a/src/common/helpers/ObjectHydrate.ts +++ b/src/common/helpers/ObjectHydrate.ts @@ -1,7 +1,7 @@ -import { plainToClassFromExist } from "class-transformer"; - -export default abstract class ObjectHydrate { - public static hydrate(object: { [key: string]: any }, from: { [key: string]: any }): T { - return plainToClassFromExist(object, from) as T; - } -} +import { plainToClassFromExist } from "class-transformer"; + +export default abstract class ObjectHydrate { + public static hydrate(object: { [key: string]: any }, from: { [key: string]: any }): T { + return plainToClassFromExist(object, from) as T; + } +} diff --git a/src/common/repositories/MetricsRepository.ts b/src/common/repositories/MetricsRepository.ts index 32d651ce..9f5bbb9d 100644 --- a/src/common/repositories/MetricsRepository.ts +++ b/src/common/repositories/MetricsRepository.ts @@ -64,7 +64,7 @@ export default class MetricRepository { const data = { ...metricEntity }; const result: MetricEntity[] = []; - this.instanceDb.$transaction(async (transaction: Prisma.TransactionClient) => { + this.instanceDb.$transaction(async(transaction: Prisma.TransactionClient) => { for (const item of data) { if (!item) continue; result.push( @@ -135,7 +135,7 @@ export default class MetricRepository { const response = this.model.groupBy({ by: ["date_requested"], _count: { - date_requested: true, + date_requested: true, }, where: { projectId: projectId, @@ -187,3 +187,4 @@ export default class MetricRepository { } } } + diff --git a/src/common/repositories/ProjectRepository.ts b/src/common/repositories/ProjectRepository.ts index a90b4ccb..1b2b610f 100644 --- a/src/common/repositories/ProjectRepository.ts +++ b/src/common/repositories/ProjectRepository.ts @@ -24,13 +24,14 @@ export default class ProjectRepository { const data = { ...projectEntity }; return this.model.findUnique({ where: data, - + include: { // Include metrics & count Metrics: true, _count: { select: { Metrics: true }, - }, + }, + }, }); } catch (error) { @@ -58,3 +59,4 @@ export default class ProjectRepository { } } } + diff --git a/src/common/ressources/MetricEntity.ts b/src/common/ressources/MetricEntity.ts index 7a5cc526..ca8e40dd 100644 --- a/src/common/ressources/MetricEntity.ts +++ b/src/common/ressources/MetricEntity.ts @@ -4,28 +4,28 @@ import ProjectEntity from "./ProjectEntity"; export default class MetricEntity { @IsNotEmpty() public id!: number; - - @IsNotEmpty({ groups: ["create"] }) + + @IsNotEmpty(({groups: ["create"]})) public path!: string; - @IsNotEmpty({ groups: ["create"] }) + @IsNotEmpty(({groups: ["create"]})) public uuid!: string; - @IsNotEmpty({ groups: ["create"] }) + @IsNotEmpty(({groups: ["create"]})) public remote_address!: string; - @IsNotEmpty({ groups: ["create"] }) + @IsNotEmpty(({groups: ["create"]})) public date_requested!: Date; - @IsNotEmpty({ groups: ["create"] }) + @IsNotEmpty(({groups: ["create"]})) public projectId!: number; - @IsNotEmpty({ groups: ["create"] }) + @IsNotEmpty(({groups: ["create"]})) public project!: ProjectEntity; @IsDate() public createdAt?: Date; - @IsDate() + @IsDate() public updatedAt?: Date; } diff --git a/src/common/ressources/ProjectEntity.ts b/src/common/ressources/ProjectEntity.ts index 5b3c4166..8bfc5e01 100644 --- a/src/common/ressources/ProjectEntity.ts +++ b/src/common/ressources/ProjectEntity.ts @@ -5,21 +5,21 @@ export default class ProjectEntity { @IsNotEmpty() public id!: number; - @IsNotEmpty({ groups: ["create"] }) + @IsNotEmpty({groups: ["create"]}) public title!: string; - @IsNotEmpty() + @IsNotEmpty() public uuid!: string; @IsDate() public createdAt!: Date; - @IsDate() + @IsDate() public updatedAt!: Date; - @IsNotEmpty({ groups: ["create"] }) + @IsNotEmpty({groups: ["create"]}) public network!: string; @IsOptional() public metrics?: MetricEntity[]; -} +} \ No newline at end of file diff --git a/src/common/ressources/index.ts b/src/common/ressources/index.ts index 823a7e15..75171740 100644 --- a/src/common/ressources/index.ts +++ b/src/common/ressources/index.ts @@ -1,4 +1,4 @@ -import ProjectEntity from "./ProjectEntity"; -import MetricEntity from "./MetricEntity"; - -export { ProjectEntity, MetricEntity }; +import ProjectEntity from "./ProjectEntity"; +import MetricEntity from "./MetricEntity"; + +export { ProjectEntity, MetricEntity}; diff --git a/src/common/services/BaseService.ts b/src/common/services/BaseService.ts index 12ec929f..fb2c5ab3 100644 --- a/src/common/services/BaseService.ts +++ b/src/common/services/BaseService.ts @@ -1 +1,2 @@ export default class BaseService {} + diff --git a/src/common/services/metric/MetricService.ts b/src/common/services/metric/MetricService.ts index 497be266..76e9770b 100644 --- a/src/common/services/metric/MetricService.ts +++ b/src/common/services/metric/MetricService.ts @@ -35,18 +35,18 @@ export default class MetricService { } /** - * - * @throws {Error} If metric is undefined - * @returns - */ - public async getCountRpcPath(metricEntity: Partial, from: Date, to: Date) { - const pathsCount = await this.metricRepository.countRpcPathUsage(metricEntity.projectId!, from, to); - if (!pathsCount) return null; - return pathsCount; - } + * + * @throws {Error} If metric is undefined + * @returns + */ + public async getCountRpcPath(metricEntity: Partial, from: Date, to: Date) { + const pathsCount = await this.metricRepository.countRpcPathUsage(metricEntity.projectId!,from,to); + if (!pathsCount) return null; + return pathsCount; + } /** - * - * @throws {Error} If metric is undefined + * + * @throws {Error} If metric is undefined * @returns */ public async getCountAllMetrics(metricEntity: Partial) { @@ -56,27 +56,27 @@ export default class MetricService { } /** - * + * * @throws {Error} If metric is undefined * @returns */ - public async getLastMetrics(metricEntity: Partial, limit: number) { - const lastMetric = await this.metricRepository.findLastRequests(metricEntity.projectId!, limit); + public async getLastMetrics(metricEntity: Partial, limit: number){ + const lastMetric = await this.metricRepository.findLastRequests(metricEntity.projectId!,limit); return ObjectHydrate.hydrate>(new MetricEntity(), lastMetric); } /** - * + * * @throws {Error} If metric is undefined * @returns */ - public async getRequestsByDay(metricEntity: Partial, from: Date, to: Date) { - const requestByDay = await this.metricRepository.findRequestsByDay(metricEntity.projectId!, from, to); + public async getRequestsByDay(metricEntity: Partial, from: Date, to: Date){ + const requestByDay = await this.metricRepository.findRequestsByDay(metricEntity.projectId!,from,to); return ObjectHydrate.hydrate>(new MetricEntity(), requestByDay); } /** - * + * * @throws {Error} If metric is undefined * @returns */ @@ -85,3 +85,4 @@ export default class MetricService { await this.metricRepository.removeOldMetricsBymonths(months); } } + diff --git a/src/common/services/project/ProjectService.ts b/src/common/services/project/ProjectService.ts index 6f220833..40025318 100644 --- a/src/common/services/project/ProjectService.ts +++ b/src/common/services/project/ProjectService.ts @@ -4,6 +4,8 @@ import { ProjectEntity } from "@Common/ressources"; import { type processFindManyQuery } from "prisma-query"; import { Service } from "typedi"; + + @Service() export default class ProjectService { constructor(private projectRepository: ProjectRepository) {} @@ -15,7 +17,7 @@ export default class ProjectService { const projects = await this.projectRepository.findMany(query); return ObjectHydrate.hydrate>(new ProjectEntity(), projects); } - /** + /** * @throws {Error} If project is undefined */ public async getByUUID(projectEntity: Partial) { @@ -23,14 +25,15 @@ export default class ProjectService { if (!project) return null; return ObjectHydrate.hydrate>(new ProjectEntity(), project); } - /** - * - * @throws {Error} If project cannot be created - * @returns - */ + /** + * + * @throws {Error} If project cannot be created + * @returns + */ public async create(projectEntity: Partial) { const project = await this.projectRepository.create(projectEntity); if (!project) return null; return ObjectHydrate.hydrate>(new ProjectEntity(), project); } } + diff --git a/src/common/system/ExpressServer.ts b/src/common/system/ExpressServer.ts index ec8e217b..8f381907 100644 --- a/src/common/system/ExpressServer.ts +++ b/src/common/system/ExpressServer.ts @@ -31,3 +31,4 @@ export default class ExpressServer implements ServerInterface { return this; } } + diff --git a/src/common/system/ServerInterface.ts b/src/common/system/ServerInterface.ts index e3962a03..15ea57f2 100644 --- a/src/common/system/ServerInterface.ts +++ b/src/common/system/ServerInterface.ts @@ -14,3 +14,4 @@ export default interface ServerInterface { init(config: IConfig): this; } + diff --git a/src/common/system/controller-pattern/ApiController.ts b/src/common/system/controller-pattern/ApiController.ts index 3f8458c7..f1159f3e 100644 --- a/src/common/system/controller-pattern/ApiController.ts +++ b/src/common/system/controller-pattern/ApiController.ts @@ -6,3 +6,4 @@ import HttpCodes from "@Common/system/controller-pattern/HttpCodes"; export default abstract class ApiController extends BaseController {} export { HttpCodes as ResponseStatusCodes }; + diff --git a/src/common/system/controller-pattern/BaseController.ts b/src/common/system/controller-pattern/BaseController.ts index 3b128b1f..516b7e66 100644 --- a/src/common/system/controller-pattern/BaseController.ts +++ b/src/common/system/controller-pattern/BaseController.ts @@ -2,8 +2,10 @@ import { StRoute } from "./StRoute"; import { Response } from "express"; import HttpCodes from "@Common/system/controller-pattern/HttpCodes"; + type IResponseData = {} | string | number | boolean | null | unknown; + export default abstract class BaseController { public expressRoutes!: StRoute[]; public httpCode: typeof HttpCodes = HttpCodes; diff --git a/src/common/system/controller-pattern/Controller.ts b/src/common/system/controller-pattern/Controller.ts index 91d5789f..9a5c8d2e 100644 --- a/src/common/system/controller-pattern/Controller.ts +++ b/src/common/system/controller-pattern/Controller.ts @@ -34,3 +34,4 @@ function createRoute(controller: any, route: StRoute) { } export default Controller; + diff --git a/src/common/system/controller-pattern/ErrorCatch.ts b/src/common/system/controller-pattern/ErrorCatch.ts index 8dc0aea4..d6bed57c 100644 --- a/src/common/system/controller-pattern/ErrorCatch.ts +++ b/src/common/system/controller-pattern/ErrorCatch.ts @@ -12,3 +12,4 @@ export default class ErrorCatch { next(args[args.length - 1] ?? "Unknown Error"); } } + diff --git a/src/common/system/controller-pattern/HttpCodes.ts b/src/common/system/controller-pattern/HttpCodes.ts index 8ca2500b..433b5525 100644 --- a/src/common/system/controller-pattern/HttpCodes.ts +++ b/src/common/system/controller-pattern/HttpCodes.ts @@ -1,10 +1,10 @@ -enum HttpCodes { - SUCCESS = 200, - CREATED = 201, - BAD_REQUEST = 400, - INTERNAL_ERROR = 500, - UNKNOWN_ERROR = 520, - NOT_IMPLEMENTED = 501, - NOT_FOUND = 404, -} -export default HttpCodes; +enum HttpCodes { + SUCCESS = 200, + CREATED = 201, + BAD_REQUEST = 400, + INTERNAL_ERROR = 500, + UNKNOWN_ERROR = 520, + NOT_IMPLEMENTED = 501, + NOT_FOUND = 404, +} +export default HttpCodes; diff --git a/src/common/system/controller-pattern/Methods.ts b/src/common/system/controller-pattern/Methods.ts index 43c0f6f0..b0dd3729 100644 --- a/src/common/system/controller-pattern/Methods.ts +++ b/src/common/system/controller-pattern/Methods.ts @@ -1,12 +1,7 @@ import BaseController from "./BaseController"; import { StRoute } from "./StRoute"; -function MethodsAny( - type: StRoute["type"], - path: string, - frontMiddlewares: StRoute["frontMiddlewares"] = [], - backMiddlewares: StRoute["backMiddlewares"] = [], -) { +function MethodsAny(type: StRoute["type"], path: string, frontMiddlewares: StRoute["frontMiddlewares"] = [], backMiddlewares: StRoute["backMiddlewares"] = []) { return (target: any, memberName: string, propertyDescriptor: PropertyDescriptor) => { const func = propertyDescriptor.value; const constructor: typeof BaseController = target.constructor; @@ -34,3 +29,4 @@ export const Delete = MethodsAny.bind(null, "delete"); * @description Decorator Method PUT */ export const Put = MethodsAny.bind(null, "put"); + diff --git a/src/common/system/controller-pattern/StRoute.ts b/src/common/system/controller-pattern/StRoute.ts index fe6ae78d..f216112f 100644 --- a/src/common/system/controller-pattern/StRoute.ts +++ b/src/common/system/controller-pattern/StRoute.ts @@ -7,3 +7,4 @@ export interface StRoute { frontMiddlewares: ((requests: Request, response: Response, next: NextFunction) => void)[]; backMiddlewares: ((requests: Request, response: Response, next: NextFunction) => void)[]; } + diff --git a/src/common/system/controller-pattern/exceptions/HttpException.ts b/src/common/system/controller-pattern/exceptions/HttpException.ts index 62a485b7..ceb49fa7 100644 --- a/src/common/system/controller-pattern/exceptions/HttpException.ts +++ b/src/common/system/controller-pattern/exceptions/HttpException.ts @@ -1,7 +1,7 @@ -import HttpCodes from "../HttpCodes"; - -export default class HttpException extends Error { - constructor(message: string, public httpCode: HttpCodes = HttpCodes.UNKNOWN_ERROR) { - super(message); - } -} +import HttpCodes from "../HttpCodes"; + +export default class HttpException extends Error { + constructor(message: string, public httpCode: HttpCodes = HttpCodes.UNKNOWN_ERROR) { + super(message); + } +} diff --git a/src/common/system/database/DbProvider.ts b/src/common/system/database/DbProvider.ts index 9df45a56..82a15a81 100644 --- a/src/common/system/database/DbProvider.ts +++ b/src/common/system/database/DbProvider.ts @@ -1,31 +1,32 @@ -import dotenv from "dotenv"; -import { PrismaClient } from "@prisma/client"; -import IDatabaseConfig from "../../config/IDatabaseConfig"; - -dotenv.config(); - -export default class DbProvider { - protected client = new PrismaClient({ - datasources: { - db: { - url: `postgres://${process.env["DATABASE_USER"]}:${process.env["DATABASE_PASSWORD"]}@${process.env["DATABASE_HOSTNAME"]}:${process.env["DATABASE_PORT"]}/${process.env["DATABASE_NAME"]}`, - }, - }, - }); - - constructor(protected config: IDatabaseConfig) {} - - public async connect(): Promise { - await this.client.$connect(); - console.info(`⚡️[Prisma]: Connected to ${this.config.name}`); // A Logger middleware is to be added here - } - - public getClient() { - return this.client; - } - - public async disconnect(): Promise { - await this.client.$disconnect(); - console.info(`⚡️[Prisma]: Disconnected from ${this.config.name}`); // A Logger middleware is to be added here - } -} +import dotenv from "dotenv"; +import { PrismaClient } from "@prisma/client"; +import IDatabaseConfig from "../../config/IDatabaseConfig"; + +dotenv.config(); + +export default class DbProvider { + protected client = new PrismaClient({ + datasources: { + db: { + url: `postgres://${process.env["DATABASE_USER"]}:${process.env["DATABASE_PASSWORD"]}@${process.env["DATABASE_HOSTNAME"]}:${process.env["DATABASE_PORT"]}/${process.env["DATABASE_NAME"]}`, + }, + }, + }); + + constructor(protected config: IDatabaseConfig) { + } + + public async connect(): Promise { + await this.client.$connect(); + console.info(`⚡️[Prisma]: Connected to ${this.config.name}`);// A Logger middleware is to be added here + } + + public getClient() { + return this.client; + } + + public async disconnect(): Promise { + await this.client.$disconnect(); + console.info(`⚡️[Prisma]: Disconnected from ${this.config.name}`); // A Logger middleware is to be added here + } +} diff --git a/src/common/system/database/exceptions/ORMBadQueryError.ts b/src/common/system/database/exceptions/ORMBadQueryError.ts index 89255e6a..b61c4d15 100644 --- a/src/common/system/database/exceptions/ORMBadQueryError.ts +++ b/src/common/system/database/exceptions/ORMBadQueryError.ts @@ -2,4 +2,4 @@ export class ORMBadQueryError extends Error { constructor(message: string, public error: Error) { super(message); } -} +} \ No newline at end of file diff --git a/src/common/system/database/index.ts b/src/common/system/database/index.ts index 744d3d62..6fa84a21 100644 --- a/src/common/system/database/index.ts +++ b/src/common/system/database/index.ts @@ -2,4 +2,4 @@ import IDatabaseConfig from "@Common/config/IDatabaseConfig"; import DbProvider from "./DbProvider"; export type { IDatabaseConfig }; -export default DbProvider; +export default DbProvider; \ No newline at end of file diff --git a/src/entries/Api.ts b/src/entries/Api.ts index 39470ab1..0545c9d1 100644 --- a/src/entries/Api.ts +++ b/src/entries/Api.ts @@ -22,8 +22,15 @@ Container.get(ExpressServer).init({ label, port: parseInt(port), rootUrl, - middlwares: [cors({ origin: "*" }), bodyParser.urlencoded({ extended: true }), bodyParser.json()], + middlwares: [ + cors({ origin: "*" }), + bodyParser.urlencoded({ extended: true }), + bodyParser.json(), + ], errorHandler, }); routes.start(); + + + diff --git a/src/entries/Web.ts b/src/entries/Web.ts index 8edd92b9..d1ee8274 100644 --- a/src/entries/Web.ts +++ b/src/entries/Web.ts @@ -15,7 +15,7 @@ if (!rootUrl) throw new Error(`process.env RootUrl is undefined`); Container.get(NextServer).init({ label, - isDev: process.env.NODE_ENV !== "production", + isDev: process.env.NODE_ENV !== 'production', port: parseInt(port), rootUrl, -}); +}); \ No newline at end of file