Skip to content

Commit 1ecd0e1

Browse files
committed
small cleaning of crud functions
1 parent 2751dec commit 1ecd0e1

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/officers/crud.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,40 @@
1414

1515
_logger = logging.getLogger(__name__)
1616

17-
1817
async def most_recent_officer_term(db_session: database.DBSession, computing_id: str) -> OfficerTerm | None:
1918
"""
2019
Returns the most recent OfficerTerm an exec has held
2120
"""
22-
query = (
21+
return await db_session.scalar(
2322
sqlalchemy
2423
.select(OfficerTerm)
2524
.where(OfficerTerm.computing_id == computing_id)
2625
.order_by(OfficerTerm.start_date.desc())
2726
.limit(1)
2827
)
29-
return await db_session.scalar(query)
3028

3129
async def current_officer_positions(db_session: database.DBSession, computing_id: str) -> list[str]:
3230
"""
3331
Returns the list of officer positions a user currently has. Returns [] if the user is not currently an officer.
3432
3533
An officer can have multiple positions at once, such as Webmaster, Frosh chair, and DoEE.
3634
"""
37-
query = (
35+
query = utils.is_active_officer(
3836
sqlalchemy
3937
.select(OfficerTerm)
4038
.where(OfficerTerm.computing_id == computing_id)
4139
# In order of most recent start date first
4240
.order_by(OfficerTerm.start_date.desc())
4341
)
44-
query = utils.is_active_officer(query)
45-
4642
officer_term_list = (await db_session.scalars(query)).all()
4743
return [term.position for term in officer_term_list]
4844

4945
async def officer_info(db_session: database.DBSession, computing_id: str) -> OfficerInfo:
50-
query = (
46+
officer_term = await db_session.scalar(
5147
sqlalchemy
5248
.select(OfficerInfo)
5349
.where(OfficerInfo.computing_id == computing_id)
5450
)
55-
officer_term = await db_session.scalar(query)
5651
if officer_term is None:
5752
raise HTTPException(status_code=400, detail=f"officer_info for computing_id={computing_id} does not exist yet")
5853
return officer_term
@@ -250,5 +245,5 @@ async def update_officer_term(
250245
await db_session.execute(query)
251246
return True
252247

253-
def remove_officer_term():
248+
async def remove_officer_term():
254249
pass

0 commit comments

Comments
 (0)