node_acl
node_acl copied to clipboard
How to get all roles and userRoles ?
hi, don't you have any ideas?
You could do this using your native data storage. There should be a link to it in the Acl object. I used mongo db so yours is probably different. Also the syntax is es7 so might have to do a bit of translating.
import { connect as mongoConnect } from "mongodb";
import acl from "acl";
const connectToMongoDb = () => new Promise((resolve, reject) => {
mongoConnect(`${process.env.database}/mastermindacl`, (err, db) => {
if (err) return reject(err);
else return resolve(db);
});
});
const findAllRoles = async ({ backend: { db } }) => {
const collection = await db.collection("acl_roles");
return new Promise((resolve, reject) => {
collection.find({}).toArray((err, roles) => {
if (err) reject(err);
else resolve(roles);
});
});
};
const getAllroles = () => {
const aclDatabase = await connectToMongoDb();
const ACL = new acl(new acl.mongodbBackend(aclDatabase, "acl_"));
return await findAllRoles(ACL)
}