Starting in 1.81 there is a new unit conversion helper that allows data queries to return a simple unit ID for measures. This unit ID can have attributes looked up via a singleton unit measure object that is invoked via the forUnits utility.

forUnits helper – loadUnitData()

This method lives in utils/helpers/forUnits.

The method creates a singleton instantiation of the UnitMeasureProcess data processor. That means there is one re-usable copy of the object for the entire lifecycle of the API calls.

This method creates a data processing connection to the UnitMeasures model and persistent data behind it. It reads all the active (status code = active) records from the unit measures table. These records are stored in the Units property in simplified array that matches the data returned from the database query.

It also creates a UnitsByID object that is an indexed object where the keys are the unit IDs, making for a quick reference to get all the properties of a unit when given only the integer ID.

UnitMeasureProcess Objects

get( id:number , property: string)

Get unit meta based on the unit ID.

An example of using the get calls.

load()

Sets up the Units and UnitsByID properties by reading all active units of measure from the database.

Units []

The units of measure record array with simplified data.

UnitsByID

The Units entries mapped by unit IDs.