From ecc3d4d53522abd5bc0a01f7498f27eef9ea0464 Mon Sep 17 00:00:00 2001 From: Irina Lagutina Date: Sat, 19 Oct 2024 20:52:37 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B8=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5=D0=B9=D0=BD=D0=B5=D1=80?= =?UTF-8?q?,=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20=D0=B8=20=D1=81?= =?UTF-8?q?=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli/commands/command.constant.ts | 2 - src/cli/commands/import.command.ts | 4 +- src/main.rest.ts | 2 + src/shared/const.ts | 7 +++ .../comments/comment-service.interface.ts | 9 ++++ .../modules/comments/comment.container.ts | 19 +++++++ src/shared/modules/comments/comment.entity.ts | 35 ++++++++++++ .../comments/default-comment.service.ts | 32 +++++++++++ .../comments/dto/create-comment.dto.ts | 6 +++ src/shared/modules/comments/index.ts | 4 ++ .../modules/offer/default-offer.service.ts | 53 ++++++++++++++++++- .../modules/offer/dto/update-offer.dto.ts | 19 +++++++ .../modules/offer/offer-service.interface.ts | 8 +++ 13 files changed, 196 insertions(+), 4 deletions(-) delete mode 100644 src/cli/commands/command.constant.ts create mode 100644 src/shared/modules/comments/comment-service.interface.ts create mode 100644 src/shared/modules/comments/comment.container.ts create mode 100644 src/shared/modules/comments/comment.entity.ts create mode 100644 src/shared/modules/comments/default-comment.service.ts create mode 100644 src/shared/modules/comments/dto/create-comment.dto.ts create mode 100644 src/shared/modules/comments/index.ts create mode 100644 src/shared/modules/offer/dto/update-offer.dto.ts diff --git a/src/cli/commands/command.constant.ts b/src/cli/commands/command.constant.ts deleted file mode 100644 index 3503d91..0000000 --- a/src/cli/commands/command.constant.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const DEFAULT_DB_PORT = '27017'; -export const DEFAULT_USER_PASSWORD = '123456'; diff --git a/src/cli/commands/import.command.ts b/src/cli/commands/import.command.ts index aedca59..9ab7489 100644 --- a/src/cli/commands/import.command.ts +++ b/src/cli/commands/import.command.ts @@ -7,9 +7,11 @@ import { Logger } from '../../shared/libs/logger/logger.interface.js'; import { DefaultOfferService, OfferModel, OfferService } from '../../shared/modules/offer/index.js'; import { DefaultUserService, UserModel, UserService } from '../../shared/modules/user/index.js'; import { Offer } from '../../shared/types/index.js'; -import { DEFAULT_DB_PORT, DEFAULT_USER_PASSWORD } from './command.constant.js'; import { Command } from './command.interface.js'; +const DEFAULT_DB_PORT = '27017'; +const DEFAULT_USER_PASSWORD = '123456'; + export class ImportCommand implements Command { private userService: UserService; private offerService: OfferService; diff --git a/src/main.rest.ts b/src/main.rest.ts index 7833374..a0dadac 100644 --- a/src/main.rest.ts +++ b/src/main.rest.ts @@ -6,12 +6,14 @@ import { Component } from './shared/const.js'; import { RESTApplication } from './rest/rest.application.js'; import { createUserContainer } from './shared/modules/user/index.js'; import { createOfferContainer } from './shared/modules/offer/index.js'; +import { createCommentContainer } from './shared/modules/comments/index.js'; async function bootstrap() { const container = Container.merge( createRestApplicationContainer(), createUserContainer(), createOfferContainer(), + createCommentContainer(), ); const application = container.get(Component.RestApplication); diff --git a/src/shared/const.ts b/src/shared/const.ts index 3bf2135..43528af 100644 --- a/src/shared/const.ts +++ b/src/shared/const.ts @@ -56,4 +56,11 @@ export const Component = { UserModel: Symbol.for('UserModel'), OfferService: Symbol.for('OfferService'), OfferModel: Symbol.for('OfferModel'), + CommentService: Symbol.for('CommentService'), + CommentModel: Symbol.for('CommentModel'), } as const; + +export enum SortType { + Down = -1, + Up = 1, +} diff --git a/src/shared/modules/comments/comment-service.interface.ts b/src/shared/modules/comments/comment-service.interface.ts new file mode 100644 index 0000000..c7221b5 --- /dev/null +++ b/src/shared/modules/comments/comment-service.interface.ts @@ -0,0 +1,9 @@ +import { DocumentType } from '@typegoose/typegoose'; +import { CommentEntity } from './comment.entity.js'; +import { CreateCommentDto } from './dto/create-comment.dto.js'; + +export interface CommentService { + create(dto: CreateCommentDto): Promise>; + findByOfferId(offerId: string): Promise[]>; + deleteByOfferId(offerId: string): Promise; +} diff --git a/src/shared/modules/comments/comment.container.ts b/src/shared/modules/comments/comment.container.ts new file mode 100644 index 0000000..a6853a2 --- /dev/null +++ b/src/shared/modules/comments/comment.container.ts @@ -0,0 +1,19 @@ +import { Container } from 'inversify'; +import { Component } from '../../const.js'; +import { CommentService } from './comment-service.interface.js'; +import { DefaultCommentService } from './default-comment.service.js'; +import { types } from '@typegoose/typegoose'; +import { CommentEntity, CommentModel } from './comment.entity.js'; + +export function createCommentContainer() { + const commentContainer = new Container(); + + commentContainer.bind(Component.CommentService) + .to(DefaultCommentService) + .inSingletonScope(); + + commentContainer.bind>(Component.CommentModel) + .toConstantValue(CommentModel); + + return commentContainer; +} diff --git a/src/shared/modules/comments/comment.entity.ts b/src/shared/modules/comments/comment.entity.ts new file mode 100644 index 0000000..39f0a15 --- /dev/null +++ b/src/shared/modules/comments/comment.entity.ts @@ -0,0 +1,35 @@ +import { defaultClasses, getModelForClass, modelOptions, prop, Ref } from '@typegoose/typegoose'; +import { OfferEntity } from '../offer/index.js'; +import { UserEntity } from '../user/index.js'; + +// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging +export interface CommentEntity extends defaultClasses.Base { } + +@modelOptions({ + schemaOptions: { + collection: 'comments', + timestamps: true, + } +}) +// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging +export class CommentEntity extends defaultClasses.TimeStamps { + @prop({ trim: true, required: true }) + public text: string; + + @prop({ + ref: OfferEntity, + required: true + }) + public offerId: Ref; + + @prop({ + ref: UserEntity, + required: true, + }) + public userId: Ref; + + @prop({ required: true }) + public rating: number; +} + +export const CommentModel = getModelForClass(CommentEntity); diff --git a/src/shared/modules/comments/default-comment.service.ts b/src/shared/modules/comments/default-comment.service.ts new file mode 100644 index 0000000..56a8881 --- /dev/null +++ b/src/shared/modules/comments/default-comment.service.ts @@ -0,0 +1,32 @@ +import { DocumentType, types } from '@typegoose/typegoose'; +import { inject, injectable } from 'inversify'; +import { CommentService } from './comment-service.interface.js'; +import { CreateCommentDto } from './dto/create-comment.dto.js'; +import { CommentEntity } from './comment.entity.js'; +import { Component } from '../../const.js'; + +@injectable() +export class DefaultCommentService implements CommentService { + constructor( + @inject(Component.CommentModel) private readonly commentModel: types.ModelType + ) { } + + public async create(dto: CreateCommentDto): Promise> { + const comment = await this.commentModel.create(dto); + return comment.populate('userId'); + } + + public async findByOfferId(offerId: string): Promise[]> { + return this.commentModel + .find({ offerId }) + .populate('userId'); + } + + public async deleteByOfferId(offerId: string): Promise { + const result = await this.commentModel + .deleteMany({ offerId }) + .exec(); + + return result.deletedCount; + } +} diff --git a/src/shared/modules/comments/dto/create-comment.dto.ts b/src/shared/modules/comments/dto/create-comment.dto.ts new file mode 100644 index 0000000..65c531f --- /dev/null +++ b/src/shared/modules/comments/dto/create-comment.dto.ts @@ -0,0 +1,6 @@ +export class CreateCommentDto { + public text: string; + public offerId: string; + public userId: string; + public rating: number; +} diff --git a/src/shared/modules/comments/index.ts b/src/shared/modules/comments/index.ts new file mode 100644 index 0000000..eac14a2 --- /dev/null +++ b/src/shared/modules/comments/index.ts @@ -0,0 +1,4 @@ +export { CommentService } from './comment-service.interface.js'; +export { CommentEntity, CommentModel } from './comment.entity.js'; +export { DefaultCommentService } from './default-comment.service.js'; +export { createCommentContainer } from './comment.container.js'; diff --git a/src/shared/modules/offer/default-offer.service.ts b/src/shared/modules/offer/default-offer.service.ts index 4de5780..0ff19b5 100644 --- a/src/shared/modules/offer/default-offer.service.ts +++ b/src/shared/modules/offer/default-offer.service.ts @@ -5,6 +5,11 @@ import { OfferEntity } from './offer.entity.js'; import { DocumentType, types } from '@typegoose/typegoose'; import { OfferService } from './offer-service.interface.js'; import { CreateOfferDto } from './dto/create-offer.dto.js'; +import { UpdateOfferDto } from './dto/update-offer.dto.js'; +import { SortType } from '../../const.js'; +import { City } from '../../types/index.js'; + +const DEFAULT_PREMIUM_COUNT = 3; @injectable() export class DefaultOfferService implements OfferService { @@ -21,6 +26,52 @@ export class DefaultOfferService implements OfferService { } public async findById(offerId: string): Promise | null> { - return this.offerModel.findById(offerId).exec(); + return this.offerModel + .findById(offerId) + .populate('userId') + .exec(); + } + + public async find(): Promise[]> { + return this.offerModel + .find() + .populate('userId') + .exec(); + } + + public async deleteById(offerId: string): Promise | null> { + return this.offerModel + .findByIdAndDelete(offerId) + .exec(); + } + + public async updateById(offerId: string, dto: UpdateOfferDto): Promise | null> { + return this.offerModel + .findByIdAndUpdate(offerId, dto, { new: true }) + .populate('userId') + .exec(); + } + + public async exists(documentId: string): Promise { + return (await this.offerModel + .exists({ _id: documentId })) !== null; + } + + public async incCommentCount(offerId: string): Promise | null> { + return this.offerModel + .findByIdAndUpdate(offerId, { + '$inc': { + commentCount: 1, + } + }).exec(); + } + + public async findPremiumByCity(city: City): Promise[] | null> { + return this.offerModel + .find({ city }) + .sort({ createdAt: SortType.Down }) + .limit(DEFAULT_PREMIUM_COUNT) + .populate('userId') + .exec(); } } diff --git a/src/shared/modules/offer/dto/update-offer.dto.ts b/src/shared/modules/offer/dto/update-offer.dto.ts new file mode 100644 index 0000000..4ce9c76 --- /dev/null +++ b/src/shared/modules/offer/dto/update-offer.dto.ts @@ -0,0 +1,19 @@ +import { City, Location, OfferType } from '../../../types/index.js'; + +export class UpdateOfferDto { + public title?: string; + public description?: string; + public postDate?: Date; + public city?: City; + public preview?: string; + public images?: string[]; + public isPremium?: boolean; + public isFavorite?: boolean; + public type?: OfferType; + public rooms?: number; + public guests?: number; + public price?: number; + public facilities?: string[]; + public userId?: string; + public location?: Location; +} diff --git a/src/shared/modules/offer/offer-service.interface.ts b/src/shared/modules/offer/offer-service.interface.ts index 2109d34..288b745 100644 --- a/src/shared/modules/offer/offer-service.interface.ts +++ b/src/shared/modules/offer/offer-service.interface.ts @@ -1,8 +1,16 @@ import { DocumentType } from '@typegoose/typegoose'; import { CreateOfferDto } from './dto/create-offer.dto.js'; import { OfferEntity } from './offer.entity.js'; +import { UpdateOfferDto } from './dto/update-offer.dto.js'; +import { City } from '../../types/index.js'; export interface OfferService { create(dto: CreateOfferDto): Promise>; + find(): Promise[] | null>; findById(offerId: string): Promise | null>; + findPremiumByCity(city: City): Promise[] | null>; + deleteById(offerId: string): Promise | null>; + updateById(offerId: string, dto: UpdateOfferDto): Promise | null>; + incCommentCount(offerId: string): Promise | null>; + exists(documentId: string): Promise; } From 492d4b731eef4637488ee900e6d744016e239617 Mon Sep 17 00:00:00 2001 From: Irina Lagutina Date: Sat, 19 Oct 2024 20:56:03 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=88=D0=B8=D1=80=D0=B8?= =?UTF-8?q?=D1=82=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?UTF-8?q?=20UserService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/shared/modules/user/default-user.service.ts | 7 +++++++ src/shared/modules/user/dto/update-user.dto.ts | 4 ++++ src/shared/modules/user/user-service.interface.ts | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 src/shared/modules/user/dto/update-user.dto.ts diff --git a/src/shared/modules/user/default-user.service.ts b/src/shared/modules/user/default-user.service.ts index 19da05f..04f3140 100644 --- a/src/shared/modules/user/default-user.service.ts +++ b/src/shared/modules/user/default-user.service.ts @@ -5,6 +5,7 @@ import { CreateUserDto } from './dto/create-user.dto.js'; import { inject, injectable } from 'inversify'; import { Component } from '../../const.js'; import { Logger } from '../../libs/logger/logger.interface.js'; +import { UpdateUserDto } from './dto/update-user.dto.js'; @injectable() export class DefaultUserService implements UserService { @@ -36,4 +37,10 @@ export class DefaultUserService implements UserService { return this.create(dto, salt); } + + public async updateById(userId: string, dto: UpdateUserDto): Promise | null> { + return this.userModel + .findByIdAndUpdate(userId, dto, { new: true }) + .exec(); + } } diff --git a/src/shared/modules/user/dto/update-user.dto.ts b/src/shared/modules/user/dto/update-user.dto.ts new file mode 100644 index 0000000..58450a4 --- /dev/null +++ b/src/shared/modules/user/dto/update-user.dto.ts @@ -0,0 +1,4 @@ +export class UpdateUserDto { + public name?: string; + public avatar?: string; +} diff --git a/src/shared/modules/user/user-service.interface.ts b/src/shared/modules/user/user-service.interface.ts index 14aff2d..abc9a4b 100644 --- a/src/shared/modules/user/user-service.interface.ts +++ b/src/shared/modules/user/user-service.interface.ts @@ -1,9 +1,11 @@ import { DocumentType } from '@typegoose/typegoose'; import { UserEntity } from './user.entity.js'; import { CreateUserDto } from './dto/create-user.dto.js'; +import { UpdateUserDto } from './dto/update-user.dto.js'; export interface UserService { create(dto: CreateUserDto, salt: string): Promise>; findByEmail(email: string): Promise | null>; findOrCreate(dto: CreateUserDto, salt: string): Promise>; + updateById(userId: string, dto: UpdateUserDto): Promise | null>; } From aa5e4e412b2905c412854c9bb176bc6b7bd03657 Mon Sep 17 00:00:00 2001 From: Irina Lagutina Date: Wed, 30 Oct 2024 14:21:48 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- specification/specification.yml | 25 ++++++++++++++++--- .../comments/dto/create-comment.dto.ts | 4 +-- .../modules/offer/default-offer.service.ts | 17 +++---------- .../modules/offer/dto/update-offer.dto.ts | 2 ++ .../modules/offer/offer-service.interface.ts | 1 - 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/specification/specification.yml b/specification/specification.yml index 90b7898..0ea2319 100644 --- a/specification/specification.yml +++ b/specification/specification.yml @@ -10,7 +10,7 @@ info: tags: - name: offers - description: Действия с объявлениями. + description: Действия с предложениями. - name: comments description: Действия с комментариями. - name: users @@ -62,8 +62,27 @@ paths: tags: - users summary: Загрузка аватара - description: Загружает изображение аватара пользователя. Изображение - аватара должно быть в формате `png` или `jpg`. + description: Загружает изображение аватара пользователя. Изображение аватара должно быть в формате `png` или `jpg`. + + /users/{userId}/favorites: + get: + tags: + - users + summary: Возвращает избранные предложения + description: Возвращает предложения, добавленные в избранное. Доступен только авторизованным пользователям. + + /users/{userId}/favorites/{offerId}: + post: + tags: + - users + summary: Добавление в избранное + description: Добавляет предложение в избранное. Доступен только авторизованным пользователям. + + delete: + tags: + - users + summary: Удаление из избранного + description: Удаляет предложение из избранного. Доступен только авторизованным пользователям. components: diff --git a/src/shared/modules/comments/dto/create-comment.dto.ts b/src/shared/modules/comments/dto/create-comment.dto.ts index 65c531f..364976c 100644 --- a/src/shared/modules/comments/dto/create-comment.dto.ts +++ b/src/shared/modules/comments/dto/create-comment.dto.ts @@ -1,6 +1,6 @@ export class CreateCommentDto { - public text: string; public offerId: string; - public userId: string; + public text: string; public rating: number; + public userId: string; } diff --git a/src/shared/modules/offer/default-offer.service.ts b/src/shared/modules/offer/default-offer.service.ts index 0ff19b5..3ea3604 100644 --- a/src/shared/modules/offer/default-offer.service.ts +++ b/src/shared/modules/offer/default-offer.service.ts @@ -28,14 +28,14 @@ export class DefaultOfferService implements OfferService { public async findById(offerId: string): Promise | null> { return this.offerModel .findById(offerId) - .populate('userId') + .populate(['userId']) .exec(); } public async find(): Promise[]> { return this.offerModel .find() - .populate('userId') + .populate(['userId']) .exec(); } @@ -48,7 +48,7 @@ export class DefaultOfferService implements OfferService { public async updateById(offerId: string, dto: UpdateOfferDto): Promise | null> { return this.offerModel .findByIdAndUpdate(offerId, dto, { new: true }) - .populate('userId') + .populate(['userId']) .exec(); } @@ -57,21 +57,12 @@ export class DefaultOfferService implements OfferService { .exists({ _id: documentId })) !== null; } - public async incCommentCount(offerId: string): Promise | null> { - return this.offerModel - .findByIdAndUpdate(offerId, { - '$inc': { - commentCount: 1, - } - }).exec(); - } - public async findPremiumByCity(city: City): Promise[] | null> { return this.offerModel .find({ city }) .sort({ createdAt: SortType.Down }) .limit(DEFAULT_PREMIUM_COUNT) - .populate('userId') + .populate(['userId']) .exec(); } } diff --git a/src/shared/modules/offer/dto/update-offer.dto.ts b/src/shared/modules/offer/dto/update-offer.dto.ts index 4ce9c76..52a904c 100644 --- a/src/shared/modules/offer/dto/update-offer.dto.ts +++ b/src/shared/modules/offer/dto/update-offer.dto.ts @@ -16,4 +16,6 @@ export class UpdateOfferDto { public facilities?: string[]; public userId?: string; public location?: Location; + public rating?: number; + public commentCount?: number; } diff --git a/src/shared/modules/offer/offer-service.interface.ts b/src/shared/modules/offer/offer-service.interface.ts index 288b745..8d5433f 100644 --- a/src/shared/modules/offer/offer-service.interface.ts +++ b/src/shared/modules/offer/offer-service.interface.ts @@ -11,6 +11,5 @@ export interface OfferService { findPremiumByCity(city: City): Promise[] | null>; deleteById(offerId: string): Promise | null>; updateById(offerId: string, dto: UpdateOfferDto): Promise | null>; - incCommentCount(offerId: string): Promise | null>; exists(documentId: string): Promise; } From 68fd6470f3d5a5ed5645c1a24103c5b0d7cdf4ba Mon Sep 17 00:00:00 2001 From: Irina Lagutina Date: Wed, 30 Oct 2024 17:33:01 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B4=D0=BE=D0=BB=D0=B6?= =?UTF-8?q?=D0=B0=D0=B5=D0=BC=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20?= =?UTF-8?q?=D1=81=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/comments/comment.container.ts | 8 ++--- .../comments/default-comment.service.ts | 9 ++---- .../modules/offer/default-offer.service.ts | 29 ++++--------------- .../modules/user/default-user.service.ts | 4 +-- 4 files changed, 11 insertions(+), 39 deletions(-) diff --git a/src/shared/modules/comments/comment.container.ts b/src/shared/modules/comments/comment.container.ts index a6853a2..2b2d329 100644 --- a/src/shared/modules/comments/comment.container.ts +++ b/src/shared/modules/comments/comment.container.ts @@ -8,12 +8,8 @@ import { CommentEntity, CommentModel } from './comment.entity.js'; export function createCommentContainer() { const commentContainer = new Container(); - commentContainer.bind(Component.CommentService) - .to(DefaultCommentService) - .inSingletonScope(); - - commentContainer.bind>(Component.CommentModel) - .toConstantValue(CommentModel); + commentContainer.bind(Component.CommentService).to(DefaultCommentService).inSingletonScope(); + commentContainer.bind>(Component.CommentModel).toConstantValue(CommentModel); return commentContainer; } diff --git a/src/shared/modules/comments/default-comment.service.ts b/src/shared/modules/comments/default-comment.service.ts index 56a8881..1f0bccd 100644 --- a/src/shared/modules/comments/default-comment.service.ts +++ b/src/shared/modules/comments/default-comment.service.ts @@ -17,16 +17,11 @@ export class DefaultCommentService implements CommentService { } public async findByOfferId(offerId: string): Promise[]> { - return this.commentModel - .find({ offerId }) - .populate('userId'); + return this.commentModel.find({ offerId }).populate('userId').exec(); } public async deleteByOfferId(offerId: string): Promise { - const result = await this.commentModel - .deleteMany({ offerId }) - .exec(); - + const result = await this.commentModel.deleteMany({ offerId }).exec(); return result.deletedCount; } } diff --git a/src/shared/modules/offer/default-offer.service.ts b/src/shared/modules/offer/default-offer.service.ts index 3ea3604..491b23b 100644 --- a/src/shared/modules/offer/default-offer.service.ts +++ b/src/shared/modules/offer/default-offer.service.ts @@ -26,43 +26,26 @@ export class DefaultOfferService implements OfferService { } public async findById(offerId: string): Promise | null> { - return this.offerModel - .findById(offerId) - .populate(['userId']) - .exec(); + return this.offerModel.findById(offerId).populate('userId').exec(); } public async find(): Promise[]> { - return this.offerModel - .find() - .populate(['userId']) - .exec(); + return this.offerModel.find().populate('userId').exec(); } public async deleteById(offerId: string): Promise | null> { - return this.offerModel - .findByIdAndDelete(offerId) - .exec(); + return this.offerModel.findByIdAndDelete(offerId).exec(); } public async updateById(offerId: string, dto: UpdateOfferDto): Promise | null> { - return this.offerModel - .findByIdAndUpdate(offerId, dto, { new: true }) - .populate(['userId']) - .exec(); + return this.offerModel.findByIdAndUpdate(offerId, dto, { new: true }).populate('userId').exec(); } public async exists(documentId: string): Promise { - return (await this.offerModel - .exists({ _id: documentId })) !== null; + return (await this.offerModel.exists({ _id: documentId })) !== null; } public async findPremiumByCity(city: City): Promise[] | null> { - return this.offerModel - .find({ city }) - .sort({ createdAt: SortType.Down }) - .limit(DEFAULT_PREMIUM_COUNT) - .populate(['userId']) - .exec(); + return this.offerModel.find({ city }).sort({ createdAt: SortType.Down }).limit(DEFAULT_PREMIUM_COUNT).populate('userId').exec(); } } diff --git a/src/shared/modules/user/default-user.service.ts b/src/shared/modules/user/default-user.service.ts index 04f3140..5899986 100644 --- a/src/shared/modules/user/default-user.service.ts +++ b/src/shared/modules/user/default-user.service.ts @@ -39,8 +39,6 @@ export class DefaultUserService implements UserService { } public async updateById(userId: string, dto: UpdateUserDto): Promise | null> { - return this.userModel - .findByIdAndUpdate(userId, dto, { new: true }) - .exec(); + return this.userModel.findByIdAndUpdate(userId, dto, { new: true }).exec(); } }