Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
joker77-github committed Nov 5, 2024
1 parent 6c7f8d2 commit 341103b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
16 changes: 1 addition & 15 deletions src/shared/helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,4 @@ export function reduceValidationErrors(errors: ValidationError[]): ValidationErr

export function getFullServerPath(host: string, port: number) {
return `http://${host}:${port}`;
export function createErrorObject(errorType: ApplicationError, error: string, details: ValidationErrorField[] = []) {
return { errorType, error, details };
}

export function reduceValidationErrors(errors: ValidationError[]): ValidationErrorField[] {
return errors.map(({ property, value, constraints }) => ({
property,
value,
messages: constraints ? Object.values(constraints) : []
}));
}

export function getFullServerPath(host: string, port: number) {
return `http://${host}:${port}`;
}
}
2 changes: 0 additions & 2 deletions src/shared/libs/rest/middleware/validate-dto.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import { ValidationError } from '../errors/validation.error.js';
export class ValidateDtoMiddleware implements Middleware {
constructor(private dto: ClassConstructor<object>) { }

public async execute({ body, path }: Request, _res: Response, next: NextFunction): Promise<void> {
public async execute({ body, path }: Request, _res: Response, next: NextFunction): Promise<void> {
const dtoInstance = plainToInstance(this.dto, body);
const errors = await validate(dtoInstance);

if (errors.length > 0) {
throw new ValidationError(`Validation error: ${path}`, reduceValidationErrors(errors));
throw new ValidationError(`Validation error: ${path}`, reduceValidationErrors(errors));
}

next();
Expand Down
5 changes: 3 additions & 2 deletions src/shared/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { fillDTO } from '../../helpers/common.js';
import { UserRdo } from './rdo/user.rdo.js';
import { LoginUserRequest } from './types/login-user-request.type.js';
import { CreateUserRequest } from './types/create-user-request.type.js';
import { BaseController, HttpError, UploadFileMiddleware, ValidateDtoMiddleware, ValidateObjectIdMiddleware } from '../../libs/rest/index.js';
import { BaseController, HttpError, PrivateRouteMiddleware, UploadFileMiddleware, ValidateDtoMiddleware, ValidateObjectIdMiddleware } from '../../libs/rest/index.js';
import { LoginUserDto } from './dto/login-user.dto.js';
import { AuthService } from '../auth/index.js';
import { OfferService } from '../offer/index.js';
import { FavoriteOfferRdo } from '../offer/rdo/favorite-offer.rdo.js';
import { UploadUserAvatarRdo } from './rdo/upload-user-avatar.rdo.js';

@injectable()
export class UserController extends BaseController {
Expand All @@ -22,7 +23,7 @@ export class UserController extends BaseController {
@inject(Component.UserService) private readonly userService: UserService,
@inject(Component.Config) private readonly configService: Config<RestSchema>,
@inject(Component.AuthService) private readonly authService: AuthService,
// @inject(Component.OfferService) private readonly offerService: OfferService,
@inject(Component.OfferService) private readonly offerService: OfferService,
) {
super(logger);
this.logger.info('Register routes for UserController');
Expand Down

0 comments on commit 341103b

Please sign in to comment.