-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from DashaKukartseva/module4-task2
- Loading branch information
Showing
12 changed files
with
302 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { FilterType } from '../const'; | ||
import { isEventFuture, isEventPresent, isEventPast } from '../utils'; | ||
|
||
const filter = { | ||
[FilterType.EVERYTHING]: (events) => [...events], | ||
[FilterType.FUTURE]: (events) => events.filter((event) => isEventFuture(event)), | ||
[FilterType.PRESENT]: (events) => events.filter((event) => isEventPresent(event)), | ||
[FilterType.PAST]: (events) => events.filter((event) => isEventPast(event)), | ||
}; | ||
|
||
function generateFilters(events) { | ||
return Object.entries(filter).map( | ||
([filterType, filterEvents]) => ({ | ||
type: filterType, | ||
exists: filterEvents(events).length > 0 | ||
}) | ||
); | ||
} | ||
|
||
export {generateFilters}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
import { getRandomInteger, getRandomValue } from '../utils'; | ||
import { OFFERS_NAMES, POINT_TYPES,Price } from '../const'; | ||
|
||
const mockOffer=[] | ||
function generateOffersByType(type) { | ||
const mockOffer = []; | ||
|
||
function generateOffer(type) { | ||
return { | ||
type: type, | ||
offers: Array.from({ length: getRandomInteger(1, 5)}, () =>({ | ||
type, | ||
offers: Array.from({length: getRandomInteger(0, 5)}, () => ({ | ||
id: crypto.randomUUID(), | ||
title: getRandomValue(OFFERS_NAMES), | ||
price: getRandomInteger(Price.MIN, Price.MAX) | ||
price:getRandomInteger(Price.MIN, Price.MAX) | ||
})) | ||
}; | ||
} | ||
|
||
POINT_TYPES.forEach((type) => { | ||
const offer = generateOffersByType(type); | ||
const offer = generateOffer(type); | ||
mockOffer.push(offer); | ||
}); | ||
|
||
|
||
export { mockOffer }; | ||
export {mockOffer}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
import { mockDestinations } from '../mock/directions.js'; | ||
import { mockOffer } from '../mock/offers.js'; | ||
import { mockOffer } from '../mock/offer.js'; | ||
import { generatePoint } from '../mock/point.js'; | ||
import { EVENT_COUNT, POINT_TYPES } from '../const.js'; | ||
import { getRandomValue, getRandomInteger } from '../utils.js'; | ||
|
||
export default class MockService { | ||
#destinations = null; | ||
#offers = null; | ||
#points = null; | ||
constructor() { | ||
this.#destinations = mockDestinations; | ||
this.#offers = mockOffer; | ||
this.#points = this.#generatePoints(); | ||
} | ||
#destinations = null; | ||
#offers = null; | ||
#points = null; | ||
constructor() { | ||
this.#destinations = mockDestinations; | ||
this.#offers = mockOffer; | ||
this.#points = this.#generatePoints(); | ||
} | ||
|
||
#generatePoints() { | ||
return Array.from({length: EVENT_COUNT}, () => { | ||
const type = getRandomValue(POINT_TYPES); | ||
const destination = getRandomValue(this.#destinations); | ||
const destinationIDs = destination.id; | ||
const offersByType = this.#offers.find((offerByType) => offerByType.type === type); | ||
const offersIDs = []; | ||
offersByType.offers.forEach((offer) => { | ||
if (getRandomInteger(0, 1)) { | ||
offersIDs.push(offer.id); | ||
} | ||
}); | ||
return generatePoint(type, offersIDs, destinationIDs); | ||
}); | ||
} | ||
#generatePoints() { | ||
return Array.from({length: EVENT_COUNT}, () => { | ||
const type = getRandomValue(POINT_TYPES); | ||
const destinationIDs = (getRandomInteger(0, 1)) ? getRandomValue(this.#destinations).id : null; | ||
const offersByType = this.#offers.find((offerByType) => offerByType.type === type); | ||
const offersIDs = []; | ||
offersByType.offers.forEach((offer) => { | ||
if (getRandomInteger(0, 1)) { | ||
offersIDs.push(offer.id); | ||
} | ||
}); | ||
return generatePoint(type, offersIDs, destinationIDs); | ||
}); | ||
} | ||
|
||
getDestinations() { | ||
return this.#destinations; | ||
} | ||
get destinations() { | ||
return this.#destinations; | ||
} | ||
|
||
getOffers() { | ||
return this.#offers; | ||
} | ||
get offers() { | ||
return this.#offers; | ||
} | ||
|
||
getEvents() { | ||
return this.#points; | ||
} | ||
} | ||
get events() { | ||
return this.#points; | ||
} | ||
} |
Oops, something went wrong.