Home > front end >  How to make a request if a field with the uuid type is null?
How to make a request if a field with the uuid type is null?

Time:01-13

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,
  },
});

CodePudding user response:

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.

  • Related