@holaluz/pomada
Advanced tools
Comparing version 1.0.3 to 1.1.0-beta.1
@@ -1,4 +0,1 @@ | ||
export { EnergyFee } from './product-fees/domain/energy-fee'; | ||
export { ProductFee } from './product-fees/domain/product-fee'; | ||
export { ProductName } from './product-fees/domain/product-name'; | ||
export { getProductFees, GetProductFeesParams } from './product-fees/application/get-product-fees'; | ||
export { getProductFees } from './product-fees/application/get-product-fees'; |
@@ -1,2 +0,14 @@ | ||
export { ProductName } from './product-fees/domain/product-name'; | ||
// TODO: we should export each module individually, not in an index.ts file | ||
// We want things like: import { supplyPoint } from 'this-repository/supply-point | ||
// instead of importing everything from 'this-repository' | ||
export { getProductFees } from './product-fees/application/get-product-fees'; | ||
// getProductFees( | ||
// { | ||
// cups: | ||
// 'def502007780c632e2f5002c8faf93b5c74e1e65b6a08a9bee7b5abd21f60555a9c170f2946b3719cc098d90d6023c2e1e7ac6db293cc74b7fffb69415c7040a9376e2a1005eb696b8f1e76cdfb31fe8227fe65bff3b3492879b4396f7d7e8e88122f8db50453c19', | ||
// }, | ||
// { | ||
// onSuccess: () => {}, | ||
// onCupsInvalid: () => {}, | ||
// } | ||
// ) |
@@ -1,5 +0,10 @@ | ||
import { ProductFee } from '../domain/product-fee'; | ||
export declare type GetProductFeesParams = { | ||
cups: String; | ||
import { CupsError } from '../domain/cups-error'; | ||
import { SupplyPoint } from '../domain/supply-point'; | ||
declare type GetProductFeesParams = { | ||
cups: string; | ||
}; | ||
declare type GetProductFeesCallbacks = { | ||
onSuccess: (supplyPoint: SupplyPoint) => void; | ||
onCupsInvalid: (cupsError: CupsError) => void; | ||
}; | ||
/** | ||
@@ -9,2 +14,3 @@ * For a given supply point, calculates all the available products | ||
*/ | ||
export declare function getProductFees({ cups }: GetProductFeesParams): Promise<ProductFee[]>; | ||
export declare function getProductFees({ cups }: GetProductFeesParams, { onSuccess, onCupsInvalid }: GetProductFeesCallbacks): Promise<void>; | ||
export {}; |
@@ -0,1 +1,5 @@ | ||
import { isCupsValid } from '../infrastructure/is-cups-valid'; | ||
import { getSupplyPoint } from '../infrastructure/get-supply-point'; | ||
import { getPricesOfProduct } from '../infrastructure/get-prices-of-product'; | ||
import { getFeeOfProduct } from '../infrastructure/get-fee-of-product'; | ||
import { ProductName } from '../domain/product-name'; | ||
@@ -6,15 +10,34 @@ /** | ||
*/ | ||
export function getProductFees({ cups }) { | ||
return Promise.resolve([ | ||
{ | ||
name: ProductName.classic, | ||
fee: 30, | ||
energyFees: [ | ||
{ | ||
name: 'P1', | ||
fee: 0.034, | ||
}, | ||
], | ||
}, | ||
export async function getProductFees({ cups }, { onSuccess, onCupsInvalid }) { | ||
const isCupsValidRequest = await isCupsValid(cups); | ||
if (isCupsValidRequest.isFail()) { | ||
return onCupsInvalid(isCupsValidRequest.getFail()); | ||
} | ||
const supplyPointRequest = await getSupplyPoint(cups); | ||
if (supplyPointRequest.isFail()) { | ||
return onCupsInvalid(supplyPointRequest.getFail()); | ||
} | ||
const supplyPoint = supplyPointRequest.getSuccess(); | ||
await Promise.all([ | ||
...supplyPoint.products.map(async (product) => { | ||
if (product.name === ProductName.fairFee) | ||
return; | ||
const pricesResult = await getPricesOfProduct(product.id); | ||
// Fixme: what if we have error? | ||
if (pricesResult.isSuccess()) { | ||
const prices = pricesResult.getSuccess(); | ||
product.powerFees = prices.power; | ||
product.energyFees = prices.energy; | ||
} | ||
}), | ||
...supplyPoint.products.map(async (product) => { | ||
const feeResult = await getFeeOfProduct(product.id, supplyPoint.consumption, supplyPoint.currentPower, supplyPoint.optimizedPower); | ||
// Fixme: what if we have error? | ||
if (feeResult.isSuccess()) { | ||
const fee = feeResult.getSuccess(); | ||
product.fee = fee; | ||
} | ||
}), | ||
]); | ||
return onSuccess(supplyPoint); | ||
} |
import { EnergyFee } from './energy-fee'; | ||
import { ProductName } from './product-name'; | ||
export declare type ProductFee = { | ||
id: string; | ||
name: ProductName; | ||
fee: Number; | ||
energyFees: [EnergyFee]; | ||
powerFees: number; | ||
}; |
export declare enum ProductName { | ||
classic = "classic", | ||
fairFee = "fairFee", | ||
sinsor = "sinsor" | ||
classic = "clasico", | ||
fairFee = "tarifaJusta", | ||
sinsor = "sinSorpresas" | ||
} |
export var ProductName; | ||
(function (ProductName) { | ||
ProductName["classic"] = "classic"; | ||
ProductName["fairFee"] = "fairFee"; | ||
ProductName["sinsor"] = "sinsor"; | ||
ProductName["classic"] = "clasico"; | ||
ProductName["fairFee"] = "tarifaJusta"; | ||
ProductName["sinsor"] = "sinSorpresas"; | ||
})(ProductName || (ProductName = {})); |
{ | ||
"name": "@holaluz/pomada", | ||
"version": "1.0.3", | ||
"version": "1.1.0-beta.1", | ||
"description": "Holaluz shared FE business logic repository", | ||
@@ -5,0 +5,0 @@ "author": "Holaluz", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
16006
34
405
1
2