Search code examples
node.jspostgresqlnestjstypeorm

How to make a request if a field with the uuid type is null?


I have an optional field parent that has a data type uuid . Sometimes this field may be empty.

How to execute a get data request if the field is null?

invalid syntax for uuid type: "null"

const current_file = await this.fileService.findOne({
  relations: ['user', 'parent'],
  where: {
    name: file.originalname,
    user: current_user.user_id,
    parent: request.body.parent,
  },
});

Solution

  • const current_file = await this.fileService.findOne({
      relations: ['user', 'parent'],
      where: {
        name: file.originalname,
        user: current_user.user_id,
        parent: request.body.parent || undefined,
      },
    });
    

    This way when parent is null you actually set the key as undefined via the || operator.