bapig
Version:
Welcome to BAPIG, a powerful backend solution designed to streamline your development process. With over 40 built-in functionalities, BAPIG simplifies CRUD operations, facilitates authentication and encryption, handles communication tasks, and much more.
43 lines • 2.02 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSingleSchema = void 0;
// Import necessary modules
var fs_1 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
var helpers_1 = require("../helpers");
/**
* Function to retrieve a single table schema by its filename.
* @param {string} fileName - The name of the schema file.
* @returns {controllerResponse} Returns success and message containing the schema if successful; otherwise, returns an error message.
*/
function getSingleSchema(fileName) {
try {
// Check if the models directory exists
var schemaDirectory = fs_1.default.existsSync(helpers_1.modelsDirectory) ? helpers_1.modelsDirectory : undefined;
if (schemaDirectory) {
// Load the schema from the specified file
var message = require(path_1.default.join(schemaDirectory, fileName));
// Check if the schema is an ES module
if (message.__esModule) {
// Use the default export if available; otherwise, use the named export
return {
success: true,
message: message.default || message[fileName] || "No export for ".concat(fileName, " model in ").concat(schemaDirectory),
};
}
// Return the actual schema
return { success: true, message: message.default || message };
}
// Return an error if the models directory does not exist
return { success: false, message: "".concat(fileName, " schema filename does not exist") };
}
catch (error) {
// Return an error if an exception occurs
return { success: false, message: error.message };
}
}
exports.getSingleSchema = getSingleSchema;
//# sourceMappingURL=single.js.map