sequelize-ts-boilerplate
Version:
A REST API scaffolding tool designed to scale and easily generate CRUD endpoints based on database schema design
36 lines • 2.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const general_utils_1 = require("../../utils/general-utils");
class TableProperty {
constructor(propertyName, tableName, autoSequelizeTableData, config) {
this.propName = propertyName;
this.lowerCasePropName = general_utils_1.default.lowerCaseFirstLetter(propertyName);
this.type = general_utils_1.default.getType(config.DATABASE_CONNECTION_SETINGS[config.ENV].dialect, autoSequelizeTableData[propertyName].type);
this.isAllowNull = autoSequelizeTableData[propertyName].allowNull || false;
this.isPrimaryKey = general_utils_1.default.isPrimaryKey(propertyName, autoSequelizeTableData[propertyName].primaryKey, config.ORM_GENERATE.pkIdentifier);
this.isAutoIncrement = (this.isPrimaryKey || autoSequelizeTableData[propertyName].autoIncrement) ? true : false;
this.defaultValue = autoSequelizeTableData[propertyName].defaultValue || null;
this.isRef = autoSequelizeTableData[propertyName].foreignKey && autoSequelizeTableData[propertyName].foreignKey.target_table ? true : false;
this.isLookup = general_utils_1.default.isLookup(propertyName, config.ORM_GENERATE.lookup);
if (this.isRef) {
this.reference = {
model: autoSequelizeTableData[propertyName].foreignKey.target_table,
lowerCaseModel: general_utils_1.default.lowerCaseFirstLetter(autoSequelizeTableData[propertyName].foreignKey.target_table),
key: autoSequelizeTableData[propertyName].foreignKey.target_column,
isToSelf: autoSequelizeTableData[propertyName].foreignKey.target_table === tableName,
isMapTable: general_utils_1.default.isMapTable(tableName, config.ORM_GENERATE.manyToManyIdentifiers)
};
}
else {
this.reference = {};
}
if (this.isLookup) {
this.lookup = {
tableName: config.ORM_GENERATE.lookup.tableName,
propName: general_utils_1.default.makeLookupPropName(propertyName, config.ORM_GENERATE.lookup)
};
}
}
}
exports.TableProperty = TableProperty;
//# sourceMappingURL=TableProperty.js.map