mirror of
https://gitlab.com/mobicoop/v3/service/auth.git
synced 2026-01-08 12:02:41 +00:00
authorization presenter
This commit is contained in:
@@ -21,7 +21,7 @@ import { Authentication } from '../../domain/entities/authentication';
|
||||
import { Username } from '../../domain/entities/username';
|
||||
import { ValidateAuthenticationQuery } from '../../queries/validate-authentication.query';
|
||||
import { AuthenticationPresenter } from './authentication.presenter';
|
||||
import { RpcValidationPipe } from './rpc.validation-pipe';
|
||||
import { RpcValidationPipe } from '../../../../utils/pipes/rpc.validation-pipe';
|
||||
import { UsernamePresenter } from './username.presenter';
|
||||
|
||||
@UsePipes(
|
||||
@@ -43,10 +43,14 @@ export class AuthenticationController {
|
||||
data: ValidateAuthenticationRequest,
|
||||
): Promise<AuthenticationPresenter> {
|
||||
try {
|
||||
const auth: Authentication = await this._queryBus.execute(
|
||||
const authentication: Authentication = await this._queryBus.execute(
|
||||
new ValidateAuthenticationQuery(data.username, data.password),
|
||||
);
|
||||
return this._mapper.map(auth, Authentication, AuthenticationPresenter);
|
||||
return this._mapper.map(
|
||||
authentication,
|
||||
Authentication,
|
||||
AuthenticationPresenter,
|
||||
);
|
||||
} catch (e) {
|
||||
throw new RpcException({
|
||||
code: 7,
|
||||
@@ -60,10 +64,14 @@ export class AuthenticationController {
|
||||
data: CreateAuthenticationRequest,
|
||||
): Promise<AuthenticationPresenter> {
|
||||
try {
|
||||
const auth: Authentication = await this._commandBus.execute(
|
||||
const authentication: Authentication = await this._commandBus.execute(
|
||||
new CreateAuthenticationCommand(data),
|
||||
);
|
||||
return this._mapper.map(auth, Authentication, AuthenticationPresenter);
|
||||
return this._mapper.map(
|
||||
authentication,
|
||||
Authentication,
|
||||
AuthenticationPresenter,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof DatabaseException) {
|
||||
if (e.message.includes('Already exists')) {
|
||||
@@ -135,11 +143,15 @@ export class AuthenticationController {
|
||||
data: UpdatePasswordRequest,
|
||||
): Promise<AuthenticationPresenter> {
|
||||
try {
|
||||
const auth: Authentication = await this._commandBus.execute(
|
||||
const authentication: Authentication = await this._commandBus.execute(
|
||||
new UpdatePasswordCommand(data),
|
||||
);
|
||||
|
||||
return this._mapper.map(auth, Authentication, AuthenticationPresenter);
|
||||
return this._mapper.map(
|
||||
authentication,
|
||||
Authentication,
|
||||
AuthenticationPresenter,
|
||||
);
|
||||
} catch (e) {
|
||||
throw new RpcException({
|
||||
code: 7,
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { Injectable, ValidationPipe } from '@nestjs/common';
|
||||
import { RpcException } from '@nestjs/microservices';
|
||||
|
||||
@Injectable()
|
||||
export class RpcValidationPipe extends ValidationPipe {
|
||||
createExceptionFactory() {
|
||||
return (validationErrors = []) => {
|
||||
return new RpcException({
|
||||
code: 3,
|
||||
message: this.flattenValidationErrors(validationErrors),
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user