mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: merge organization member db queries (#13542)
Merge members queries into 1 that also joins in the user table for username. Required to list organization members on UI/cli
This commit is contained in:
@ -1,13 +1,28 @@
|
||||
-- name: GetOrganizationMemberByUserID :one
|
||||
-- name: OrganizationMembers :many
|
||||
-- Arguments are optional with uuid.Nil to ignore.
|
||||
-- - Use just 'organization_id' to get all members of an org
|
||||
-- - Use just 'user_id' to get all orgs a user is a member of
|
||||
-- - Use both to get a specific org member row
|
||||
SELECT
|
||||
*
|
||||
sqlc.embed(organization_members),
|
||||
users.username
|
||||
FROM
|
||||
organization_members
|
||||
INNER JOIN
|
||||
users ON organization_members.user_id = users.id
|
||||
WHERE
|
||||
organization_id = $1
|
||||
AND user_id = $2
|
||||
LIMIT
|
||||
1;
|
||||
-- Filter by organization id
|
||||
CASE
|
||||
WHEN @organization_id :: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
|
||||
organization_id = @organization_id
|
||||
ELSE true
|
||||
END
|
||||
-- Filter by user id
|
||||
AND CASE
|
||||
WHEN @user_id :: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
|
||||
user_id = @user_id
|
||||
ELSE true
|
||||
END;
|
||||
|
||||
-- name: InsertOrganizationMember :one
|
||||
INSERT INTO
|
||||
@ -22,14 +37,6 @@ VALUES
|
||||
($1, $2, $3, $4, $5) RETURNING *;
|
||||
|
||||
|
||||
-- name: GetOrganizationMembershipsByUserID :many
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
organization_members
|
||||
WHERE
|
||||
user_id = $1;
|
||||
|
||||
-- name: GetOrganizationIDsByMemberIDs :many
|
||||
SELECT
|
||||
user_id, array_agg(organization_id) :: uuid [ ] AS "organization_IDs"
|
||||
|
Reference in New Issue
Block a user