@etainabl/nodejs-sdk 1.1.17 → 1.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api.ts +7 -0
- package/src/units.ts +2 -2
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -275,6 +275,13 @@ export default (auth: AuthOptions, instanceOptions: CreateAxiosDefaults = {}) =>
|
|
|
275
275
|
createEmail: factory.create(etainablApi, 'emails'),
|
|
276
276
|
removeEmail: factory.remove(etainablApi, 'emails'),
|
|
277
277
|
|
|
278
|
+
// emission factors
|
|
279
|
+
getEmissionFactor: factory.getWithId(etainablApi, 'emissionFactors'),
|
|
280
|
+
listEmissionFactors: factory.list(etainablApi, 'emissionFactors'),
|
|
281
|
+
updateEmissionFactor: factory.update(etainablApi, 'emissionFactors'),
|
|
282
|
+
createEmissionFactor: factory.create(etainablApi, 'emissionFactors'),
|
|
283
|
+
removeEmissionFactor: factory.remove(etainablApi, 'emissionFactors'),
|
|
284
|
+
|
|
278
285
|
// logs
|
|
279
286
|
getLog: factory.getWithId(etainablApi, 'logs'),
|
|
280
287
|
listLogs: factory.list(etainablApi, 'logs'),
|
package/src/units.ts
CHANGED
|
@@ -60,14 +60,14 @@ const accountTypeUnitMap: { [key: string]: ETNUnit[] } = {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
// Convert units to base format
|
|
63
|
-
export const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined
|
|
63
|
+
export const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined): any => {
|
|
64
64
|
if (!type) throw new Error('Account type is required');
|
|
65
65
|
|
|
66
66
|
const baseUnit = accountTypeMap[type];
|
|
67
67
|
if (!baseUnit) throw new Error(`Account type ${type} is not supported`);
|
|
68
68
|
|
|
69
69
|
const convertedItems = items.map(item => {
|
|
70
|
-
const factor = item.factor ||
|
|
70
|
+
const factor = item.factor || 1;
|
|
71
71
|
const units = item.units || item.unit || defaultUnits || baseUnit;
|
|
72
72
|
const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
|
|
73
73
|
return { ...item, value: convertedValue, units: baseUnit };
|