process
This commit is contained in:
parent
7ff6165882
commit
ae9842d5e1
61 changed files with 929 additions and 433 deletions
|
@ -2,11 +2,11 @@ import { validationModelMiddleware } from "../middlewares/validation_model";
|
|||
import { Result } from "../helpers/result";
|
||||
import { Router, Request, Response } from "express";
|
||||
import { IRouteModel, Routes } from "../interfaces/router";
|
||||
import { CoreValidation } from "../validations/core_validation";
|
||||
|
||||
export type HttpMethodType = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "PATCH" | "HEAD";
|
||||
|
||||
export type ResponseBase = Promise<Result<any, any>>;
|
||||
|
||||
export abstract class CallbackStrategyWithEmpty {
|
||||
abstract call(): ResponseBase;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ export abstract class CallbackStrategyWithValidationModel<V> {
|
|||
abstract call(a: V): ResponseBase;
|
||||
}
|
||||
export abstract class CallbackStrategyWithIdQuery {
|
||||
abstract idValidationExpression: RegExp | null;
|
||||
abstract idValidationExpression: CoreValidation;
|
||||
abstract call(id: string): ResponseBase;
|
||||
}
|
||||
export abstract class CallBackStrategyWithQueryPage {
|
||||
|
@ -84,7 +84,24 @@ export class CoreHttpController<V> implements ICoreHttpController {
|
|||
throw Error("needs to be implimed");
|
||||
}
|
||||
if (el.fn instanceof CallbackStrategyWithIdQuery) {
|
||||
throw Error("needs to be implimed");
|
||||
if (req.query.id === undefined) {
|
||||
res.status(400).json("request query id is null, need query id ?id={id:String}");
|
||||
return;
|
||||
}
|
||||
if (el.fn.idValidationExpression !== undefined) {
|
||||
if (!el.fn.idValidationExpression.regExp.test(req.query.id)) {
|
||||
res
|
||||
.status(400)
|
||||
.json(
|
||||
`request query id must fall under the pattern: ${el.fn.idValidationExpression.regExp} message: ${el.fn.idValidationExpression.message} `
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
await this.responseHelper(res, el.fn.call(req.query.id));
|
||||
}
|
||||
} else {
|
||||
await this.responseHelper(res, el.fn.call(req["files"]["file"]));
|
||||
}
|
||||
}
|
||||
if (el.fn instanceof CallBackStrategyWithQueryPage) {
|
||||
throw Error("needs to be implimed");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue