@miracledevs/paradigm-express-webapi
Version:
An easy to use MVC WebApi implementation over Express.
35 lines • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Action = void 0;
const action_type_1 = require("./action-type");
const http_method_1 = require("../shared/http-method");
const action_type_collection_1 = require("./action-type-collection");
require("reflect-metadata");
const object_type_1 = require("@miracledevs/paradigm-web-di/object-type");
function Action(actionDescriptor) {
return (controller, methodName, _) => {
const controllerName = (0, object_type_1.getObjectTypeName)(controller);
if (!controller)
throw new Error('Can not decorate a null or undefined value as a controller.');
if (!methodName)
throw new Error('Can not decorate a null or undefined method as an action.');
if (action_type_collection_1.ActionTypeCollection.globalInstance.contains(controllerName, methodName))
throw new Error(`The action '${controllerName}.${methodName}' was already registered.`);
if (!actionDescriptor)
actionDescriptor = {
route: "",
query: "",
filters: [],
fromBody: false,
method: http_method_1.HttpMethod.GET
};
if (!actionDescriptor.method) {
const methodByConvention = http_method_1.HttpMethod[methodName.toUpperCase()];
actionDescriptor.method = methodByConvention ? methodByConvention : http_method_1.HttpMethod.GET;
}
const actionType = new action_type_1.ActionType(controller.constructor, methodName, actionDescriptor, Reflect.getMetadata("design:paramtypes", controller, methodName), Reflect.getMetadata("design:returntype", controller, methodName));
action_type_collection_1.ActionTypeCollection.globalInstance.register(actionType);
};
}
exports.Action = Action;
//# sourceMappingURL=action.js.map