UNPKG

@tractorzoom/equipment-attributes

Version:

Source of truth for equipment attributes by category

105 lines (104 loc) 5.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getClearableAttributesForCategory = exports.getTopAttributesForCategory = exports.getAttributesForCategory = exports.COMMON_ATTRIBUTES = exports.VALUE_ATTRIBUTES = exports.LOCATION_ATTRIBUTES = exports.IDENTIFYING_ATTRIBUTES = void 0; const attributes_1 = require("./attributes"); const categories_1 = require("./categories"); exports.IDENTIFYING_ATTRIBUTES = [attributes_1.YEAR, attributes_1.MAKE, attributes_1.MODEL, attributes_1.CATEGORY, attributes_1.SUBCATEGORY]; exports.LOCATION_ATTRIBUTES = [attributes_1.LOT_NUMBER, attributes_1.CITY, attributes_1.STATE, attributes_1.ZIP_CODE]; exports.VALUE_ATTRIBUTES = [attributes_1.PRICE]; exports.COMMON_ATTRIBUTES = [ ...exports.IDENTIFYING_ATTRIBUTES, ...exports.LOCATION_ATTRIBUTES, ...exports.VALUE_ATTRIBUTES, attributes_1.CONDITION, attributes_1.DESCRIPTION, attributes_1.EQUIPMENT_CONDITION, attributes_1.SERIAL, ]; const ATTRIBUTES_BY_CATEGORY = { [categories_1.CATEGORIES.AG_TRAILERS.name]: [attributes_1.LENGTH], [categories_1.CATEGORIES.CHEMICAL_APPLICATORS.name]: [attributes_1.HOURS, attributes_1.CAPACITY, attributes_1.DRIVE, attributes_1.HORSEPOWER, attributes_1.NUMBER_OF_SHANKS, attributes_1.WIDTH], [categories_1.CATEGORIES.COMBINE_HARVESTERS.name]: [ attributes_1.HOURS, attributes_1.SEPARATOR_HOURS, attributes_1.COMBINE_TYPE, attributes_1.DRIVE, attributes_1.POWERFOLD_BIN, attributes_1.CHOPPER, attributes_1.SPREADER, attributes_1.FRONT_TIRES, ], [categories_1.CATEGORIES.HARVESTING.name]: [ attributes_1.HOURS, attributes_1.SEPARATOR_HOURS, attributes_1.COMBINE_TYPE, attributes_1.DRIVE, attributes_1.FRONT_TIRES, attributes_1.NUMBER_OF_ROWS, attributes_1.POWERFOLD_BIN, attributes_1.CHOPPER, attributes_1.SPREADER, attributes_1.SPACING, attributes_1.WIDTH, ], [categories_1.CATEGORIES.HAY_AND_FORAGE.name]: [attributes_1.HOURS, attributes_1.ACRES, attributes_1.NUMBER_OF_BALES, attributes_1.LENGTH, attributes_1.WIDTH], [categories_1.CATEGORIES.MANURE_HANDLING.name]: [attributes_1.HOURS, attributes_1.CAPACITY, attributes_1.DRIVE, attributes_1.HORSEPOWER, attributes_1.NUMBER_OF_SHANKS, attributes_1.WIDTH], [categories_1.CATEGORIES.OTHER_EQUIPMENT.name]: [attributes_1.HOURS, attributes_1.CAPACITY, attributes_1.EMISSIONS, attributes_1.LENGTH, attributes_1.MILES, attributes_1.TAG_AXLE, attributes_1.TRANSMISSION, attributes_1.WIDTH], [categories_1.CATEGORIES.PLANTING.name]: [attributes_1.HOURS, attributes_1.ACRES, attributes_1.CENTER_BULK_FILL, attributes_1.NUMBER_OF_ROWS, attributes_1.ROW_CLEANERS, attributes_1.SPACING, attributes_1.WIDTH], [categories_1.CATEGORIES.TILLAGE.name]: [attributes_1.NUMBER_OF_BOTTOMS, attributes_1.NUMBER_OF_ROWS, attributes_1.NUMBER_OF_SHANKS, attributes_1.SPACING, attributes_1.WIDTH], [categories_1.CATEGORIES.TRACTORS.name]: [ attributes_1.HOURS, attributes_1.CAB, attributes_1.DRIVE, attributes_1.HORSEPOWER, attributes_1.BELLY_MOWER, attributes_1.LOADER, attributes_1.THREE_POINT_HITCH, attributes_1.REAR_PTO, attributes_1.FRONT_TIRES, attributes_1.REAR_TIRES, ], [categories_1.CATEGORIES.CONSTRUCTION.name]: [attributes_1.HOURS, attributes_1.CAPACITY, attributes_1.EMISSIONS, attributes_1.LENGTH, attributes_1.MILES, attributes_1.TAG_AXLE, attributes_1.TRANSMISSION, attributes_1.WIDTH], }; const getAttributesForCategory = (categoryName) => { if (!categoryName) return []; if (categoryName in ATTRIBUTES_BY_CATEGORY) { return [...exports.COMMON_ATTRIBUTES, ...ATTRIBUTES_BY_CATEGORY[categoryName]]; } return exports.COMMON_ATTRIBUTES; }; exports.getAttributesForCategory = getAttributesForCategory; const getTopAttributesForCategory = (categoryName) => { const importantAttributes = [attributes_1.HOURS.name, attributes_1.HORSEPOWER.name, attributes_1.LENGTH.name, attributes_1.SEPARATOR_HOURS.name]; const semiImportantAttributes = [attributes_1.NUMBER_OF_ROWS.name, attributes_1.NUMBER_OF_BOTTOMS.name]; const attributes = (0, exports.getAttributesForCategory)(categoryName); let topAttributes = attributes.filter((attr) => importantAttributes.includes(attr.name)); if (topAttributes.length < 2) { topAttributes = [...topAttributes, ...attributes.filter((attr) => semiImportantAttributes.includes(attr.name))]; } return topAttributes; }; exports.getTopAttributesForCategory = getTopAttributesForCategory; const getClearableAttributesForCategory = (categoryName) => { const allAttributes = (0, attributes_1.getAllAttributes)(); const attributesNotToClear = (0, exports.getAttributesForCategory)(categoryName); const nulledIrrelevantAttributes = {}; allAttributes.forEach((attribute) => { const doNotClear = attributesNotToClear.find((att) => att.name === attribute.name); if (!doNotClear) { nulledIrrelevantAttributes[attribute.name] = null; if (attribute.name === attributes_1.CAPACITY.name) { nulledIrrelevantAttributes.gallon = null; nulledIrrelevantAttributes.ton = null; nulledIrrelevantAttributes.bushels = null; } if (attribute.name === attributes_1.WIDTH.name) { nulledIrrelevantAttributes.widthFeet = null; nulledIrrelevantAttributes.widthInches = null; } } }); return nulledIrrelevantAttributes; }; exports.getClearableAttributesForCategory = getClearableAttributesForCategory;