async function validateUniqueValues(ctx, username, email) {
  username = validator.trim(username).toLowerCase();
  let queryString = "/users?or=(";

  if (username != null) {
    queryString += `username.eq.${username}`;
  }

  if (email != null) {
    if (username != null) {
      queryString += `,`;
    }
    queryString += `email.eq.${email}`;
  }

  queryString += `)`;

  // database request to check for values
  const response = await dbServer.get(queryString);
  const userArray = response.data;

  // create feedback
  if (userArray.length > 0) {
    let feedback = "These are already in use:";
    if (userArray.findIndex((x) => x.username === username) >= 0) {
      feedback += " username";
    }
    if (userArray.findIndex((x) => x.email === email) >= 0) {
      feedback += " email";
    }

    // there is an user already with email/username
    return { valid: false, msg: feedback };
  }
  // both values are not used
  return { valid: true };
}
// function to check if username and email is unique
function to check if username and email is unique
function to check if username and email is unique
async function validateUniqueValues(ctx, username, email) {
  username = validator.trim(username).toLowerCase();
  let queryString = "/users?or=(";
  if (username != null) {
    queryString += `username.eq.${username}`;
  }
  if (email != null) {
    if (username != null) {
      queryString += `,`;
    }
    queryString += `email.eq.${email}`;
  }
  queryString += `)`;
  const response = await dbServer.get(queryString);
  const userArray = response.data;
  if (userArray.length > 0) {
    let feedback = "These are already in use:";
    if (userArray.findIndex((x) => x.username === username) >= 0) {
      feedback += " username";
    }
    if (userArray.findIndex((x) => x.email === email) >= 0) {
      feedback += " email";
    }
    return { valid: false, msg: feedback };
  }
  return { valid: true };
}
async function validateUniqueValues ( ctx , username , email ) { username = validator . trim ( username ) . toLowerCase ( ) ; let queryString = "/users?or=(" ; if ( username != null ) { queryString += ` ${ username } ` ; } if ( email != null ) { if ( username != null ) { queryString += ` ` ; } queryString += ` ${ email } ` ; } queryString += ` ` ; const response = await dbServer . get ( queryString ) ; const userArray = response . data ; if ( userArray . length > 0 ) { let feedback = "These are already in use:" ; if ( userArray . findIndex ( ( x ) => x . username === username ) >= 0 ) { feedback += " username" ; } if ( userArray . findIndex ( ( x ) => x . email === email ) >= 0 ) { feedback += " email" ; } return { valid : false , msg : feedback } ; } return { valid : true } ; }
function to check if username and email is unique
function to check if username and email is unique
// database request to check for values // create feedback // there is an user already with email/username // both values are not used