From 5edb80c98a5fde9fea84cd2073ad004080d44942 Mon Sep 17 00:00:00 2001 From: rcole1919 Date: Wed, 30 Oct 2024 00:49:08 +0400 Subject: [PATCH] refactoring --- .../middlewares/document-exists.middleware.ts | 8 +++ .../middlewares/validate-dto.middleware.ts | 2 +- .../modules/comment/comment.controller.ts | 1 - src/shared/modules/comment/comment.http | 3 +- .../comment/default-comment.service.ts | 4 +- .../modules/comment/dto/create-comment.dto.ts | 17 +++-- .../comment/dto/create-comment.message.ts | 12 ---- .../modules/offer/default-offer.service.ts | 4 +- src/shared/modules/offer/dto/coords.dto.ts | 7 +- .../modules/offer/dto/create-offer.dto.ts | 54 +++++++-------- src/shared/modules/offer/dto/offer.message.ts | 67 ------------------- .../modules/offer/dto/update-offer.dto.ts | 52 +++++++------- src/shared/modules/offer/offer.controller.ts | 11 ++- .../modules/user/dto/create-user.dto.ts | 20 +++--- src/shared/modules/user/dto/login-user.dto.ts | 10 ++- src/shared/modules/user/dto/user.message.ts | 23 ------- src/shared/modules/user/rdo/user.rdo.ts | 7 +- 17 files changed, 98 insertions(+), 204 deletions(-) delete mode 100644 src/shared/modules/comment/dto/create-comment.message.ts delete mode 100644 src/shared/modules/offer/dto/offer.message.ts delete mode 100644 src/shared/modules/user/dto/user.message.ts diff --git a/src/rest/middlewares/document-exists.middleware.ts b/src/rest/middlewares/document-exists.middleware.ts index e5569db..85a60f8 100644 --- a/src/rest/middlewares/document-exists.middleware.ts +++ b/src/rest/middlewares/document-exists.middleware.ts @@ -13,6 +13,14 @@ export class DocumentExistsMiddleware implements IMiddleware { public async execute({ params }: Request, _res: Response, next: NextFunction): Promise { const documentId = params[this.paramName]; + if (!documentId) { + throw new HttpError( + StatusCodes.BAD_REQUEST, + `${documentId} is not defined`, + 'DocumentExistsMiddleware' + ); + } + if (! await this.service.exists(documentId)) { throw new HttpError( StatusCodes.NOT_FOUND, diff --git a/src/rest/middlewares/validate-dto.middleware.ts b/src/rest/middlewares/validate-dto.middleware.ts index 1b5c3dd..9667195 100644 --- a/src/rest/middlewares/validate-dto.middleware.ts +++ b/src/rest/middlewares/validate-dto.middleware.ts @@ -12,7 +12,7 @@ export class ValidateDTOMiddleware implements IMiddleware { const dtoInstance = plainToInstance(this.dto, body); const errors = await validate(dtoInstance); - if (errors.length > 0) { + if (errors.length) { res.status(StatusCodes.BAD_REQUEST).send(errors); return; } diff --git a/src/shared/modules/comment/comment.controller.ts b/src/shared/modules/comment/comment.controller.ts index 6d86aca..d5f838f 100644 --- a/src/shared/modules/comment/comment.controller.ts +++ b/src/shared/modules/comment/comment.controller.ts @@ -1,6 +1,5 @@ import { inject, injectable } from 'inversify'; import { Request, Response } from 'express'; -// import { StatusCodes } from 'http-status-codes'; import { BaseController, diff --git a/src/shared/modules/comment/comment.http b/src/shared/modules/comment/comment.http index 3c59a27..6269847 100644 --- a/src/shared/modules/comment/comment.http +++ b/src/shared/modules/comment/comment.http @@ -11,7 +11,8 @@ Content-Type: application/json { "text": "asddfsdasc 23dfsdfsdf sdfs", - "authorId": "66f947e7e706754fb39b93a7" + "authorId": "66f947e7e706754fb39b93a7", + "rating": 4 } ### \ No newline at end of file diff --git a/src/shared/modules/comment/default-comment.service.ts b/src/shared/modules/comment/default-comment.service.ts index 89b1588..a4079b8 100644 --- a/src/shared/modules/comment/default-comment.service.ts +++ b/src/shared/modules/comment/default-comment.service.ts @@ -4,10 +4,9 @@ import { Types } from 'mongoose'; import { ICommentService } from './types/index.js'; import { CommentEntity, CreateCommentDTO } from './index.js'; -import { COMMENT_RATING, COMPONENT, DEFAULT_COMMENTS_COUNT } from '../../constants/index.js'; +import { COMPONENT, DEFAULT_COMMENTS_COUNT } from '../../constants/index.js'; import { ILogger } from '../../libs/logger/types/index.js'; import { ESortType } from '../../types/sort-type.enum.js'; -import { getRandomNumber } from '../../helpers/index.js'; @injectable() export class DefaultCommentService implements ICommentService { @@ -20,7 +19,6 @@ export class DefaultCommentService implements ICommentService { const result = await this.commentModel.create({ ...dto, offerId, - rating: getRandomNumber(COMMENT_RATING.MIN, COMMENT_RATING.MAX), }); this.logger.info(`New comment created: ${dto.text}`); diff --git a/src/shared/modules/comment/dto/create-comment.dto.ts b/src/shared/modules/comment/dto/create-comment.dto.ts index 7720110..5009791 100644 --- a/src/shared/modules/comment/dto/create-comment.dto.ts +++ b/src/shared/modules/comment/dto/create-comment.dto.ts @@ -1,14 +1,17 @@ -import { IsMongoId, MinLength, MaxLength, IsString } from 'class-validator'; +import { IsMongoId, IsString, IsInt, Min, Max, Length } from 'class-validator'; -import { COMMENT_TEXT_LENGTH } from '../../../constants/index.js'; -import { CreateCommentValidationMessage } from './create-comment.message.js'; +import { COMMENT_RATING, COMMENT_TEXT_LENGTH } from '../../../constants/index.js'; export class CreateCommentDTO { - @IsString({ message: CreateCommentValidationMessage.text.invalidFormat }) - @MinLength(COMMENT_TEXT_LENGTH.MIN, { message: CreateCommentValidationMessage.text.minLength }) - @MaxLength(COMMENT_TEXT_LENGTH.MAX, { message: CreateCommentValidationMessage.text.maxLength }) + @IsString() + @Length(COMMENT_TEXT_LENGTH.MIN, COMMENT_TEXT_LENGTH.MAX) public text!: string; - @IsMongoId({ message: CreateCommentValidationMessage.authorId.invalid }) + @IsMongoId() public authorId!: string; + + @IsInt() + @Min(COMMENT_RATING.MIN) + @Max(COMMENT_RATING.MAX) + public rating!: number; } diff --git a/src/shared/modules/comment/dto/create-comment.message.ts b/src/shared/modules/comment/dto/create-comment.message.ts deleted file mode 100644 index 831c2b1..0000000 --- a/src/shared/modules/comment/dto/create-comment.message.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { COMMENT_TEXT_LENGTH } from '../../../constants/index.js'; - -export const CreateCommentValidationMessage = { - text: { - invalidFormat: 'Field text must be a string', - minLength: `Minimum text length must be ${COMMENT_TEXT_LENGTH.MIN}`, - maxLength: `Maximum text length must be ${COMMENT_TEXT_LENGTH.MAX}`, - }, - authorId: { - invalid: 'Field authorId must be a valid MongoDB identifier', - } -}; diff --git a/src/shared/modules/offer/default-offer.service.ts b/src/shared/modules/offer/default-offer.service.ts index 1799ea2..0961737 100644 --- a/src/shared/modules/offer/default-offer.service.ts +++ b/src/shared/modules/offer/default-offer.service.ts @@ -24,8 +24,8 @@ export class DefaultOfferService implements IOfferService { ) {} public async exists(documentId: string): Promise { - return await this.offerModel - .exists({_id: documentId}) !== null; + return this.offerModel + .exists({_id: documentId}).then(((resolve) => !!resolve)); } public async create(dto: CreateOfferDTO): Promise> { diff --git a/src/shared/modules/offer/dto/coords.dto.ts b/src/shared/modules/offer/dto/coords.dto.ts index 3be07c3..287db4e 100644 --- a/src/shared/modules/offer/dto/coords.dto.ts +++ b/src/shared/modules/offer/dto/coords.dto.ts @@ -1,10 +1,9 @@ -import { IsInt } from 'class-validator'; -import { OfferValidationMessage } from './offer.message.js'; +import { IsNumber } from 'class-validator'; export class CoordsDTO { - @IsInt({ message: OfferValidationMessage.coords.latitude.invalidFormat }) + @IsNumber() public latitude!: number; - @IsInt({ message: OfferValidationMessage.coords.longitude.invalidFormat }) + @IsNumber() public longitude!: number; } diff --git a/src/shared/modules/offer/dto/create-offer.dto.ts b/src/shared/modules/offer/dto/create-offer.dto.ts index 4e21ea2..27d9b5b 100644 --- a/src/shared/modules/offer/dto/create-offer.dto.ts +++ b/src/shared/modules/offer/dto/create-offer.dto.ts @@ -9,11 +9,10 @@ import { ArrayUnique, ArrayMinSize, ArrayMaxSize, - MinLength, - MaxLength, Min, Max, ValidateNested, + Length, } from 'class-validator'; import { Type } from 'class-transformer'; @@ -26,61 +25,58 @@ import { VISITORS_NUMBER, PRICE, } from '../../../constants/index.js'; -import { OfferValidationMessage } from './offer.message.js'; import { CoordsDTO } from './coords.dto.js'; export class CreateOfferDTO { - @IsString({ message: OfferValidationMessage.title.invalidFormat }) - @MinLength(OFFER_TITLE_LENGTH.MIN, { message: OfferValidationMessage.title.minLength }) - @MaxLength(OFFER_TITLE_LENGTH.MAX, { message: OfferValidationMessage.title.maxLength }) + @IsString() + @Length(OFFER_TITLE_LENGTH.MIN, OFFER_TITLE_LENGTH.MAX) public title!: string; - @IsString({ message: OfferValidationMessage.description.invalidFormat }) - @MinLength(OFFER_DESCRIPTION_LENGTH.MIN, { message: OfferValidationMessage.description.minLength }) - @MaxLength(OFFER_DESCRIPTION_LENGTH.MAX, { message: OfferValidationMessage.description.maxLength }) + @IsString() + @Length(OFFER_DESCRIPTION_LENGTH.MIN, OFFER_DESCRIPTION_LENGTH.MAX) public description!: string; - @IsEnum(ECity, { message: OfferValidationMessage.city.invalid }) + @IsEnum(ECity) public city!: string; - @IsString({ message: OfferValidationMessage.previewImagePath.invalidFormat }) + @IsString() public previewImagePath!: string; - @IsArray({ message: OfferValidationMessage.photos.invalidFormat }) - @ArrayMinSize(PHOTOS_LENGTH, { message: OfferValidationMessage.photos.invalidLength }) - @ArrayMaxSize(PHOTOS_LENGTH, { message: OfferValidationMessage.photos.invalidLength }) + @IsArray() + @ArrayMinSize(PHOTOS_LENGTH) + @ArrayMaxSize(PHOTOS_LENGTH) public photos!: string[]; - @IsBoolean({ message: OfferValidationMessage.isPremium.invalidFormat }) + @IsBoolean() public isPremium!: boolean; - @IsEnum(EHousing, { message: OfferValidationMessage.housingType.invalid }) + @IsEnum(EHousing) public housingType!: EHousing; - @IsInt({ message: OfferValidationMessage.roomsNumber.invalidFormat }) - @Min(ROOMS_NUMBER.MIN, { message: OfferValidationMessage.roomsNumber.min }) - @Max(ROOMS_NUMBER.MAX, { message: OfferValidationMessage.roomsNumber.max }) + @IsInt() + @Min(ROOMS_NUMBER.MIN) + @Max(ROOMS_NUMBER.MAX) public roomsNumber!: number; - @IsInt({ message: OfferValidationMessage.visitorsNumber.invalidFormat }) - @Min(VISITORS_NUMBER.MIN, { message: OfferValidationMessage.visitorsNumber.min }) - @Max(VISITORS_NUMBER.MAX, { message: OfferValidationMessage.visitorsNumber.max }) + @IsInt() + @Min(VISITORS_NUMBER.MIN) + @Max(VISITORS_NUMBER.MAX) public visitorsNumber!: number; - @IsInt({ message: OfferValidationMessage.price.invalidFormat }) - @Min(PRICE.MIN, { message: OfferValidationMessage.price.min }) - @Max(PRICE.MAX, { message: OfferValidationMessage.price.max }) + @IsInt() + @Min(PRICE.MIN) + @Max(PRICE.MAX) public price!: number; - @IsArray({ message: OfferValidationMessage.facilities.invalidFormat }) - @ArrayUnique({message: OfferValidationMessage.facilities.invalid}) + @IsArray() + @ArrayUnique() public facilities!: EFacilities[]; - @IsMongoId({ message: OfferValidationMessage.authorId.invalid }) + @IsMongoId() public authorId!: string; @ValidateNested() - @IsObject({ message: OfferValidationMessage.coords.invalidFormat }) + @IsObject() @Type(() => CoordsDTO) public coords!: CoordsDTO; } diff --git a/src/shared/modules/offer/dto/offer.message.ts b/src/shared/modules/offer/dto/offer.message.ts deleted file mode 100644 index f0344ee..0000000 --- a/src/shared/modules/offer/dto/offer.message.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { - OFFER_TITLE_LENGTH, - OFFER_DESCRIPTION_LENGTH, - PHOTOS_LENGTH, - ROOMS_NUMBER, - VISITORS_NUMBER, -} from '../../../constants/index.js'; - -export const OfferValidationMessage = { - title: { - invalidFormat: 'Field title must be a string', - minLength: `Minimum title length must be ${OFFER_TITLE_LENGTH.MIN}`, - maxLength: `Maximum title length must be ${OFFER_TITLE_LENGTH.MAX}`, - }, - description: { - invalidFormat: 'Field description must be a string', - minLength: `Minimum description length must be ${OFFER_DESCRIPTION_LENGTH.MIN}`, - maxLength: `Maximum description length must be ${OFFER_DESCRIPTION_LENGTH.MAX}`, - }, - city: { - invalid: 'city must be Paris, Cologne, Brussels, Amsterdam, Hamburg or Dusseldorf', - }, - previewImagePath: { - invalidFormat: 'Field photos must be a string', - }, - photos: { - invalidFormat: 'Field photos must be an array', - invalidLength: `Photos length must be ${PHOTOS_LENGTH}`, - }, - isPremium: { - invalidFormat: 'Field isPremium must be a boolean', - }, - housingType: { - invalid: 'housingType must be apartment, house, room or hotel', - }, - roomsNumber: { - invalidFormat: 'Field roomsNumber must be an integer', - min: `Min roomsNumber must be ${ROOMS_NUMBER.MIN}`, - max: `Max roomsNumber must be ${ROOMS_NUMBER.MAX}`, - }, - visitorsNumber: { - invalidFormat: 'Field visitorsNumber must be an integer', - min: `Min visitorsNumber must be ${VISITORS_NUMBER.MIN}`, - max: `Max visitorsNumber must be ${VISITORS_NUMBER.MAX}`, - }, - price: { - invalidFormat: 'Field price must be an integer', - min: `Min price must be ${VISITORS_NUMBER.MIN}`, - max: `Max price must be ${VISITORS_NUMBER.MAX}`, - }, - facilities: { - invalidFormat: 'Field photos must be an array', - invalid: 'facilities must be an unique array of Breakfast, Air conditioning, Laptop friendly workspace, Baby seat, Washer, Towels or Fridge', - }, - authorId: { - invalid: 'Field authorId must be a valid MongoDB identifier', - }, - coords: { - invalidFormat: 'Field coords must be an object of latitude and longitude fields', - latitude: { - invalidFormat: 'Field latitude must be an integer', - }, - longitude: { - invalidFormat: 'Field longitude must be an integer', - }, - } -}; diff --git a/src/shared/modules/offer/dto/update-offer.dto.ts b/src/shared/modules/offer/dto/update-offer.dto.ts index 6bac593..8413ee5 100644 --- a/src/shared/modules/offer/dto/update-offer.dto.ts +++ b/src/shared/modules/offer/dto/update-offer.dto.ts @@ -8,10 +8,9 @@ import { ArrayUnique, ArrayMinSize, ArrayMaxSize, - MinLength, - MaxLength, Min, Max, + Length, ValidateNested, IsOptional, } from 'class-validator'; @@ -26,71 +25,68 @@ import { VISITORS_NUMBER, PRICE, } from '../../../constants/index.js'; -import { OfferValidationMessage } from './offer.message.js'; import { CoordsDTO } from './coords.dto.js'; export class UpdateOfferDTO { @IsOptional() - @IsString({ message: OfferValidationMessage.title.invalidFormat }) - @MinLength(OFFER_TITLE_LENGTH.MIN, { message: OfferValidationMessage.title.minLength }) - @MaxLength(OFFER_TITLE_LENGTH.MAX, { message: OfferValidationMessage.title.maxLength }) + @IsString() + @Length(OFFER_TITLE_LENGTH.MIN, OFFER_TITLE_LENGTH.MAX) public title?: string; @IsOptional() - @IsString({ message: OfferValidationMessage.description.invalidFormat }) - @MinLength(OFFER_DESCRIPTION_LENGTH.MIN, { message: OfferValidationMessage.description.minLength }) - @MaxLength(OFFER_DESCRIPTION_LENGTH.MAX, { message: OfferValidationMessage.description.maxLength }) + @IsString() + @Length(OFFER_DESCRIPTION_LENGTH.MIN, OFFER_DESCRIPTION_LENGTH.MAX) public description?: string; @IsOptional() - @IsEnum(ECity, { message: OfferValidationMessage.city.invalid }) + @IsEnum(ECity) public city?: string; @IsOptional() - @IsString({ message: OfferValidationMessage.previewImagePath.invalidFormat }) + @IsString() public previewImagePath?: string; @IsOptional() - @IsArray({ message: OfferValidationMessage.photos.invalidFormat }) - @ArrayMinSize(PHOTOS_LENGTH, { message: OfferValidationMessage.photos.invalidLength }) - @ArrayMaxSize(PHOTOS_LENGTH, { message: OfferValidationMessage.photos.invalidLength }) + @IsArray() + @ArrayMinSize(PHOTOS_LENGTH) + @ArrayMaxSize(PHOTOS_LENGTH) public photos?: string[]; @IsOptional() - @IsBoolean({ message: OfferValidationMessage.isPremium.invalidFormat }) + @IsBoolean() public isPremium?: boolean; @IsOptional() - @IsEnum(EHousing, { message: OfferValidationMessage.housingType.invalid }) + @IsEnum(EHousing) public housingType?: EHousing; @IsOptional() - @IsInt({ message: OfferValidationMessage.roomsNumber.invalidFormat }) - @Min(ROOMS_NUMBER.MIN, { message: OfferValidationMessage.roomsNumber.min }) - @Max(ROOMS_NUMBER.MAX, { message: OfferValidationMessage.roomsNumber.max }) + @IsInt() + @Min(ROOMS_NUMBER.MIN) + @Max(ROOMS_NUMBER.MAX) public roomsNumber?: number; @IsOptional() - @IsInt({ message: OfferValidationMessage.visitorsNumber.invalidFormat }) - @Min(VISITORS_NUMBER.MIN, { message: OfferValidationMessage.visitorsNumber.min }) - @Max(VISITORS_NUMBER.MAX, { message: OfferValidationMessage.visitorsNumber.max }) + @IsInt() + @Min(VISITORS_NUMBER.MIN) + @Max(VISITORS_NUMBER.MAX) public visitorsNumber?: number; @IsOptional() - @IsInt({ message: OfferValidationMessage.price.invalidFormat }) - @Min(PRICE.MIN, { message: OfferValidationMessage.price.min }) - @Max(PRICE.MAX, { message: OfferValidationMessage.price.max }) + @IsInt() + @Min(PRICE.MIN) + @Max(PRICE.MAX) public price?: number; @IsOptional() - @IsArray({ message: OfferValidationMessage.facilities.invalidFormat }) - @ArrayUnique({message: OfferValidationMessage.facilities.invalid}) + @IsArray() + @ArrayUnique() public facilities?: EFacilities[]; @IsOptional() @ValidateNested() - @IsObject({ message: OfferValidationMessage.coords.invalidFormat }) + @IsObject() @Type(() => CoordsDTO) public coords?: CoordsDTO; } diff --git a/src/shared/modules/offer/offer.controller.ts b/src/shared/modules/offer/offer.controller.ts index 50b7487..6c34d3f 100644 --- a/src/shared/modules/offer/offer.controller.ts +++ b/src/shared/modules/offer/offer.controller.ts @@ -1,10 +1,10 @@ import { inject, injectable } from 'inversify'; import { Request, Response } from 'express'; -// import { StatusCodes } from 'http-status-codes'; +import { StatusCodes } from 'http-status-codes'; import { BaseController, - // HttpError, + HttpError, ValidateObjectIdMiddleware, ValidateDTOMiddleware, DocumentExistsMiddleware, @@ -64,6 +64,13 @@ export class OfferController extends BaseController { } public async index({ query }: Request, res: Response): Promise { + if (query.count !== undefined && !Number.parseInt(query.count as string, RADIX)) { + throw new HttpError( + StatusCodes.BAD_REQUEST, + 'Count query must be an integer', + 'UserController', + ); + } const offers = await this.offerService.find(Number.parseInt(query?.count as string, RADIX)); const responseData = fillDTO(ShortOfferRDO, offers); this.ok(res, responseData); diff --git a/src/shared/modules/user/dto/create-user.dto.ts b/src/shared/modules/user/dto/create-user.dto.ts index 7d014d3..1d57eb1 100644 --- a/src/shared/modules/user/dto/create-user.dto.ts +++ b/src/shared/modules/user/dto/create-user.dto.ts @@ -1,7 +1,6 @@ import { IsString, - MinLength, - MaxLength, + Length, IsEnum, IsEmail, IsOptional, @@ -9,26 +8,23 @@ import { import { USER_NAME_LENGTH, USER_PASSWORD_LENGTH } from '../../../constants/index.js'; import { EUserType } from '../../../types/index.js'; -import { UserValidationMessage } from './user.message.js'; export class CreateUserDTO { - @IsEmail({}, { message: UserValidationMessage.email.invalidFormat }) + @IsEmail() public email!: string; - @IsString({ message: UserValidationMessage.name.invalidFormat }) - @MinLength(USER_NAME_LENGTH.MIN, { message: UserValidationMessage.name.minLength }) - @MaxLength(USER_NAME_LENGTH.MAX, { message: UserValidationMessage.name.maxLength }) + @IsString() + @Length(USER_NAME_LENGTH.MIN, USER_NAME_LENGTH.MAX) public name!: string; @IsOptional() - @IsString({ message: UserValidationMessage.avatarPath.invalidFormat }) + @IsString() public avatarPath?: string; - @IsEnum(EUserType, { message: UserValidationMessage.type.invalid }) + @IsEnum(EUserType) public type!: EUserType; - @IsString({ message: UserValidationMessage.password.invalidFormat }) - @MinLength(USER_PASSWORD_LENGTH.MIN, { message: UserValidationMessage.password.minLength }) - @MaxLength(USER_PASSWORD_LENGTH.MAX, { message: UserValidationMessage.password.maxLength }) + @IsString() + @Length(USER_PASSWORD_LENGTH.MIN, USER_PASSWORD_LENGTH.MAX) public password!: string; } diff --git a/src/shared/modules/user/dto/login-user.dto.ts b/src/shared/modules/user/dto/login-user.dto.ts index e0afa9d..0f2819a 100644 --- a/src/shared/modules/user/dto/login-user.dto.ts +++ b/src/shared/modules/user/dto/login-user.dto.ts @@ -1,13 +1,11 @@ -import { IsEmail, IsString, MaxLength, MinLength } from 'class-validator'; -import { UserValidationMessage } from './user.message.js'; +import { IsEmail, IsString, Length } from 'class-validator'; import { USER_PASSWORD_LENGTH } from '../../../constants/index.js'; export class LoginUserDTO { - @IsEmail({}, { message: UserValidationMessage.email.invalidFormat }) + @IsEmail() public email!: string; - @IsString({ message: UserValidationMessage.password.invalidFormat }) - @MinLength(USER_PASSWORD_LENGTH.MIN, { message: UserValidationMessage.password.minLength }) - @MaxLength(USER_PASSWORD_LENGTH.MAX, { message: UserValidationMessage.password.maxLength }) + @IsString() + @Length(USER_PASSWORD_LENGTH.MIN, USER_PASSWORD_LENGTH.MAX) public password!: string; } diff --git a/src/shared/modules/user/dto/user.message.ts b/src/shared/modules/user/dto/user.message.ts deleted file mode 100644 index 26564e0..0000000 --- a/src/shared/modules/user/dto/user.message.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { USER_NAME_LENGTH, USER_PASSWORD_LENGTH } from '../../../constants/index.js'; - -export const UserValidationMessage = { - email: { - invalidFormat: 'Email must be a valid email format', - }, - name: { - invalidFormat: 'Field name must be a string', - minLength: `Minimum name length must be ${USER_NAME_LENGTH.MIN}`, - maxLength: `Maximum name length must be ${USER_NAME_LENGTH.MAX}`, - }, - avatarPath: { - invalidFormat: 'Field name must be a string', - }, - type: { - invalid: 'Field type must be pro or обычный', - }, - password: { - invalidFormat: 'Field password must be a string', - minLength: `Minimum password length must be ${USER_PASSWORD_LENGTH.MIN}`, - maxLength: `Maximum password length must be ${USER_PASSWORD_LENGTH.MAX}`, - } -}; diff --git a/src/shared/modules/user/rdo/user.rdo.ts b/src/shared/modules/user/rdo/user.rdo.ts index f1e4b0e..a1c64b1 100644 --- a/src/shared/modules/user/rdo/user.rdo.ts +++ b/src/shared/modules/user/rdo/user.rdo.ts @@ -1,6 +1,5 @@ -import { Expose, Transform } from 'class-transformer'; +import { Expose } from 'class-transformer'; import { EUserType } from '../../../types/index.js'; -import { ObjectId } from 'mongoose'; export class UserRDO { @Expose() @@ -14,8 +13,4 @@ export class UserRDO { @Expose() public type!: EUserType; - - @Expose() - @Transform((value) => value.obj.favorites.map((f: ObjectId) => f.toString())) - public favorites!: string[]; }