Assign production plans to Graphs users

This commit is contained in:
Cauê Faleiros
2026-08-25 13:40:52 -03:00
parent d14f7e315f
commit c259ddea29
8 changed files with 147 additions and 24 deletions

View File

@@ -59,6 +59,35 @@ const listUsers = async () => {
return result.rows.map(publicUserFields);
};
// This deliberately exposes only the identity needed to assign operational
// responsibility. It is available to signed-in Graphs users, unlike the full
// user-management list which remains super-admin only.
const listActiveOperationalUsers = async () => {
const result = await pool.query(
`SELECT id, name
FROM app_users
WHERE is_active = TRUE
ORDER BY LOWER(name), id`
);
return result.rows.map((row) => ({
id: Number(row.id),
name: row.name
}));
};
const getActiveOperationalUserById = async (id, client = pool) => {
const result = await client.query(
`SELECT id, name
FROM app_users
WHERE id = $1 AND is_active = TRUE
LIMIT 1`,
[id]
);
return result.rows[0] || null;
};
const createUser = async ({ name, email, password }) => {
const normalizedName = String(name || '').trim();
const normalizedEmail = normalizeEmail(email);
@@ -200,6 +229,8 @@ module.exports = {
findUserById,
findUserByEmail,
generatePassword,
getActiveOperationalUserById,
listActiveOperationalUsers,
listUsers,
normalizeEmail,
publicUserFields,