diff --git a/specification/specification.yml b/specification/specification.yml index 423f3f8..d2c3ab6 100644 --- a/specification/specification.yml +++ b/specification/specification.yml @@ -340,7 +340,7 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - '403': + '401': description: Пользователь не авторизован content: application/json: @@ -373,7 +373,7 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' - '403': + '401': description: Пользователь не авторизован content: application/json: diff --git a/src/shared/modules/offer/offer-controller.ts b/src/shared/modules/offer/offer-controller.ts index fe2a96c..cd7b6f8 100644 --- a/src/shared/modules/offer/offer-controller.ts +++ b/src/shared/modules/offer/offer-controller.ts @@ -109,7 +109,7 @@ export class OfferController extends BaseController { } public async index(req: Request, res: Response) { - const limit = Number(req.params.limit) || MAX_DISPLAY_OFFERS_COUNT; + const limit = Number(req.query.limit) || MAX_DISPLAY_OFFERS_COUNT; const offers = await this.offerService.find(limit); let favoritesIds: string[] = []; diff --git a/src/shared/modules/offer/offer-service.ts b/src/shared/modules/offer/offer-service.ts index b2ae901..d85d36d 100644 --- a/src/shared/modules/offer/offer-service.ts +++ b/src/shared/modules/offer/offer-service.ts @@ -68,7 +68,12 @@ export class OfferService implements OfferServiceInterface, DocumentExists { } async find(limit: number): Promise[]> { - return this.offerModel.find().populate('host').limit(limit).exec(); + return this.offerModel + .find() + .populate('host') + .sort({ date: -1 }) + .limit(limit) + .exec(); } async findPremiumOffersByCity( @@ -102,9 +107,13 @@ export class OfferService implements OfferServiceInterface, DocumentExists { userId: string, ): Promise | null> { const result = await this.userModel - .findByIdAndUpdate(userId, { - $addToSet: { favorites: new mongoose.Types.ObjectId(offerId) }, - }) + .findByIdAndUpdate( + userId, + { + $addToSet: { favorites: new mongoose.Types.ObjectId(offerId) }, + }, + { new: true }, + ) .exec(); return result;