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