defmodule Noted.Workspace.Team do
use Ash.Resource,
otp_app: :noted,
domain: Noted.Workspace,
authorizers: [Ash.Policy.Authorizer],
data_layer: AshPostgres.DataLayer
postgres do
table "teams"
repo Noted.Repo
end
actions do
defaults [:read]
create :create_team do
# 1. Create new Team
# 2. Create a new TeamMember, relate it to the actor and newly created team, and assign it an admin role (this must be done in a transaction)
end
end
attributes do
uuid_v7_primary_key :id
attribute :name, :string do
allow_nil? false
public? true
constraints min_length: 2, max_length: 50
end
create_timestamp :created_at
update_timestamp :updated_at
end
relationships do
has_many :invitations, Noted.Workspace.Invitation
many_to_many :users, Noted.Accounts.User do
through Noted.Workspace.TeamMember
end
end
end
defmodule Noted.Workspace.Team do
use Ash.Resource,
otp_app: :noted,
domain: Noted.Workspace,
authorizers: [Ash.Policy.Authorizer],
data_layer: AshPostgres.DataLayer
postgres do
table "teams"
repo Noted.Repo
end
actions do
defaults [:read]
create :create_team do
# 1. Create new Team
# 2. Create a new TeamMember, relate it to the actor and newly created team, and assign it an admin role (this must be done in a transaction)
end
end
attributes do
uuid_v7_primary_key :id
attribute :name, :string do
allow_nil? false
public? true
constraints min_length: 2, max_length: 50
end
create_timestamp :created_at
update_timestamp :updated_at
end
relationships do
has_many :invitations, Noted.Workspace.Invitation
many_to_many :users, Noted.Accounts.User do
through Noted.Workspace.TeamMember
end
end
end