Hi Midha, I created a plugin to help simplify this problem: strapi-plugin-public-permissions - npm.
Hopefully it helps solve your problem!
If you’d rather code the solution yourself, for the plugin I ended up using strapi.db.connection to gain access to knex (the underlying ORM which Strapi uses to interact with the database). You can see the approach I took here.