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 = () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue