|
14 | 14 |
|
15 | 15 | _logger = logging.getLogger(__name__) |
16 | 16 |
|
17 | | - |
18 | 17 | async def most_recent_officer_term(db_session: database.DBSession, computing_id: str) -> OfficerTerm | None: |
19 | 18 | """ |
20 | 19 | Returns the most recent OfficerTerm an exec has held |
21 | 20 | """ |
22 | | - query = ( |
| 21 | + return await db_session.scalar( |
23 | 22 | sqlalchemy |
24 | 23 | .select(OfficerTerm) |
25 | 24 | .where(OfficerTerm.computing_id == computing_id) |
26 | 25 | .order_by(OfficerTerm.start_date.desc()) |
27 | 26 | .limit(1) |
28 | 27 | ) |
29 | | - return await db_session.scalar(query) |
30 | 28 |
|
31 | 29 | async def current_officer_positions(db_session: database.DBSession, computing_id: str) -> list[str]: |
32 | 30 | """ |
33 | 31 | Returns the list of officer positions a user currently has. Returns [] if the user is not currently an officer. |
34 | 32 |
|
35 | 33 | An officer can have multiple positions at once, such as Webmaster, Frosh chair, and DoEE. |
36 | 34 | """ |
37 | | - query = ( |
| 35 | + query = utils.is_active_officer( |
38 | 36 | sqlalchemy |
39 | 37 | .select(OfficerTerm) |
40 | 38 | .where(OfficerTerm.computing_id == computing_id) |
41 | 39 | # In order of most recent start date first |
42 | 40 | .order_by(OfficerTerm.start_date.desc()) |
43 | 41 | ) |
44 | | - query = utils.is_active_officer(query) |
45 | | - |
46 | 42 | officer_term_list = (await db_session.scalars(query)).all() |
47 | 43 | return [term.position for term in officer_term_list] |
48 | 44 |
|
49 | 45 | async def officer_info(db_session: database.DBSession, computing_id: str) -> OfficerInfo: |
50 | | - query = ( |
| 46 | + officer_term = await db_session.scalar( |
51 | 47 | sqlalchemy |
52 | 48 | .select(OfficerInfo) |
53 | 49 | .where(OfficerInfo.computing_id == computing_id) |
54 | 50 | ) |
55 | | - officer_term = await db_session.scalar(query) |
56 | 51 | if officer_term is None: |
57 | 52 | raise HTTPException(status_code=400, detail=f"officer_info for computing_id={computing_id} does not exist yet") |
58 | 53 | return officer_term |
@@ -250,5 +245,5 @@ async def update_officer_term( |
250 | 245 | await db_session.execute(query) |
251 | 246 | return True |
252 | 247 |
|
253 | | -def remove_officer_term(): |
| 248 | +async def remove_officer_term(): |
254 | 249 | pass |
0 commit comments