diff --git a/src/shared/helpers/const.ts b/src/shared/helpers/const.ts new file mode 100644 index 0000000..ba19fce --- /dev/null +++ b/src/shared/helpers/const.ts @@ -0,0 +1,15 @@ +export enum WeekDay { + First = 1, + Last = 7 +} + +export enum Attributes { + Min = 1, + Max = 5 +} + +export enum Price { + Min = 560, + Mix = 3500 +} + diff --git a/src/shared/libs/offer-generator/tsv-offer-generate.ts b/src/shared/libs/offer-generator/tsv-offer-generate.ts index c2cde2e..6e1101b 100644 --- a/src/shared/libs/offer-generator/tsv-offer-generate.ts +++ b/src/shared/libs/offer-generator/tsv-offer-generate.ts @@ -2,21 +2,7 @@ import dayjs from 'dayjs'; import { getRandomElement, getRandomItems, getRandomNumber } from '../../helpers/index.js'; import { MockServerData } from '../../types/index.js'; import { OfferGenerator } from './index.js'; - -const FIRST_WEEK_DAY = 1; -const LAST_WEEK_DAY = 7; - -const MINIMUM_RATING = 1; -const MAXIMUM_RATING = 5; - -const MAX_BEDROOMS = 5; -const MIN_BEDROOM = 1; - -const MIN_ADULT = 1; -const MAX_ADULTS = 5; - -const MIN_PRICE = 560; -const MAX_PRICE = 3500; +import { Attributes, Price, WeekDay } from '../../helpers/const.js'; export class TSVOfferGenerator implements OfferGenerator { constructor(private readonly mockData: MockServerData) {} @@ -24,17 +10,17 @@ export class TSVOfferGenerator implements OfferGenerator { public generate(): string { const title = getRandomElement(this.mockData.title); const description = getRandomElement(this.mockData.description); - const postDate = dayjs().subtract(getRandomNumber(FIRST_WEEK_DAY, LAST_WEEK_DAY), 'day').toISOString(); + const postDate = dayjs().subtract(getRandomNumber(WeekDay.First, WeekDay.Last), 'day').toISOString(); const city = getRandomElement(this.mockData.city); const previewImage = getRandomElement(this.mockData.previewImage); const images = getRandomItems(this.mockData.images).join(';'); const isFavorite = Math.random() < 0.5; const isPremium = Math.random() < 0.5; - const rating = getRandomNumber(MINIMUM_RATING, MAXIMUM_RATING); + const rating = getRandomNumber(Attributes.Min, Attributes.Max); const type = getRandomElement(this.mockData.type); - const bedrooms = getRandomNumber(MIN_BEDROOM, MAX_BEDROOMS); - const maxAdults = getRandomNumber(MIN_ADULT, MAX_ADULTS); - const price = getRandomNumber(MIN_PRICE, MAX_PRICE); + const bedrooms = getRandomNumber(Attributes.Min, Attributes.Max); + const maxAdults = getRandomNumber(Attributes.Min, Attributes.Max); + const price = getRandomNumber(Price.Min, Price.Mix); const goods = getRandomItems(this.mockData.goods).join(';'); const name = getRandomElement(this.mockData.name); const email = getRandomElement(this.mockData.email);