generic query params

Solutions on MaxInterview for generic query params by the best coders in the world

showing results for - "generic query params"
Stefano
21 Jan 2018
1  const keys = Object.keys(query);
2
3  // generic query parameter
4  for (let i = 0; i < keys.length; i += 1) {
5    if (keys[i].match(/generic/gi)) {
6      const genericArr = query[keys[i]].split(',');
7
8      if (genericArr[0] in AssessorRecord.rawAttributes) {
9        const genericField = genericArr[0];
10        let genericValue = genericArr[2];
11        const genericType = AssessorRecord.rawAttributes[genericField].type.key;
12
13        if (genericType === 'INTEGER' || genericType === 'DECIMAL') {
14          genericValue = Number(genericValue);
15        } else if (genericType === 'DATE') {
16          genericValue = new Date(genericValue);
17        } else if (genericType === 'BOOLEAN') {
18          genericValue = Number(genericValue);
19          if (genericValue === 1 || genericValue === 0) {
20            genericValue = Number(genericValue);
21          } else {
22            return res
23              .status(400)
24              .json({ detail: `only booleans values are valid for the field ${genericField}` });
25          }
26        }
27        where[genericField] = {
28          [Op[genericArr[1]]]: genericValue,
29        };
30      } else {
31        return res.status(400).json({ detail: `please pass correct query params` });
32      }
33    }
34  }
35
Simone
08 Jun 2017
1@Query("Select t.type from #{#entityName} t")
2