dbaas
Version:
Database as a service. Expose db to REST and GraphQL.
37 lines • 1.24 kB
JavaScript
import { InvalidCredentialsException, ItemsService } from "directus";
async function getUserAccountability(reqOrFilterCtxOrActionCtx, userId) {
const options = {
schema: reqOrFilterCtxOrActionCtx.schema,
knex: "database" in reqOrFilterCtxOrActionCtx
? reqOrFilterCtxOrActionCtx.database
: undefined,
accountability: { role: null, admin: true },
};
const userService = new ItemsService("directus_users", options);
const roleService = new ItemsService("directus_roles", options);
const [user] = await userService.readByQuery({
filter: {
id: { _eq: userId },
status: { _eq: "active" },
},
limit: 1,
});
if (!user) {
throw new InvalidCredentialsException("User not found");
}
const [role] = await roleService.readByQuery({
filter: {
id: { _eq: user.role },
},
limit: 1,
});
const accountability = {
user: user.id,
role: user.role ? user.role : null,
admin: role?.admin_access,
app: role?.app_access,
};
return accountability;
}
export default getUserAccountability;
//# sourceMappingURL=getUserAccountability.js.map