Skip to content

Commit

Permalink
[person/department] new func to add department or get one by name
Browse files Browse the repository at this point in the history
  • Loading branch information
flablog committed Aug 1, 2024
1 parent 296aeaa commit 26071e4
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions gazu/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ def get_all_month_time_spents(id, date, client=default):
client=client,
)

@cache
def get_department_by_name(name, client=default):
"""
Args:
name (str): department name.
Returns:
dict: department corresponding to given name.
"""
return raw.fetch_first(
"departments",
{"name": name},
client=client,
)

@cache
def get_person(id, relations=False, client=default):
Expand Down Expand Up @@ -182,6 +196,35 @@ def get_organisation(client=default):
return raw.get("auth/authenticated", client=client)["organisation"]


def new_department(
name,
color="",
archived=False,
client=default
):
"""
Create a new departement based on given parameters.
Args:
name (str): the name of the departement.
color (str): the color of the departement.
archived (bool): Whether the departement is archived or not.
Returns:
dict: Created departement.
"""
department = get_department_by_name(name, client=client)
if department is None:
department = raw.post(
"data/departments",
{
"name": name,
"color": color,
"archived": archived
},
client=client,
)
return department

def new_person(
first_name,
last_name,
Expand Down

0 comments on commit 26071e4

Please sign in to comment.