alapa
Version:
A cutting-edge web development framework designed to revolutionize the way developers build modern web applications.
56 lines (55 loc) • 1.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ControllerRoutes = void 0;
const excludedMethods = [
"constructor",
"hasOwnProperty",
"isPrototypeOf",
"propertyIsEnumerable",
"toString",
"toLocaleString",
"valueOf",
"__defineGetter__",
"__defineSetter__",
"__lookupGetter__",
"__lookupSetter__",
];
function getObjectPropertiesTypes(obj) {
const types = {};
while (obj !== null) {
const properties = [];
properties.push(...Object.getOwnPropertyNames(obj));
for (const property of properties) {
types[property] = typeof obj[property];
}
obj = Object.getPrototypeOf(obj);
}
return types;
}
class ControllerRoutes {
methodStructure = {
get: "/",
show: "/:id",
update: "/:id",
destroy: "/:id",
create: "/",
index: "/",
edit: "/:id/edit",
};
static make = (path, controllerClass, route) => {
const controller = new controllerClass(); // Create an instance of the controller
const propertyTypes = getObjectPropertiesTypes(controller);
const methods = Object.keys(propertyTypes).filter((key) => {
const type = propertyTypes[key];
if (type === "function" && !excludedMethods.includes(key)) {
return key;
}
});
for (const name of methods) {
if (name.startsWith("show")) {
route["get"](`/${path}/:id`, controller[name]);
}
}
};
}
exports.ControllerRoutes = ControllerRoutes;
;