interationObserver init on whole listing
This commit is contained in:
parent
935178a66d
commit
e5478bb1c6
31 changed files with 4445 additions and 202 deletions
38
src/services/apiService.ts
Normal file
38
src/services/apiService.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import type { IExcursionCard, IExcursionsFilter } from '@/types'
|
||||
import { excursions } from "@/constants";
|
||||
|
||||
interface IGetExcursionsRequest {
|
||||
limit: number;
|
||||
offset: number;
|
||||
filter?: Partial<IExcursionsFilter>;
|
||||
}
|
||||
|
||||
export default class ApiService {
|
||||
getExcursions({ limit, offset, filter }: IGetExcursionsRequest): IExcursionCard[] {
|
||||
console.log(limit, offset, filter);
|
||||
|
||||
let result = excursions.slice(offset, offset + limit)
|
||||
|
||||
|
||||
if (filter) {
|
||||
if (filter.city) {
|
||||
result = result.filter((card) => card.city.includes(filter.city))
|
||||
}
|
||||
if (filter.minCost) {
|
||||
result = result.filter((card) => card.cost >= +filter.minCost)
|
||||
}
|
||||
if (filter.maxCost) {
|
||||
result = result.filter((card) => card.cost <= +filter.maxCost)
|
||||
}
|
||||
if (filter.countPeople) {
|
||||
result = result.filter((card) => (
|
||||
card.minCountPeople <= filter.countPeople &&
|
||||
card.maxCountPeople >= filter.countPeople)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue