I use postgresql/sequelize and findAndCountAll function. I want client can filter based on attributes that choose , I haven't any idea to this , if you have any solution let me know. this is my code:
try {
const { count, rows: usersPersonalInfo } = await PersonalInfo.findAndCountAll({
offset: (pageNo - 1) * pageSize,
limit: pageSize,
subQuery: false,
distinct: true,
where: {
userId: { [Op.in]: allowedOrgUserIds },
deletedAt: null,
},
attributes:["firstName", "middleName", "lastName", "dob"],
include: [
{
model: User,
attributes:["id", "user"],
include:[
{
model: Location,
as:'locations',
attributes:["id", "locationName", "locationAddress"]
},
],
}]
})
success(res)({
providersList: usersPersonalInfo,
total: count,
pageNo,
pageSize,
})
} catch (error) {
handleError(res)(error);
}
for example I want see only firstName , dob , and locationName attributes .
127.0.0.1:10000/attributesFilter/pageNo=1&pageSize=10&sortBy=&sortASC=&attributes=dob,firstName