-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const OFFER_COUNT = 5; | ||
const DESTINATION_COUNT = 5; | ||
const POINT_COUNT = 5; | ||
|
||
const CITIES = [ | ||
'Chamonix', | ||
Check failure on line 6 in src/const.js GitHub Actions / Check
|
||
'Geneva', | ||
Check failure on line 7 in src/const.js GitHub Actions / Check
|
||
'Amsterdam', | ||
Check failure on line 8 in src/const.js GitHub Actions / Check
|
||
'Helsinki', | ||
Check failure on line 9 in src/const.js GitHub Actions / Check
|
||
'Oslo', | ||
Check failure on line 10 in src/const.js GitHub Actions / Check
|
||
'Kopenhagen', | ||
Check failure on line 11 in src/const.js GitHub Actions / Check
|
||
'Den Haag', | ||
Check failure on line 12 in src/const.js GitHub Actions / Check
|
||
'Rotterdam', | ||
Check failure on line 13 in src/const.js GitHub Actions / Check
|
||
'Saint Petersburg', | ||
Check failure on line 14 in src/const.js GitHub Actions / Check
|
||
'Moscow', | ||
Check failure on line 15 in src/const.js GitHub Actions / Check
|
||
'Sochi', | ||
'Tokio', | ||
]; | ||
|
||
const OFFERS = [ | ||
'Order Uber', | ||
'Add luggage', | ||
'Switch to comfort', | ||
'Rent a car', | ||
'Add breakfast', | ||
'Book tickets', | ||
'Lunch in city', | ||
'Upgrade to a business class' | ||
]; | ||
|
||
const DESCRIPTION = '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.'; | ||
|
||
const Price = { | ||
MIN: 1, | ||
MAX: 1000 | ||
}; | ||
|
||
const TYPES = [ | ||
'taxi', | ||
'bus', | ||
'train', | ||
'ship', | ||
'drive', | ||
'flight', | ||
'check-in', | ||
'sightseeing', | ||
'restaurant' | ||
]; | ||
|
||
const DEFAULT_TYPE = 'flight'; | ||
|
||
const POINT_EMPTY = { | ||
basePrice: 0, | ||
dateFrom: null, | ||
dateTo: null, | ||
destination: null, | ||
isFavorite: false, | ||
offers: [], | ||
type: DEFAULT_TYPE | ||
}; | ||
|
||
export { | ||
OFFER_COUNT, | ||
DESTINATION_COUNT, | ||
POINT_COUNT, | ||
CITIES, | ||
OFFERS, | ||
DESCRIPTION, | ||
Price, | ||
TYPES, | ||
DEFAULT_TYPE, | ||
POINT_EMPTY | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getRandomValue, getRandomInteger } from "../utils.js"; | ||
import { CITIES, DESCRIPTION } from "../const.js"; | ||
|
||
function generateDestination () { | ||
const city = getRandomValue(CITIES); | ||
|
||
return { | ||
id: crypto.randomUUID(), | ||
description: DESCRIPTION, | ||
name: city, | ||
pictures: Array.from({ length: getRandomInteger(1, 5) }, () => ({ | ||
'src': `https://loremflickr.com/248/152?random=${crypto.randomUUID()}`, | ||
'description': `${city} description` | ||
})) | ||
}; | ||
} | ||
|
||
export { generateDestination }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { OFFERS, Price } from '../const.js' | ||
import { getRandomInteger, getRandomValue } from "../utils.js"; | ||
|
||
function generateOffer() { | ||
const offer = getRandomValue(OFFERS); | ||
|
||
return { | ||
id: crypto.randomUUID(), | ||
title: offer, | ||
price: getRandomInteger(Price.MIN, (Price.MAX / 10)) | ||
}; | ||
} | ||
|
||
export { generateOffer }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Price } from "../const.js"; | ||
import { getRandomInteger, getDate } from "../utils.js"; | ||
|
||
function generatePoint (type, destinationId, offerIds) { | ||
return { | ||
id: crypto.randomUUID(), | ||
basePrice: getRandomInteger(Price.MIN, Price.MAX), | ||
dateFrom: getDate({ next: false }), | ||
dateTo: getDate({ next: true }), | ||
destination: destinationId, | ||
isFavorite: getRandomInteger(0, 1), | ||
offers: offerIds, | ||
type | ||
}; | ||
} | ||
|
||
export { generatePoint }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default class DestinationsModel { | ||
constructor(service) { | ||
this.service = service; | ||
this.destinations = this.service.getDestinations(); | ||
} | ||
|
||
get() { | ||
return this.destinations; | ||
} | ||
|
||
getById(id) { | ||
return this.destinations.find((destination) => destination.id === id); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default class OffersModel { | ||
constructor(service) { | ||
this.service = service; | ||
this.offers = this.service.getOffers(); | ||
} | ||
|
||
get() { | ||
return this.offers; | ||
} | ||
|
||
getByType(type) { | ||
return this.offers.find((offer) => offer.type === type); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default class PointsModel { | ||
constructor(service) { | ||
this.service = service; | ||
this.points = this.service.getPoints(); | ||
} | ||
|
||
get() { | ||
return this.points; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { generateDestination } from '../mock/destination.js'; | ||
import { generateOffer } from '../mock/offer.js'; | ||
import { generatePoint } from '../mock/point.js'; | ||
|
||
import { getRandomInteger, getRandomValue } from '../utils.js'; | ||
import { DESTINATION_COUNT, OFFER_COUNT, POINT_COUNT, TYPES } from '../const.js'; | ||
|
||
export default class MockService { | ||
destinations = []; | ||
offers = []; | ||
points = []; | ||
|
||
constructor() { | ||
this.destinations = this.generateDestinations(); | ||
this.offers = this.generateOffers(); | ||
this.points = this.generatePoints(); | ||
} | ||
|
||
getDestinations() { | ||
return this.destinations; | ||
} | ||
|
||
generateOffers() { | ||
return TYPES.map((type) => ({ | ||
type, | ||
offers: Array.from({ length: getRandomInteger(0, OFFER_COUNT) }, () => generateOffer(type)) | ||
})); | ||
} | ||
|
||
generatePoints() { | ||
return Array.from({ length: POINT_COUNT }, () => { | ||
const type = getRandomValue(TYPES); | ||
const destination = getRandomValue(this.destinations); | ||
const hasOffers = getRandomInteger(0, 1); | ||
const offersByType = this.offers.find((offerByType) => offerByType.type === type); | ||
const offerIds = (hasOffers) | ||
? offersByType.offers | ||
.slice(0, getRandomInteger(0, OFFER_COUNT)) | ||
.map((offer) => offer.id) | ||
: []; | ||
|
||
return generatePoint(type, destination.id, offerIds); | ||
}); | ||
} | ||
|
||
getOffers() { | ||
return this.offers; | ||
} | ||
|
||
getPoints() { | ||
return this.points; | ||
} | ||
|
||
generateDestinations() { | ||
return Array.from( | ||
{ length: DESTINATION_COUNT }, | ||
() => generateDestination() | ||
); | ||
} | ||
} |