-
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 #4 from n3wstar/module2-task1
- Loading branch information
Showing
18 changed files
with
458 additions
and
94 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -27,5 +27,8 @@ | |
}, | ||
"engines": { | ||
"node": "18" | ||
}, | ||
"dependencies": { | ||
"dayjs": "^1.11.10" | ||
} | ||
} |
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,22 @@ | ||
|
||
const DEFAULT_TYPE = 'flight'; | ||
|
||
const EMPTY_POINT = { | ||
basePrice: 0, | ||
dateFrom: null, | ||
dateTo: null, | ||
destination: null, | ||
isFavorite: false, | ||
offers: [], | ||
type: DEFAULT_TYPE | ||
}; | ||
|
||
const MSEC_IN_SEC = 1000; | ||
const SEC_IN_MIN = 60; | ||
const MIN_IN_HOUR = 60; | ||
const HOUR_IN_DAY = 24; | ||
|
||
const MSEC_IN_HOUR = MIN_IN_HOUR * SEC_IN_MIN * MSEC_IN_SEC; | ||
const MSEC_IN_DAY = HOUR_IN_DAY * MSEC_IN_HOUR; | ||
|
||
export {EMPTY_POINT, MSEC_IN_DAY, MSEC_IN_HOUR}; |
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,55 @@ | ||
|
||
const CITIES = [ | ||
'Tokyo', | ||
'Moscow', | ||
'New York', | ||
'Amsterdam', | ||
'Saint Petersburg', | ||
'Copenhagen' | ||
]; | ||
|
||
const DESCRIPTIONS = [ | ||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
'Cras aliquet varius magna, non porta ligula feugiat eget.', | ||
'Fusce tristique felis at fermentum pharetra. Aliquam id orci ut lectus varius viverra.', | ||
'Nullam nunc ex, convallis sed finibus eget, sollicitudin eget ante.' | ||
]; | ||
|
||
const PRICE = { | ||
MIN: 1, | ||
MAX: 1000 | ||
}; | ||
|
||
const DURATION = { | ||
DAY: 5, | ||
HOUR: 23, | ||
MINUTE: 59 | ||
}; | ||
|
||
const TYPES = [ | ||
'Check-in', | ||
'Sightseeing', | ||
'Restaurant', | ||
'Taxi', | ||
'Bus', | ||
'Train', | ||
'Ship', | ||
'Drive', | ||
'Flight' | ||
]; | ||
|
||
const POINT_OFFERS = [ | ||
'Add luggage', | ||
'Switch to comfort', | ||
'Add meal', | ||
'Choose seats', | ||
'Travel by train', | ||
'Order Uber', | ||
]; | ||
|
||
const POINTS_COUNT = 5; | ||
const DESTINATIONS_COUNT = 5; | ||
const OFFERS_COUNT = 5; | ||
|
||
export{CITIES, DESCRIPTIONS, PRICE, DURATION, TYPES, POINTS_COUNT, POINT_OFFERS, DESTINATIONS_COUNT, OFFERS_COUNT}; | ||
|
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,18 @@ | ||
import { getRandomNumber, getRandomValue } from '../utils.js'; | ||
import { CITIES, DESCRIPTIONS } from './consts.js'; | ||
|
||
function generateDestination() { | ||
const city = getRandomValue(CITIES); | ||
const description = getRandomValue(DESCRIPTIONS); | ||
return { | ||
id: crypto.randomUUID(), | ||
description: description, | ||
name: city, | ||
pictures: Array.from({length: getRandomNumber(1, 5)}, () => ({ | ||
src: `https://loremflickr.com/248/152?random=${crypto.randomUUID()}`, | ||
description: getRandomValue(DESCRIPTIONS) | ||
})) | ||
}; | ||
} | ||
|
||
export {generateDestination}; |
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,12 @@ | ||
import { getRandomNumber, getRandomValue } from '../utils.js'; | ||
import { PRICE, POINT_OFFERS} from './consts.js'; | ||
|
||
function generateOffer() { | ||
return{ | ||
id: crypto.randomUUID(), | ||
title: getRandomValue(POINT_OFFERS), | ||
price: getRandomNumber(PRICE.MIN, PRICE.MAX) | ||
}; | ||
} | ||
|
||
export{generateOffer}; |
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,19 @@ | ||
import { getRandomNumber, getDate } from '../utils.js'; | ||
import { PRICE } from './consts.js'; | ||
|
||
function generatePoint(type, destID, offerIds){ | ||
|
||
return { | ||
id: crypto.randomUUID(), | ||
basePrice: getRandomNumber(PRICE.MIN, PRICE.MAX), | ||
dateFrom: getDate({next: false}), | ||
dateTo: getDate({next: true}), | ||
destination: destID, | ||
isFavorite: Boolean(getRandomNumber(0,1)), | ||
offers: offerIds, | ||
type | ||
}; | ||
} | ||
|
||
export {generatePoint}; | ||
|
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,15 @@ | ||
export default class DestinationsModel{ | ||
|
||
constructor(service){ | ||
this.service = service; | ||
this.destinations = this.service.getDestinations(); | ||
} | ||
|
||
getDestination(){ | ||
return this.destinations; | ||
} | ||
|
||
getById(id){ | ||
return this.destinations.find((destination) => destination.id === id); | ||
} | ||
} |
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,15 @@ | ||
export default class OffersModel{ | ||
|
||
constructor(service){ | ||
this.service = service; | ||
this.offers = this.service.getOffers(); | ||
} | ||
|
||
getOffers(){ | ||
return this.offers; | ||
} | ||
|
||
getOfferByType(type){ | ||
return this.offers.find((offer) => offer.type === type); | ||
} | ||
} |
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,11 @@ | ||
export default class PointsModel{ | ||
|
||
constructor(service){ | ||
this.service = service; | ||
this.points = this.service.getPoints(); | ||
} | ||
|
||
getPoints(){ | ||
return this.points; | ||
} | ||
} |
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,61 @@ | ||
|
||
import { getRandomNumber, getRandomValue } from '../utils.js'; | ||
import { TYPES } from '../mock/consts.js'; | ||
import { generateDestination } from '../mock/destination.js'; | ||
import { generateOffer } from '../mock/offer.js'; | ||
import { generatePoint } from '../mock/point.js'; | ||
import { POINTS_COUNT, DESTINATIONS_COUNT, OFFERS_COUNT } from '../mock/consts.js'; | ||
|
||
export default class MockService{ | ||
#destinations = null; | ||
#offers = null; | ||
#points = null; | ||
|
||
constructor(){ | ||
this.#destinations = this.#generateDestinations(); | ||
this.#offers = this.#generateOffers(); | ||
this.#points = this.#generatePoints(); | ||
|
||
} | ||
|
||
#generateDestinations() { | ||
return Array.from({ length: DESTINATIONS_COUNT }, generateDestination); | ||
} | ||
|
||
#generateOffers() { | ||
return TYPES.map((type) => ({ | ||
type, | ||
offers: Array.from({ length: OFFERS_COUNT }, generateOffer) | ||
})); | ||
} | ||
|
||
#generatePoints() { | ||
return Array.from({ length: POINTS_COUNT }, () => { | ||
const type = getRandomValue(TYPES); | ||
const destination = getRandomValue(this.#destinations); | ||
const hasOffers = getRandomNumber(0, 1); | ||
const offersByType = this.#offers.find((offer) => offer.type === type); | ||
const offerIds = (hasOffers) | ||
? offersByType.offers | ||
.slice(0, getRandomNumber(0, 5)) | ||
.map((offer) => offer.id) | ||
: []; | ||
|
||
return generatePoint(type, destination.id, offerIds); | ||
}); | ||
} | ||
|
||
getDestinations(){ | ||
return this.#destinations; | ||
} | ||
|
||
getOffers(){ | ||
return this.#offers; | ||
} | ||
|
||
getPoints(){ | ||
return this.#points; | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.