Skip to content

Commit

Permalink
Исправит замечания.
Browse files Browse the repository at this point in the history
  • Loading branch information
RnizereB committed Oct 21, 2024
1 parent 13b93d3 commit 637660c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
15 changes: 15 additions & 0 deletions src/shared/helpers/const.ts
Original file line number Diff line number Diff line change
@@ -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
}

26 changes: 6 additions & 20 deletions src/shared/libs/offer-generator/tsv-offer-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,25 @@ 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) {}

public generate(): string {
const title = getRandomElement<string>(this.mockData.title);
const description = getRandomElement<string>(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<string>(this.mockData.city);
const previewImage = getRandomElement<string>(this.mockData.previewImage);
const images = getRandomItems<string>(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<string>(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<string>(this.mockData.goods).join(';');
const name = getRandomElement<string>(this.mockData.name);
const email = getRandomElement<string>(this.mockData.email);
Expand Down

0 comments on commit 637660c

Please sign in to comment.