Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
fix: Move class to api file
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Feb 25, 2024
1 parent 5974244 commit 7cf8212
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 63 deletions.
62 changes: 62 additions & 0 deletions tm_admin/users/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,68 @@ async def getByName(self,
results = await self.execute(sql)
return results

async def updateRole(self,
id: int,
role: Userrole,
):
"""
Update the role for a user.
Args:
id (int): The users ID
role (Userrole): The new role.
"""
role = Userrole(role)
return self.updateColumn(id, {'role': role.name})

async def updateMappingLevel(self,
id: int,
level: Mappinglevel,
):
"""
Update the mapping level for a user.
Args:
id (int): The users ID.
level (Mappinglevel): The new level.
"""
mlevel = Mappinglevel(level)
result = await self.updateColumn(id, {'mapping_level': mlevel.name})
return result

async def updateExpert(self,
id: int,
mode: bool,
):
"""
Toggle the expert mode for a user.
Args:
id (int): The users ID.
mode (bool): The new mode..
"""
result = await self.updateColumn(id, {'expert_mode': mode})
return result

async def getRegistered(self,
start: datetime,
end: datetime,
):
"""
Get all users registered in this timeframe.
Args:
start (datetime): The starting timestamp
end (datetime): The starting timestamp
Returns:
(list): The users registered in this timeframe.
"""

where = f" date_registered > '{start}' and date_registered < '{end}'"
result = self.getByWhere(where)
return result

async def main():
"""This main function lets this class be run standalone by a bash script."""
parser = argparse.ArgumentParser()
Expand Down
63 changes: 0 additions & 63 deletions tm_admin/users/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,69 +291,6 @@ async def mergeFavorites(self,
timer.stop()
return True

# These are just convience wrappers to support the REST API.
async def updateRole(self,
id: int,
role: Userrole,
):
"""
Update the role for a user.
Args:
id (int): The users ID
role (Userrole): The new role.
"""
role = Userrole(role)
return self.updateColumn(id, {'role': role.name})

async def updateMappingLevel(self,
id: int,
level: Mappinglevel,
):
"""
Update the mapping level for a user.
Args:
id (int): The users ID.
level (Mappinglevel): The new level.
"""
mlevel = Mappinglevel(level)
result = await self.updateColumn(id, {'mapping_level': mlevel.name})
return result

async def updateExpert(self,
id: int,
mode: bool,
):
"""
Toggle the expert mode for a user.
Args:
id (int): The users ID.
mode (bool): The new mode..
"""
result = await self.updateColumn(id, {'expert_mode': mode})
return result

async def getRegistered(self,
start: datetime,
end: datetime,
):
"""
Get all users registered in this timeframe.
Args:
start (datetime): The starting timestamp
end (datetime): The starting timestamp
Returns:
(list): The users registered in this timeframe.
"""

where = f" date_registered > '{start}' and date_registered < '{end}'"
result = self.getByWhere(where)
return result

async def mergeAuxTables(self,
inuri: str,
outuri: str,
Expand Down

0 comments on commit 7cf8212

Please sign in to comment.