formatting code upload project instance to files
This commit is contained in:
parent
ce4c98ff13
commit
a0b4f00f47
65 changed files with 399 additions and 748 deletions
|
@ -19,24 +19,16 @@ export class CrudController<V, D> extends CoreHttpController<V> {
|
|||
}
|
||||
init() {
|
||||
if (this.routes["POST"] === null) {
|
||||
this.routes["POST"] = new CreateDataBaseModelUseCase<D>(
|
||||
this.dataBaseModel
|
||||
).call;
|
||||
this.routes["POST"] = new CreateDataBaseModelUseCase<D>(this.dataBaseModel).call;
|
||||
}
|
||||
if (this.routes["GET"] === null) {
|
||||
this.routes["GET"] = new PaginationDataBaseModelUseCase<D>(
|
||||
this.dataBaseModel
|
||||
).call;
|
||||
this.routes["GET"] = new PaginationDataBaseModelUseCase<D>(this.dataBaseModel).call;
|
||||
}
|
||||
if (this.routes["DELETE"] === null) {
|
||||
this.routes["DELETE"] = new DeleteDataBaseModelUseCase<D>(
|
||||
this.dataBaseModel
|
||||
).call;
|
||||
this.routes["DELETE"] = new DeleteDataBaseModelUseCase<D>(this.dataBaseModel).call;
|
||||
}
|
||||
if (this.routes["PUT"] === null) {
|
||||
this.routes["PUT"] = new UpdateDataBaseModelUseCase<V, D>(
|
||||
this.dataBaseModel
|
||||
).call;
|
||||
this.routes["PUT"] = new UpdateDataBaseModelUseCase<V, D>(this.dataBaseModel).call;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,7 @@ import { Result } from "../helper/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 Method = "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head";
|
||||
|
||||
export type ResponseBase = Promise<Result<any, any>>;
|
||||
|
||||
|
@ -75,7 +67,7 @@ export class CoreHttpController<V> implements ICoreHttpController {
|
|||
return;
|
||||
},
|
||||
(err) => {
|
||||
res.status(400).json(err);
|
||||
res.status(400).json({ error: String(err) });
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
@ -83,61 +75,46 @@ 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) => {
|
||||
if (el.fn instanceof CallbackStrategyWithValidationModel) {
|
||||
// TODO(IDONTSUDO):
|
||||
throw Error("needs to be implimed");
|
||||
}
|
||||
if (el.fn instanceof CallbackStrategyWithIdQuery) {
|
||||
throw Error("needs to be implimed");
|
||||
}
|
||||
if (el.fn instanceof CallBackStrategyWithQueryPage) {
|
||||
throw Error("needs to be implimed");
|
||||
}
|
||||
if (el.fn instanceof CallbackStrategyWithEmpty) {
|
||||
await this.responseHelper(res, el.fn.call());
|
||||
this.router[el.method](this.mainURL + "/" + el.subUrl, async (req, res) => {
|
||||
if (el.fn instanceof CallbackStrategyWithValidationModel) {
|
||||
// TODO(IDONTSUDO):
|
||||
throw Error("needs to be implimed");
|
||||
}
|
||||
if (el.fn instanceof CallbackStrategyWithIdQuery) {
|
||||
throw Error("needs to be implimed");
|
||||
}
|
||||
if (el.fn instanceof CallBackStrategyWithQueryPage) {
|
||||
throw Error("needs to be implimed");
|
||||
}
|
||||
if (el.fn instanceof CallbackStrategyWithEmpty) {
|
||||
await this.responseHelper(res, el.fn.call());
|
||||
return;
|
||||
}
|
||||
|
||||
if (el.fn instanceof CallbackStrategyWithFileUpload) {
|
||||
if (req["files"] === undefined) {
|
||||
res.status(400).json("need files to form-data request");
|
||||
return;
|
||||
}
|
||||
|
||||
if (el.fn instanceof CallbackStrategyWithFileUpload) {
|
||||
if (req["files"] === undefined) {
|
||||
res.status(400).json("need files to form-data request");
|
||||
return;
|
||||
}
|
||||
if (req["files"]["file"] === undefined) {
|
||||
res.status(400).json("need file to form data request");
|
||||
return;
|
||||
}
|
||||
if (el.fn instanceof CallbackStrategyWithFileUpload) {
|
||||
if (
|
||||
!el.fn.checkingFileExpression.test(
|
||||
req["files"]["file"]["name"]
|
||||
)
|
||||
) {
|
||||
res
|
||||
.status(400)
|
||||
.json(
|
||||
"a file with this extension is expected: " +
|
||||
String(el.fn.checkingFileExpression)
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
await this.responseHelper(res, el.fn.call(req["files"]["file"]));
|
||||
if (req["files"]["file"] === undefined) {
|
||||
res.status(400).json("need file to form data request");
|
||||
return;
|
||||
}
|
||||
if (el.fn instanceof CallbackStrategyWithFileUpload) {
|
||||
if (!el.fn.checkingFileExpression.test(req["files"]["file"]["name"])) {
|
||||
res.status(400).json("a file with this extension is expected: " + String(el.fn.checkingFileExpression));
|
||||
return;
|
||||
}
|
||||
}
|
||||
await this.responseHelper(res, el.fn.call(req["files"]["file"]));
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (this.routes["POST"] != null) {
|
||||
this.router.post(
|
||||
this.mainURL,
|
||||
validationModelMiddleware(this.validationModel),
|
||||
(req, res) =>
|
||||
this.requestResponseController<V>(req, res, this.routes["POST"])
|
||||
this.router.post(this.mainURL, validationModelMiddleware(this.validationModel), (req, res) =>
|
||||
this.requestResponseController<V>(req, res, this.routes["POST"])
|
||||
);
|
||||
}
|
||||
if (this.routes["DELETE"] != null) {
|
||||
|
@ -146,17 +123,12 @@ export class CoreHttpController<V> implements ICoreHttpController {
|
|||
);
|
||||
}
|
||||
if (this.routes["PUT"] != null) {
|
||||
this.router.put(
|
||||
this.mainURL,
|
||||
validationModelMiddleware(this.validationModel),
|
||||
(req, res) =>
|
||||
this.requestResponseController<V>(req, res, this.routes["PUT"])
|
||||
this.router.put(this.mainURL, validationModelMiddleware(this.validationModel), (req, res) =>
|
||||
this.requestResponseController<V>(req, res, this.routes["PUT"])
|
||||
);
|
||||
}
|
||||
if (this.routes["GET"] != null) {
|
||||
this.router.get(this.mainURL, (req, res) =>
|
||||
this.requestResponseController<V>(req, res, this.routes["GET"])
|
||||
);
|
||||
this.router.get(this.mainURL, (req, res) => this.requestResponseController<V>(req, res, this.routes["GET"]));
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -193,7 +165,7 @@ export class CoreHttpController<V> implements ICoreHttpController {
|
|||
return;
|
||||
},
|
||||
(err) => {
|
||||
res.status(400).json(err);
|
||||
res.status(400).json({ error: String(err) });
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -8,4 +8,3 @@ export class SocketSubscriber<T> {
|
|||
this.event = event;
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue