N
N
NOneNice2021-10-08 22:58:19
PostgreSQL
NOneNice, 2021-10-08 22:58:19

Why is the delete method not working?

Good afternoon, I'm trying to parse in the backend and I can't understand why the deletion method does not work
In the service:

async remove(req) {
        return await this.UserRepository.destroy({
            where : {id : req.param.id},
            force : true
        });
    }


In the controller:
@Delete(':id')
    remove(@Param('id') id : string)
    {
        return this.usersService.remove(id);
    }


Gives an error: ERROR [ExceptionsHandler] Cannot read property 'id' of undefined

I would like to know why I can't reach id? But if I hardcode a specific id, it deletes it, or if I enter truncate : true it deletes the db completely, but how can I delete a specific id ?
Git: https://github.com/NOneNice/project-for-home

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Sviridov, 2021-10-08
@NOneNice

Maybe the service should be like this?

async remove(userId: number) {
        return await this.UserRepository.destroy({
            where : {id : userId},
            force : true
        });
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question