armisa-models
Version:
models of armisa!
83 lines (82 loc) • 2.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BasePropertyFactory = exports.BaseProperty = exports.BaseEntityProperties = void 0;
class BaseEntityProperties {
constructor(tableName, FA, EN, AR, SP, FR) {
this.tableName = tableName;
this.FA = FA;
this.EN = EN;
this.AR = AR;
this.SP = SP;
this.FR = FR;
this.Add = (property) => {
this.properties.push(property);
};
this.properties = [];
}
static buildNew(jsons) {
let finalJsons;
if (Array.isArray(jsons)) {
finalJsons = jsons;
}
else {
finalJsons = [jsons];
}
const results = finalJsons.map(json => {
const result = new BaseEntityProperties(json.tableName, json.fa, json.en || undefined, json.ar || undefined, json.sp || undefined, json.fr || undefined);
json.properties.forEach(prop => {
result.Add(BaseProperty.buildNew(prop));
});
return result;
});
return results;
}
}
exports.BaseEntityProperties = BaseEntityProperties;
class BaseProperty {
constructor(dataType, fieldName, FA, EN, AR, SP, FR) {
this.dataType = dataType;
this.fieldName = fieldName;
this.FA = FA;
this.EN = EN;
this.AR = AR;
this.SP = SP;
this.FR = FR;
}
static buildNew(entityJson) {
return new BaseProperty(entityJson.dataType, entityJson.fieldName, entityJson.fa, entityJson.en, entityJson.ar, entityJson.sp, entityJson.fr);
}
}
exports.BaseProperty = BaseProperty;
class BasePropertyFactory {
constructor() {
this.setEntities = (entities) => {
this.entities = BaseEntityProperties.buildNew(entities);
};
}
getCurrentProperty(entity, fieldName) {
if (fieldName === '') {
return undefined;
}
if (!entity) {
return undefined;
}
if (!entity.properties) {
return undefined;
}
if (entity.properties.length === 0) {
return undefined;
}
return entity.properties.find(i => i.fieldName === fieldName);
}
getCurrentEntity(tableName) {
if (tableName === '') {
return undefined;
}
return this.entities?.find(i => i.tableName === tableName);
}
static buildNew() {
return new BasePropertyFactory();
}
}
exports.BasePropertyFactory = BasePropertyFactory;