well, I'm making an api with rabbitmq, where one part I want the user with enough prestige to be able to update the question of a random user, who can vote or give a negative vote, thus changing that user's prestige, losing prestige due to a negative vote or improving due to a positive vote, but to me it seems right but it returns an error saying that:
Error:
invalid input syntax for type uuid: "{"idUsuario":"d7b24127-32d5-4936-a53f-4b5c690de8a1","idUsuarioPropio":"4b4bae21-ecfb-4f10-af23-4a2dc50e34a5","id":"d6259a4f-eb25-494f-bc65-1161107d6b8f","voto":-1,"titulo":"opa eai","pergunta":"e assim e assim opa eai cara como e"}"
my codes:
my usuarioPrestigiadoAtualiza(User with sufficient prestige updates and votes or down votes on a user's question):
async usuarioPrestigiadoAtualiza(idUsuario: string, idUsuarioPropio: string, dados: atualizaEspecificoDTO){
const { id, titulo, pergunta, voto } = dados
const usuario = await this.usuarioMetaRepository.findOne({where: {id: idUsuario}})
if(usuario === null){
throw new NotFoundException('Usuario Prestigiado nao existe')
}
const usuario2 = await this.usuarioMetaRepository.findOne({where: {id: idUsuarioPropio}})
if(usuario2 === null){
throw new NotFoundException('Usuario Propio nao existe')
}
if(usuario2.pergunta.id !== id){
throw new UnauthorizedException('Usuario Propio nao possui essa pergunta')
}
const perguntaAchada = await this.perguntaRepository.findOne({where: {id}})
if(perguntaAchada === null){
throw new NotFoundException('Pergunta nao existe')
}
const perguntaEntidade = new PerguntaEntidade()
perguntaEntidade.id = id
perguntaEntidade.titulo = titulo
perguntaEntidade.pergunta = pergunta
perguntaEntidade.voto = voto
if(usuario.prestigio < 100){
throw new UnauthorizedException(`Usuario: ${usuario.nome} nao possui prestigio suficiente!`)
}
if(voto === -1){
usuario2.prestigio - 5
usuario2.voteForce - 2
}
if(voto > 1){
for(let i = 0; i < 100 ; i++){
if(usuario2.pergunta.voto + 1){
usuario2.prestigio + 4
usuario2.voteForce + 1
}
}
}
if(usuario.voteForce > 30){
voto * 2
}
if(usuario.voteForce > 60){
voto * 3
}
if(usuario.voteForce >= 100){
voto * 4
}
if(usuario2.prestigio > 100){
usuario2.prestigio === 100
}
if(voto === -10){
return await this.perguntaRepository.remove(perguntaAchada)
}
const perguntaMudadaPorPrestigiado = await this.perguntaRepository.save(perguntaEntidade)
return perguntaMudadaPorPrestigiado
}
my controler:
@MessagePattern({ cmd: 'put-perguntaPrestigio'})
async enviarPerguntaAvaliada(@Ctx() contexto: RmqContext, @Payload() id: string, @Payload() id2: string, @Payload() dados: atualizaEspecificoDTO){
const channel = contexto.getChannelRef()
const message = contexto.getMessage()
channel.ack(message)
return this.perguntaService.usuarioPrestigiadoAtualiza(id, id2, dados)
my api gateway controler:
@Put('usuarioM/:id1/:id2/:id3')
async perguntaAtualizaPorPrestigiado(@Param('id1') idUsuario: string, @Param('id2') idUsuarioPropio: string, @Param('id3') id: string, @Body() data: atualizaEspecificoDTO) {
return this.authServico.send(
{
cmd: 'put-perguntaPrestigio'
}, {idUsuario, idUsuarioPropio, id, ...data}
)
}
my dto postman
{
"voto": -1,
"titulo": "opa eai",
"pergunta": "e assim e assim opa eai cara como e"
}
my create question:
export class criarPerguntaDTO {
@IsUUID()
id: string
@IsNumber()
voto: number
@IsNotEmpty()
@MaxLength(100, {message: 'limite de 100 caracteres de titulo'})
titulo: string
@IsNotEmpty()
pergunta: string
}
As I said, when I give a send, this error comes back to me, I wanted this user with sufficient privilege to update the question and if a -1 is inserted, the user who asked would lose privilege, or vice versa if the vote(voto) is good, but give me this error, and I don't know what to do.
@Payload()
returns the entire payload object, not just a part of it, so you only need it once @Payload() payload: { idUsuario: string; idUsuarioPropio: string; dados: atualizaEspecificoDTO }
and then you can access payload.idUsuario
, payload.idUsuarioPropio
, etc