Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
fix(storage): fixes price,size filters
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajpiar committed Apr 15, 2021
1 parent 602108a commit 47b88d5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 55 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rif-marketplace-ui",
"version": "1.3.6",
"version": "1.3.7",
"description": "RIF Marketplace provides a digital catalogue with a wide range of decentralised services.",
"keywords": [
"RIF",
Expand Down
8 changes: 4 additions & 4 deletions src/api/models/storage/OfferFiltersTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { UNIT_PREFIX_POW2 } from 'utils/utils'
export default class OfferFiltersTransport {
averagePrice?: MinMaxFilter

totalCapacity?: MinMaxFilter
availableCapacity?: MinMaxFilter

periods?: PeriodInSeconds[]

Expand Down Expand Up @@ -40,11 +40,11 @@ export default class OfferFiltersTransport {
: undefined
this.averagePrice = price
? {
min: price.min - 1,
max: price.max + 1,
min: Math.floor(price.min),
max: Math.ceil(price.max),
}
: undefined
this.totalCapacity = sizeGB
this.availableCapacity = sizeGB
? {
min: sizeGB.min * UNIT_PREFIX_POW2.KILO,
max: sizeGB.max * UNIT_PREFIX_POW2.KILO,
Expand Down
10 changes: 5 additions & 5 deletions src/api/models/storage/__tests__/OfferFiltersTransport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const EXPECTED_OBJECT: OfferFiltersTransport = {
periods: Array.from(FAKE_FILTERS.periods as Set<SubscriptionPeriod>)
.map((p) => PeriodInSeconds[p]),
averagePrice: {
min: (FAKE_FILTERS.price?.min as number) - 1,
max: (FAKE_FILTERS.price?.max as number) + 1,
min: Math.floor(FAKE_FILTERS.price.min),
max: Math.ceil(FAKE_FILTERS.price.max),
},
totalCapacity: {
min: (FAKE_FILTERS.size?.min as number) * UNIT_PREFIX_POW2.KILO,
max: (FAKE_FILTERS.size?.max as number) * UNIT_PREFIX_POW2.KILO,
availableCapacity: {
min: FAKE_FILTERS.size.min * UNIT_PREFIX_POW2.KILO,
max: FAKE_FILTERS.size.max * UNIT_PREFIX_POW2.KILO,
},
provider: FAKE_FILTERS.provider
? { $like: FAKE_FILTERS.provider } : undefined,
Expand Down
45 changes: 1 addition & 44 deletions src/api/rif-marketplace-cache/storage/offers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { Paginated } from '@feathersjs/feathers'
import { AbstractAPIService, isResultPaginated } from 'api/models/apiService'
import OfferFiltersTransport from 'api/models/storage/OfferFiltersTransport'
import { OfferTransport } from 'api/models/storage/transports'
import { MinMaxFilter } from 'models/Filters'
import { StorageOffersFilters } from 'models/marketItems/StorageFilters'
import { StorageItem, StorageOffer } from 'models/marketItems/StorageItem'
import { UNIT_PREFIX_POW2 } from 'utils/utils'
import client from '../client'
import { StorageAPIService, StorageWSChannel } from './interfaces'
import { mapOfferFromTransport, MinMax } from './utils'
import { mapOfferFromTransport } from './utils'

export const offersAddress = 'storage/v0/offers' as const
export type OffersAddress = typeof offersAddress
Expand Down Expand Up @@ -41,45 +39,4 @@ export class StorageOffersService extends AbstractAPIService

return data.map(this.mapFromTransport)
}

fetchSizeLimits = async (): Promise<MinMaxFilter> => {
const minMB = await this.fetchMinMaxLimit(
this.service,
MinMax.min,
'totalCapacity',
)
const maxMB = await this.fetchMinMaxLimit(
this.service,
MinMax.max,
'totalCapacity',
)
return {
min: minMB / UNIT_PREFIX_POW2.KILO,
max: maxMB / UNIT_PREFIX_POW2.KILO,
}
}

private fetchMinMaxLimit = async (
service,
minMax: MinMax,
filedName: string,
options?: {
selectField?: string
},
): Promise<number> => {
const select = options?.selectField || filedName
const query = {
$limit: 1,
$sort: {
[filedName]: minMax,
},
$select: [select],
}
const result = await service.find({ query })

return result.reduce((_, item): number => {
const round = minMax === MinMax.min ? Math.floor : Math.ceil
return round(parseFloat(item[select]))
}, 0)
}
}

0 comments on commit 47b88d5

Please sign in to comment.