| 1 |
|
defmodule DaProductApp.SaasKit.Users do |
| 2 |
|
@moduledoc """ |
| 3 |
|
Module for handling user management through SaaS Kit. |
| 4 |
|
""" |
| 5 |
|
|
| 6 |
|
alias DaProductApp.SaasKit.Client |
| 7 |
|
|
| 8 |
|
@doc """ |
| 9 |
|
Create a new user |
| 10 |
|
""" |
| 11 |
|
def create_user(user_data) do |
| 12 |
:-( |
Client.post("/users", user_data) |
| 13 |
|
end |
| 14 |
|
|
| 15 |
|
@doc """ |
| 16 |
|
Get user by ID |
| 17 |
|
""" |
| 18 |
|
def get_user(user_id) do |
| 19 |
:-( |
Client.get("/users/#{user_id}") |
| 20 |
|
end |
| 21 |
|
|
| 22 |
|
@doc """ |
| 23 |
|
Update user information |
| 24 |
|
""" |
| 25 |
|
def update_user(user_id, user_data) do |
| 26 |
:-( |
Client.put("/users/#{user_id}", user_data) |
| 27 |
|
end |
| 28 |
|
|
| 29 |
|
@doc """ |
| 30 |
|
Delete a user |
| 31 |
|
""" |
| 32 |
|
def delete_user(user_id) do |
| 33 |
:-( |
Client.delete("/users/#{user_id}") |
| 34 |
|
end |
| 35 |
|
|
| 36 |
|
@doc """ |
| 37 |
|
List users with optional filters |
| 38 |
|
""" |
| 39 |
:-( |
def list_users(params \\ %{}) do |
| 40 |
:-( |
Client.get("/users", params) |
| 41 |
|
end |
| 42 |
|
|
| 43 |
|
@doc """ |
| 44 |
|
Authenticate a user |
| 45 |
|
""" |
| 46 |
|
def authenticate_user(email, password) do |
| 47 |
:-( |
body = %{ |
| 48 |
|
email: email, |
| 49 |
|
password: password |
| 50 |
|
} |
| 51 |
|
|
| 52 |
:-( |
Client.post("/auth/login", body) |
| 53 |
|
end |
| 54 |
|
|
| 55 |
|
@doc """ |
| 56 |
|
Get user permissions |
| 57 |
|
""" |
| 58 |
|
def get_user_permissions(user_id) do |
| 59 |
:-( |
Client.get("/users/#{user_id}/permissions") |
| 60 |
|
end |
| 61 |
|
|
| 62 |
|
@doc """ |
| 63 |
|
Update user permissions |
| 64 |
|
""" |
| 65 |
|
def update_user_permissions(user_id, permissions) do |
| 66 |
:-( |
body = %{permissions: permissions} |
| 67 |
:-( |
Client.put("/users/#{user_id}/permissions", body) |
| 68 |
|
end |
| 69 |
|
|
| 70 |
|
@doc """ |
| 71 |
|
Get user's organization/tenant information |
| 72 |
|
""" |
| 73 |
|
def get_user_organization(user_id) do |
| 74 |
:-( |
Client.get("/users/#{user_id}/organization") |
| 75 |
|
end |
| 76 |
|
|
| 77 |
|
@doc """ |
| 78 |
|
Invite a user to an organization |
| 79 |
|
""" |
| 80 |
:-( |
def invite_user(organization_id, email, role \\ "member") do |
| 81 |
:-( |
body = %{ |
| 82 |
|
organization_id: organization_id, |
| 83 |
|
email: email, |
| 84 |
|
role: role |
| 85 |
|
} |
| 86 |
|
|
| 87 |
:-( |
Client.post("/invitations", body) |
| 88 |
|
end |
| 89 |
|
|
| 90 |
|
@doc """ |
| 91 |
|
Accept an invitation |
| 92 |
|
""" |
| 93 |
|
def accept_invitation(invitation_token, user_data) do |
| 94 |
:-( |
body = Map.put(user_data, :invitation_token, invitation_token) |
| 95 |
:-( |
Client.post("/invitations/accept", body) |
| 96 |
|
end |
| 97 |
|
end |