wip tests update password

This commit is contained in:
sbriat
2023-07-10 17:37:50 +02:00
parent 55c4367702
commit de81325750
9 changed files with 182 additions and 8 deletions

View File

@@ -0,0 +1,11 @@
import { IsNotEmpty, IsString } from 'class-validator';
export class UpdatePasswordRequestDto {
@IsString()
@IsNotEmpty()
userId: string;
@IsString()
@IsNotEmpty()
password: string;
}

View File

@@ -0,0 +1,40 @@
import {
AggregateID,
IdResponse,
RpcExceptionCode,
RpcValidationPipe,
} from '@mobicoop/ddd-library';
import { Controller, UsePipes } from '@nestjs/common';
import { CommandBus } from '@nestjs/cqrs';
import { GrpcMethod, RpcException } from '@nestjs/microservices';
import { UpdatePasswordRequestDto } from './dtos/update-password.request.dto';
import { UpdatePasswordCommand } from '@modules/authentication/core/application/commands/update-password/update-password.command';
@UsePipes(
new RpcValidationPipe({
whitelist: true,
forbidUnknownValues: false,
}),
)
@Controller()
export class UpdatePasswordGrpcController {
constructor(private readonly commandBus: CommandBus) {}
@GrpcMethod('AuthenticationService', 'UpdatePassword')
async updatePassword(data: UpdatePasswordRequestDto): Promise<IdResponse> {
try {
const aggregateID: AggregateID = await this.commandBus.execute(
new UpdatePasswordCommand({
userId: data.userId,
password: data.password,
}),
);
return new IdResponse(aggregateID);
} catch (error: any) {
throw new RpcException({
code: RpcExceptionCode.UNKNOWN,
message: error.message,
});
}
}
}