Answers for "generic query params"

1

generic query params

const keys = Object.keys(query);

  // generic query parameter
  for (let i = 0; i < keys.length; i += 1) {
    if (keys[i].match(/generic/gi)) {
      const genericArr = query[keys[i]].split(',');

      if (genericArr[0] in AssessorRecord.rawAttributes) {
        const genericField = genericArr[0];
        let genericValue = genericArr[2];
        const genericType = AssessorRecord.rawAttributes[genericField].type.key;

        if (genericType === 'INTEGER' || genericType === 'DECIMAL') {
          genericValue = Number(genericValue);
        } else if (genericType === 'DATE') {
          genericValue = new Date(genericValue);
        } else if (genericType === 'BOOLEAN') {
          genericValue = Number(genericValue);
          if (genericValue === 1 || genericValue === 0) {
            genericValue = Number(genericValue);
          } else {
            return res
              .status(400)
              .json({ detail: `only booleans values are valid for the field ${genericField}` });
          }
        }
        where[genericField] = {
          [Op[genericArr[1]]]: genericValue,
        };
      } else {
        return res.status(400).json({ detail: `please pass correct query params` });
      }
    }
  }
Posted by: Guest on October-05-2021
0

@query with generics

@Query("Select t.type from #{#entityName} t")
Posted by: Guest on May-27-2021
1

generic query params

const keys = Object.keys(query);

  // generic query parameter
  for (let i = 0; i < keys.length; i += 1) {
    if (keys[i].match(/generic/gi)) {
      const genericArr = query[keys[i]].split(',');

      if (genericArr[0] in AssessorRecord.rawAttributes) {
        const genericField = genericArr[0];
        let genericValue = genericArr[2];
        const genericType = AssessorRecord.rawAttributes[genericField].type.key;

        if (genericType === 'INTEGER' || genericType === 'DECIMAL') {
          genericValue = Number(genericValue);
        } else if (genericType === 'DATE') {
          genericValue = new Date(genericValue);
        } else if (genericType === 'BOOLEAN') {
          genericValue = Number(genericValue);
          if (genericValue === 1 || genericValue === 0) {
            genericValue = Number(genericValue);
          } else {
            return res
              .status(400)
              .json({ detail: `only booleans values are valid for the field ${genericField}` });
          }
        }
        where[genericField] = {
          [Op[genericArr[1]]]: genericValue,
        };
      } else {
        return res.status(400).json({ detail: `please pass correct query params` });
      }
    }
  }
Posted by: Guest on October-05-2021
0

@query with generics

@Query("Select t.type from #{#entityName} t")
Posted by: Guest on May-27-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language