Skip to content
Gravity Logo / Docs Gravity home
Browse documentation
Documentation/Gravity Server

Database Queries

List users for the current account

In a server controller, call user.get({ account: req.account }) to fetch the members of the authenticated account. The existing GET /api/account/users handler in controller/accountController.js uses this query and returns pending invitations separately:

const user = require('../model/user');
const invite = require('../model/invite');

exports.users = async function (req, res) {
  const users = await user.get({ account: req.account });
  const invites = await invite.get({ account: req.account, returnArray: true, used: false });

  return res.status(200).send({ data: { users, invites } });
};

How the models find account members

  • SQL (Knex) — model/sql/user.js joins user.id to account_users.user_id and filters by the membership row’s account_id.
  • MongoDB (Mongoose) — model/mongo/user.js queries the user collection with User.find({ 'account.id': account }). Each user document stores its account memberships in the account array.