@tractorzoom/equipment-attributes
Version:
Source of truth for equipment attributes by category
70 lines (69 loc) • 3.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getVariableDetail = void 0;
const attributes_by_category_and_subcategory_1 = require("./attributes-by-category-and-subcategory");
const categories_1 = require("./categories");
const format_1 = require("./utilities/format");
const get_attr_text_1 = require("./utilities/get-attr-text");
const getCapacity = ({ bushels, gallon, ton }) => {
if (gallon) {
return `${(0, format_1.formatNumberWithThousandSeparator)(gallon)} Gal`;
}
if (ton) {
return `${(0, format_1.formatNumberWithThousandSeparator)(ton)} T`;
}
if (bushels) {
return `${(0, format_1.formatNumberWithThousandSeparator)(bushels)} Bu`;
}
return '---';
};
const getHours = ({ hours, separatorHours }, category) => {
const hoursLabel = hours ? `${(0, format_1.formatNumberWithThousandSeparator)(`${hours}`)} Hrs` : '--- Hrs';
const separatorHoursLabel = separatorHours
? `${(0, format_1.formatNumberWithThousandSeparator)(`${separatorHours}`)} Sep Hrs`
: '--- Sep Hrs';
const hasSepHours = [categories_1.CATEGORIES.HARVESTING.name, categories_1.CATEGORIES.COMBINE_HARVESTERS.name].includes(category);
return `${hoursLabel}${hasSepHours ? ` / ${separatorHoursLabel}` : ''}`;
};
const getLength = (length) => (length ? `${(0, format_1.formatNumberWithThousandSeparator)(length)} Ft` : '--- Ft');
const getNumberOfRows = (numberOfRows) => numberOfRows ? `${(0, format_1.formatNumberWithThousandSeparator)(numberOfRows)} Rows` : '--- Rows';
const getWidth = ({ widthFeet, widthInches }) => {
let width = '';
if (widthFeet)
width += `${(0, format_1.formatNumberWithThousandSeparator)(widthFeet)} Ft`;
if (widthFeet && widthInches)
width += ' ';
if (widthInches)
width += `${(0, format_1.formatNumberWithThousandSeparator)(widthInches)} In`;
return width.length ? width : '--- Ft';
};
const getVariableDetail = (equipment) => {
if (equipment.subcategory) {
const attr = (0, attributes_by_category_and_subcategory_1.getTopAttributesForCategoryAndSubCategory)(equipment.category, equipment.subcategory);
const attributeArray = attr.map((attribute) => (0, get_attr_text_1.getAttrText)(attribute, equipment)).filter((attr) => !!attr);
return attributeArray.join(' ');
}
else {
if (equipment.category === categories_1.CATEGORIES.MANURE_HANDLING.name ||
equipment.category === categories_1.CATEGORIES.CHEMICAL_APPLICATORS.name) {
return getCapacity(equipment);
}
if (equipment.category === categories_1.CATEGORIES.TRACTORS.name ||
equipment.category === categories_1.CATEGORIES.HARVESTING.name ||
equipment.category === categories_1.CATEGORIES.COMBINE_HARVESTERS.name ||
equipment.category === categories_1.CATEGORIES.OTHER_EQUIPMENT.name) {
return getHours(equipment, equipment.category);
}
if (equipment.category === categories_1.CATEGORIES.AG_TRAILERS.name) {
return getLength(equipment.length);
}
if (equipment.category === categories_1.CATEGORIES.PLANTING.name) {
return getNumberOfRows(equipment.numberOfRows);
}
if (equipment.category === categories_1.CATEGORIES.TILLAGE.name || equipment.category === categories_1.CATEGORIES.HAY_AND_FORAGE.name) {
return getWidth(equipment);
}
}
return '---';
};
exports.getVariableDetail = getVariableDetail;