diff --git a/src/shared/modules/offer/default-offer.service.ts b/src/shared/modules/offer/default-offer.service.ts index be35037..a79709b 100644 --- a/src/shared/modules/offer/default-offer.service.ts +++ b/src/shared/modules/offer/default-offer.service.ts @@ -107,8 +107,7 @@ export class DefaultOfferService implements OfferService { // TODO: проверка на существование документа - предложения public async exists(documentId: string): Promise { - return (await this.offerModel - .exists({_id: documentId})) !== null; + return this.offerModel.exists({_id: documentId}).then(r => !!r); } diff --git a/src/shared/modules/offer/offer.constant.ts b/src/shared/modules/offer/offer.constant.ts index e02f6cb..c49f4a9 100644 --- a/src/shared/modules/offer/offer.constant.ts +++ b/src/shared/modules/offer/offer.constant.ts @@ -1,2 +1,3 @@ export const DEFAULT_OFFER_COUNT = 60; export const DEFAULT_PREMIUM_OFFER_COUNT = 3; +export const MAX_OFFER_COUNT = 300; diff --git a/src/shared/modules/offer/offer.controller.ts b/src/shared/modules/offer/offer.controller.ts index 4dd18c8..61fdeb3 100644 --- a/src/shared/modules/offer/offer.controller.ts +++ b/src/shared/modules/offer/offer.controller.ts @@ -12,7 +12,7 @@ import { fillDTO } from '../../helpers/common.js'; import { FullOfferRdo } from './rdo/full-offer.rdo.js'; import { StatusCodes } from 'http-status-codes'; import { UpdateOfferDto } from './dto/update-offer.dto.js'; -import { DEFAULT_OFFER_COUNT } from './offer.constant.js'; +import { DEFAULT_OFFER_COUNT, MAX_OFFER_COUNT } from './offer.constant.js'; import { IdOfferRdo } from './rdo/id-offer.rdo.js'; import { ParamOfferId } from './type/param-offerid.type.js'; import { CreateOfferRequest } from './type/create-offer-request.type.js'; @@ -48,7 +48,8 @@ export class OfferController extends BaseController { } public async index({ query } : Request, res: Response): Promise { - const limit = query?.limit ? Number(query.limit) : DEFAULT_OFFER_COUNT; + const limitNum = Number(query?.limit); + const limit = query?.limit && !Number.isNaN(limitNum) && limitNum < MAX_OFFER_COUNT ? limitNum : DEFAULT_OFFER_COUNT; // TODO: Временно сделать const userId = ''; // const userId = req.user.id // AFTER JWT diff --git a/src/shared/modules/user/default-user.service.ts b/src/shared/modules/user/default-user.service.ts index ea853dd..7f1712a 100644 --- a/src/shared/modules/user/default-user.service.ts +++ b/src/shared/modules/user/default-user.service.ts @@ -30,8 +30,7 @@ export class DefaultUserService implements UserService { // TODO: проверка на существование документа - предложения public async exists(documentId: string): Promise { - return (await this.userModel - .exists({_id: documentId})) !== null; + return this.userModel.exists({_id: documentId}).then(r => !!r); } public async findByEmail(email: string): Promise | null> {