finish the launch

This commit is contained in:
IDONTSUDO 2023-10-31 09:03:41 +03:00
parent 6ca82f8c2e
commit fbcfba3948
12 changed files with 58 additions and 92 deletions

View file

@ -2,8 +2,7 @@ import { validationModelMiddleware } from "../middlewares/validation_model";
import { Result } from "../helper/result";
import { Router, Request, Response } from "express";
import { IRouteModel, Routes } from "../interfaces/router";
export type CallBackFunction<T> = (a: T) => Promise<Result<any, any>>;
abstract class ICoreHttpController {
@ -40,10 +39,8 @@ export class CoreHttpController<V> implements ICoreHttpController {
);
}
if (this.routes["DELETE"] != null) {
this.router.delete(
this.url,
(req, res) =>
this.requestResponseController<V>(req, res, this.routes["DELETE"])
this.router.delete(this.url, (req, res) =>
this.requestResponseController<V>(req, res, this.routes["DELETE"])
);
}
if (this.routes["PUT"] != null) {
@ -75,24 +72,20 @@ export class CoreHttpController<V> implements ICoreHttpController {
res: Response,
usecase: CallBackFunction<T>
) {
let payload = null
let payload = null;
if (req["model"] != undefined) {
payload = req.body as T
payload = req.body as T;
}
if (req.query.page !== undefined) {
payload = String(req.query.page)
payload = String(req.query.page);
}
if (req.query.id !== undefined) {
payload = String(req.query.id)
payload = String(req.query.id);
}
(await usecase(payload)).fold(
(ok) => {
res.json(ok);
@ -112,4 +105,3 @@ export class CoreHttpController<V> implements ICoreHttpController {
this.routes["GET"] = usecase;
}
}