Ignore:
Timestamp:
12/25/25 01:49:51 (7 months ago)
Author:
Tome <gjorgievtome@…>
Branches:
main
Children:
e7f1bfa
Parents:
d4842f4
Message:

fix returns and add checks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • database/drizzle/queries/users.ts

    rd4842f4 r83fb5e2  
    44
    55export async function createUser(db: Database, username: string, email: string, passwordHash: string) {
    6     await db
     6    const [newUser] = await db
    77        .insert(usersTable)
    88        .values({
     
    1010            email: email,
    1111            passwordHash: passwordHash,
     12        })
     13        .returning({
     14            id: usersTable.id,
    1215        });
     16
     17    return newUser?.id ?? null;
    1318}
    1419
     
    2934
    3035export async function isAdmin(db: Database, userId: number) {
    31     const admin = await db
     36    const [admin] = await db
    3237        .selectDistinct()
    3338        .from(adminsTable)
     
    3742        .limit(1);
    3843
    39     return admin.length ?? null;
     44    return !!admin;
    4045}
    4146
     
    5560
    5661export async function setComponentSuggestionStatus(db: Database, suggestionId: number, adminId: number, status: string, adminComment: string) {
    57     const result = await db
     62    const [result] = await db
    5863        .update(suggestionsTable)
    5964        .set({
     
    6469        .where(
    6570            eq(suggestionsTable.id, suggestionId)
    66         );
     71        )
     72        .returning({
     73            id: suggestionsTable.id
     74        });
    6775
    68     return result.rowCount ?? null;
     76    return result?.id ?? null;
    6977}
    7078
     
    7886            componentType: componentType
    7987        })
    80         .returning({ id: suggestionsTable.id });
     88        .returning({
     89            id: suggestionsTable.id
     90        });
    8191
    82     return newSuggestion.id ?? null;
     92    return newSuggestion?.id ?? null;
    8393}
Note: See TracChangeset for help on using the changeset viewer.