crud test controller and class validator mocker generate classes
This commit is contained in:
parent
6c85616c99
commit
9617d313a1
24 changed files with 242 additions and 108 deletions
|
@ -9,25 +9,46 @@ import fileUpload from "express-fileupload";
|
|||
import { SetLastActivePipelineToRealTimeServiceScenario } from "../scenarios/set_active_pipeline_to_realtime_service_scenario";
|
||||
import { CheckAndCreateStaticFilesFolderUseCase } from "../usecases/check_and_create_static_files_folder_usecase";
|
||||
import { DataBaseConnectUseCase } from "../usecases/database_connect_usecase";
|
||||
import { TypedEvent } from "../helpers/typed_event";
|
||||
|
||||
export class App {
|
||||
export enum ServerStatus {
|
||||
init = "init",
|
||||
finished = "finshed",
|
||||
error = "error",
|
||||
}
|
||||
export enum Environment {
|
||||
DEV = "DEV",
|
||||
E2E_TEST = "E2E_TEST",
|
||||
}
|
||||
|
||||
export class App extends TypedEvent<ServerStatus> {
|
||||
public app: express.Application;
|
||||
public port: number;
|
||||
public env: string;
|
||||
public env: Environment;
|
||||
public socketSubscribers: SocketSubscriber<any>[];
|
||||
public io: Server;
|
||||
status: ServerStatus;
|
||||
|
||||
constructor(routes: Routes[], socketSubscribers: SocketSubscriber<any>[]) {
|
||||
constructor(routes: Routes[] = [], socketSubscribers: SocketSubscriber<any>[] = [], env = Environment.DEV) {
|
||||
super();
|
||||
this.init(routes, socketSubscribers, env);
|
||||
}
|
||||
|
||||
public init(routes: Routes[], socketSubscribers: SocketSubscriber<any>[], env: Environment) {
|
||||
this.port = 4001;
|
||||
this.socketSubscribers = socketSubscribers;
|
||||
this.env = "dev";
|
||||
this.env = env;
|
||||
this.app = express();
|
||||
this.setServerStatus(ServerStatus.init);
|
||||
|
||||
this.loadAppDependencies().then(() => {
|
||||
this.initializeMiddlewares();
|
||||
this.initializeRoutes(routes);
|
||||
if (this.status !== ServerStatus.error) {
|
||||
this.setServerStatus(ServerStatus.finished);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public listen() {
|
||||
const httpServer = createServer(this.app);
|
||||
const io = new Server(httpServer, {
|
||||
|
@ -49,9 +70,13 @@ export class App {
|
|||
console.info(`🚀 WS ws://localhost:${this.port}`);
|
||||
console.info(`=================================`);
|
||||
});
|
||||
|
||||
this.io = io;
|
||||
}
|
||||
|
||||
setServerStatus(status: ServerStatus) {
|
||||
this.emit(status);
|
||||
this.status = status;
|
||||
}
|
||||
public getServer() {
|
||||
return this.app;
|
||||
}
|
||||
|
@ -75,12 +100,19 @@ export class App {
|
|||
});
|
||||
}
|
||||
|
||||
async loadAppDependencies() {
|
||||
if ((await new DataBaseConnectUseCase().call()).isFailure()) {
|
||||
console.log("database connect error");
|
||||
}
|
||||
await new CheckAndCreateStaticFilesFolderUseCase().call();
|
||||
await new SetLastActivePipelineToRealTimeServiceScenario().call();
|
||||
async loadAppDependencies(): Promise<void> {
|
||||
const dataBaseName = this.env === Environment.E2E_TEST ? "e2e_test" : "dev";
|
||||
// TODO(IDONTSUDO):maybe convert it to a class and map it there
|
||||
const result = await new DataBaseConnectUseCase().call(dataBaseName);
|
||||
await result.fold(
|
||||
async (_s) => {
|
||||
await new CheckAndCreateStaticFilesFolderUseCase().call();
|
||||
await new SetLastActivePipelineToRealTimeServiceScenario().call();
|
||||
},
|
||||
async (_e) => {
|
||||
this.setServerStatus(ServerStatus.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
static staticFilesStoreDir = () => {
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Result } from "../helpers/result";
|
|||
import { Router, Request, Response } from "express";
|
||||
import { IRouteModel, Routes } from "../interfaces/router";
|
||||
|
||||
export type Method = "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head";
|
||||
export type HttpMethodType = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "PATCH" | "HEAD";
|
||||
|
||||
export type ResponseBase = Promise<Result<any, any>>;
|
||||
|
||||
|
@ -29,7 +29,7 @@ export abstract class CallbackStrategyWithFileUpload {
|
|||
}
|
||||
|
||||
interface ISubSetFeatureRouter<T> {
|
||||
method: Method;
|
||||
method: HttpMethodType;
|
||||
subUrl: string;
|
||||
fn:
|
||||
| CallbackStrategyWithValidationModel<T>
|
||||
|
@ -78,7 +78,7 @@ export class CoreHttpController<V> implements ICoreHttpController {
|
|||
call(): Routes {
|
||||
if (this.subRoutes.isNotEmpty()) {
|
||||
this.subRoutes.map((el) => {
|
||||
this.router[el.method](this.mainURL + "/" + el.subUrl, async (req, res) => {
|
||||
this.router[el.method.toLowerCase()](this.mainURL + "/" + el.subUrl, async (req, res) => {
|
||||
if (el.fn instanceof CallbackStrategyWithValidationModel) {
|
||||
// TODO(IDONTSUDO):
|
||||
throw Error("needs to be implimed");
|
||||
|
|
26
server/src/core/controllers/routes.ts
Normal file
26
server/src/core/controllers/routes.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { NixStoreManagerPresentation } from "../../features/nix_store_manager/nix_store_manager";
|
||||
import { PipelinePresentation } from "../../features/pipelines/pipeline_presentation";
|
||||
import { ProcessPresentation } from "../../features/process/process_presentation";
|
||||
import { ProjectInstancePresentation } from "../../features/project_instance/project_instance_presentation";
|
||||
import { ProjectsPresentation } from "../../features/projects/projects_presentation";
|
||||
import { RealTimePresentation } from "../../features/realtime/realtime_presentation";
|
||||
import { TriggerPresentation } from "../../features/triggers/triggers_presentation";
|
||||
import { extensions } from "../extensions/extensions";
|
||||
import { Routes } from "../interfaces/router";
|
||||
|
||||
extensions();
|
||||
|
||||
export const routersImplementPureCrud = [
|
||||
new TriggerPresentation(),
|
||||
new ProjectsPresentation(),
|
||||
new ProcessPresentation(),
|
||||
new PipelinePresentation(),
|
||||
];
|
||||
|
||||
export const httpRoutes: Routes[] = [
|
||||
new RealTimePresentation(),
|
||||
new ProjectInstancePresentation(),
|
||||
new NixStoreManagerPresentation(),
|
||||
]
|
||||
.concat(routersImplementPureCrud)
|
||||
.map((el) => el.call());
|
Loading…
Add table
Add a link
Reference in a new issue