diff --git a/frontends/nextjs/src/lib/dbal/database-dbal/dbal-add-user.server.ts b/frontends/nextjs/src/lib/dbal/database-dbal/dbal-add-user.server.ts index e7bd1103c..83e32933d 100644 --- a/frontends/nextjs/src/lib/dbal/database-dbal/dbal-add-user.server.ts +++ b/frontends/nextjs/src/lib/dbal/database-dbal/dbal-add-user.server.ts @@ -12,12 +12,18 @@ export async function dbalAddUser(user: Omit): Promise // Map app role types to DBAL role types // Note: DBAL User type only has basic fields (id, username, email, role, createdAt, updatedAt) // Extended fields like profilePicture, bio, etc. are not in DBAL User type - const dbalRole = user.role as 'user' | 'admin' | 'god' | 'supergod' + const dbalRole = user.role === 'public' + ? 'user' + : (user.role as 'user' | 'admin' | 'god' | 'supergod') const created = await dbal.users.create({ username: user.username, email: user.email, role: dbalRole, + profilePicture: user.profilePicture, + bio: user.bio, + tenantId: user.tenantId, + isInstanceOwner: user.isInstanceOwner, }) // Map DBAL User to app User, preserving extra fields @@ -26,10 +32,10 @@ export async function dbalAddUser(user: Omit): Promise username: created.username, email: created.email, role: created.role as any, - profilePicture: user.profilePicture, - bio: user.bio, + profilePicture: created.profilePicture ?? user.profilePicture, + bio: created.bio ?? user.bio, createdAt: created.createdAt instanceof Date ? created.createdAt.getTime() : Number(created.createdAt), - tenantId: user.tenantId, - isInstanceOwner: user.isInstanceOwner, + tenantId: created.tenantId ?? user.tenantId, + isInstanceOwner: created.isInstanceOwner ?? user.isInstanceOwner, } } diff --git a/frontends/nextjs/src/lib/dbal/database-dbal/dbal-update-user.server.ts b/frontends/nextjs/src/lib/dbal/database-dbal/dbal-update-user.server.ts index ae663f02a..1be947b9c 100644 --- a/frontends/nextjs/src/lib/dbal/database-dbal/dbal-update-user.server.ts +++ b/frontends/nextjs/src/lib/dbal/database-dbal/dbal-update-user.server.ts @@ -13,7 +13,13 @@ export async function dbalUpdateUser(userId: string, updates: Partial): Pr const dbalUpdates: any = {} if (updates.username) dbalUpdates.username = updates.username if (updates.email) dbalUpdates.email = updates.email - if (updates.role) dbalUpdates.role = updates.role + if (updates.role) { + dbalUpdates.role = updates.role === 'public' ? 'user' : updates.role + } + if (updates.profilePicture !== undefined) dbalUpdates.profilePicture = updates.profilePicture + if (updates.bio !== undefined) dbalUpdates.bio = updates.bio + if (updates.tenantId !== undefined) dbalUpdates.tenantId = updates.tenantId + if (updates.isInstanceOwner !== undefined) dbalUpdates.isInstanceOwner = updates.isInstanceOwner const updated = await dbal.users.update(userId, dbalUpdates) @@ -23,10 +29,10 @@ export async function dbalUpdateUser(userId: string, updates: Partial): Pr username: updated.username, email: updated.email, role: updated.role as any, - profilePicture: updates.profilePicture, - bio: updates.bio, + profilePicture: updated.profilePicture ?? updates.profilePicture, + bio: updated.bio ?? updates.bio, createdAt: updated.createdAt instanceof Date ? updated.createdAt.getTime() : Number(updated.createdAt), - tenantId: updates.tenantId, - isInstanceOwner: updates.isInstanceOwner, + tenantId: updated.tenantId ?? updates.tenantId, + isInstanceOwner: updated.isInstanceOwner ?? updates.isInstanceOwner, } }