progress
This commit is contained in:
parent
d70253d6a6
commit
fa645dde92
51 changed files with 657 additions and 281 deletions
|
@ -1,13 +1,14 @@
|
|||
import express from "express";
|
||||
import { Routes } from "../interfaces/router";
|
||||
import cors from "cors";
|
||||
import mongoose from "mongoose";
|
||||
import { Server } from "socket.io";
|
||||
import { createServer } from "http";
|
||||
import { SocketSubscriber } from "./socket_controller";
|
||||
import { dirname } from "path";
|
||||
import { CreateFolderUseCase } from "../usecases/crete_folder_usecase";
|
||||
import { dirIsExists } from "../repository/fs";
|
||||
import fileUpload from "express-fileupload";
|
||||
import { SetLastActivePipelineToRealTimeServiceUseCase } from "../usecases/set_active_pipeline_to_realtime_service_usecase";
|
||||
import { CheckAndCreateStaticFilesFolderUseCase } from "../usecases/check_and_create_static_files_folder_usecase";
|
||||
import { DataBaseConnectUseCase } from "../usecases/database_connect_usecase";
|
||||
|
||||
export class App {
|
||||
public app: express.Application;
|
||||
|
@ -60,6 +61,11 @@ export class App {
|
|||
this.app.use(express.json());
|
||||
this.app.use(express.urlencoded({ extended: true }));
|
||||
this.app.use(express.static("public"));
|
||||
this.app.use(
|
||||
fileUpload({
|
||||
createParentPath: true,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private initializeRoutes(routes: Routes[]) {
|
||||
|
@ -68,37 +74,11 @@ export class App {
|
|||
});
|
||||
}
|
||||
async loadAppDependencies() {
|
||||
// await locator(
|
||||
// this.env == "development"
|
||||
// ? new DevEnv(this.computedFolder)
|
||||
// : new UnitTestEnv(this.computedFolder)
|
||||
// );
|
||||
await this.appStartController();
|
||||
|
||||
mongoose
|
||||
.connect("mongodb://127.0.0.1:27017/test")
|
||||
.then(() => {})
|
||||
.catch((e) => {
|
||||
console.log("ERROR:", e);
|
||||
});
|
||||
await new DataBaseConnectUseCase().call();
|
||||
await new CheckAndCreateStaticFilesFolderUseCase().call();
|
||||
await new SetLastActivePipelineToRealTimeServiceUseCase().call();
|
||||
}
|
||||
|
||||
async appStartController() {
|
||||
if (await dirIsExists(App.staticFilesStoreDir())) {
|
||||
return;
|
||||
}
|
||||
const createFolderUseCase = await new CreateFolderUseCase().call(
|
||||
App.staticFilesStoreDir()
|
||||
);
|
||||
|
||||
createFolderUseCase.fold(
|
||||
(_s) => {},
|
||||
(e) => {
|
||||
// TODO:(IDONTSUDO) need logger
|
||||
console.log(e);
|
||||
}
|
||||
);
|
||||
}
|
||||
static staticFilesStoreDir = () => {
|
||||
const dir = dirname(__filename);
|
||||
const rootDir = dir.slice(0, dir.length - 20);
|
||||
|
|
|
@ -13,14 +13,19 @@ type Method =
|
|||
| "options"
|
||||
| "head";
|
||||
|
||||
export type CallbackStrategyWithValidationModel<T> = (
|
||||
a: T
|
||||
) => Promise<Result<any, any>>;
|
||||
// TODO(IDOTSUDO):NEED IMPLEMENTS
|
||||
// interface ISubSetFeatureRouter<T>{
|
||||
// method:Method,
|
||||
// fn:CallbackStrategyWithValidationModel<T>
|
||||
// }
|
||||
export type ResponseBase = Promise<Result<any, any>>;
|
||||
|
||||
// TODO(IDONTSUDO): rewrite the router for the strategy
|
||||
export type CallbackStrategyWithEmpty = () => ResponseBase;
|
||||
export type CallbackStrategyWithValidationModel<T> = (a: T) => ResponseBase;
|
||||
export type CallbackStrategyWithIdQuery = (id: string) => ResponseBase;
|
||||
export type CallBackStrategyWithQueryPage = (page: string) => ResponseBase;
|
||||
export type CallbackStrategyWithFileUpload = (file: File) => ResponseBase;
|
||||
|
||||
interface ISubSetFeatureRouter<T> {
|
||||
method: Method;
|
||||
fn: CallbackStrategyWithValidationModel<T>;
|
||||
}
|
||||
|
||||
abstract class ICoreHttpController {
|
||||
abstract mainURL: string;
|
||||
|
@ -31,6 +36,7 @@ abstract class ICoreHttpController {
|
|||
export class CoreHttpController<V> implements ICoreHttpController {
|
||||
mainURL: string;
|
||||
validationModel: any;
|
||||
subRoutes: ISubSetFeatureRouter<any>[] = [];
|
||||
|
||||
routes = {
|
||||
POST: null,
|
||||
|
@ -47,6 +53,11 @@ export class CoreHttpController<V> implements ICoreHttpController {
|
|||
}
|
||||
|
||||
call(): Routes {
|
||||
if (this.subRoutes.isNotEmpty()) {
|
||||
this.subRoutes.map((el) => {
|
||||
console.log(this.router[el.method]);
|
||||
});
|
||||
}
|
||||
if (this.routes["POST"] != null) {
|
||||
this.router.post(
|
||||
this.mainURL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue